forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure the API returns right value types (open-telemetry#307)
Fixes open-telemetry#142 Enabling --strict mode for mypy. Added a test in the sdk and the same test in the api to test the different behaviours between the Tracer, Span and Metric classes.
- Loading branch information
Showing
8 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
from opentelemetry import metrics, trace | ||
|
||
|
||
class TestAPIOnlyImplementation(unittest.TestCase): | ||
""" | ||
This test is in place to ensure the API is returning values that | ||
are valid. The same tests have been added to the SDK with | ||
different expected results. See issue for more details: | ||
https://github.com/open-telemetry/opentelemetry-python/issues/142 | ||
""" | ||
|
||
def test_tracer(self): | ||
tracer = trace.Tracer() | ||
with tracer.start_span("test") as span: | ||
self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) | ||
self.assertEqual(span, trace.INVALID_SPAN) | ||
self.assertIs(span.is_recording_events(), False) | ||
with tracer.start_span("test2") as span2: | ||
self.assertEqual( | ||
span2.get_context(), trace.INVALID_SPAN_CONTEXT | ||
) | ||
self.assertEqual(span2, trace.INVALID_SPAN) | ||
self.assertIs(span2.is_recording_events(), False) | ||
|
||
def test_span(self): | ||
span = trace.Span() | ||
self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) | ||
self.assertIs(span.is_recording_events(), False) | ||
|
||
def test_default_span(self): | ||
span = trace.DefaultSpan(trace.INVALID_SPAN_CONTEXT) | ||
self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT) | ||
self.assertIs(span.is_recording_events(), False) | ||
|
||
def test_meter(self): | ||
meter = metrics.Meter() | ||
metric = meter.create_metric("", "", "", float, metrics.Counter) | ||
self.assertIsInstance(metric, metrics.DefaultMetric) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
from opentelemetry.metrics import DefaultMetric | ||
from opentelemetry.sdk import metrics, trace | ||
from opentelemetry.trace import INVALID_SPAN, INVALID_SPAN_CONTEXT | ||
|
||
|
||
class TestSDKImplementation(unittest.TestCase): | ||
""" | ||
This test is in place to ensure the SDK implementation of the API | ||
is returning values that are valid. The same tests have been added | ||
to the API with different expected results. See issue for more details: | ||
https://github.com/open-telemetry/opentelemetry-python/issues/142 | ||
""" | ||
|
||
def test_tracer(self): | ||
tracer = trace.Tracer() | ||
with tracer.start_span("test") as span: | ||
self.assertNotEqual(span.get_context(), INVALID_SPAN_CONTEXT) | ||
self.assertNotEqual(span, INVALID_SPAN) | ||
self.assertIs(span.is_recording_events(), True) | ||
with tracer.start_span("test2") as span2: | ||
self.assertNotEqual(span2.get_context(), INVALID_SPAN_CONTEXT) | ||
self.assertNotEqual(span2, INVALID_SPAN) | ||
self.assertIs(span2.is_recording_events(), True) | ||
|
||
def test_span(self): | ||
with self.assertRaises(Exception): | ||
# pylint: disable=no-value-for-parameter | ||
span = trace.Span() | ||
|
||
span = trace.Span("name", INVALID_SPAN_CONTEXT) | ||
self.assertEqual(span.get_context(), INVALID_SPAN_CONTEXT) | ||
self.assertIs(span.is_recording_events(), True) | ||
|
||
def test_meter(self): | ||
meter = metrics.Meter() | ||
metric = meter.create_metric("", "", "", float, metrics.Counter) | ||
self.assertNotIsInstance(metric, DefaultMetric) |