|
| 1 | +# Copyright 2019, OpenTelemetry Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import unittest |
| 16 | + |
| 17 | +from opentelemetry.metrics import DefaultMetric |
| 18 | +from opentelemetry.sdk import metrics, trace |
| 19 | +from opentelemetry.trace import INVALID_SPAN, INVALID_SPAN_CONTEXT |
| 20 | + |
| 21 | + |
| 22 | +class TestSDKImplementation(unittest.TestCase): |
| 23 | + """ |
| 24 | + This test is in place to ensure the SDK implementation of the API |
| 25 | + is returning values that are valid. The same tests have been added |
| 26 | + to the API with different expected results. See issue for more details: |
| 27 | + https://github.com/open-telemetry/opentelemetry-python/issues/142 |
| 28 | + """ |
| 29 | + |
| 30 | + def test_tracer(self): |
| 31 | + tracer = trace.Tracer() |
| 32 | + with tracer.start_span("test") as span: |
| 33 | + self.assertNotEqual(span.get_context(), INVALID_SPAN_CONTEXT) |
| 34 | + self.assertNotEqual(span, INVALID_SPAN) |
| 35 | + self.assertIs(span.is_recording_events(), True) |
| 36 | + with tracer.start_span("test2") as span2: |
| 37 | + self.assertNotEqual(span2.get_context(), INVALID_SPAN_CONTEXT) |
| 38 | + self.assertNotEqual(span2, INVALID_SPAN) |
| 39 | + self.assertIs(span2.is_recording_events(), True) |
| 40 | + |
| 41 | + def test_span(self): |
| 42 | + with self.assertRaises(Exception): |
| 43 | + # pylint: disable=no-value-for-parameter |
| 44 | + span = trace.Span() |
| 45 | + |
| 46 | + span = trace.Span("name", INVALID_SPAN_CONTEXT) |
| 47 | + self.assertEqual(span.get_context(), INVALID_SPAN_CONTEXT) |
| 48 | + self.assertIs(span.is_recording_events(), True) |
| 49 | + |
| 50 | + def test_meter(self): |
| 51 | + meter = metrics.Meter() |
| 52 | + metric = meter.create_metric("", "", "", float, metrics.Counter) |
| 53 | + self.assertNotIsInstance(metric, DefaultMetric) |
0 commit comments