Skip to content

Commit dc79a14

Browse files
committed
Improve testing
I believe it would be nice to have tests on CI not only for Python 3.7, but for all supported Python versions. These changes: - fix compatibility with Python 3.5 and 3.4 - add tests for various Python versions on CI - allow running tests for any branches
1 parent cb4fc12 commit dc79a14

File tree

9 files changed

+48
-32
lines changed

9 files changed

+48
-32
lines changed

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ dist: xenial
33
language: python
44

55
python:
6+
- '3.4'
7+
- '3.5'
8+
- '3.6'
69
- '3.7'
10+
- 'pypy3.5'
11+
- '3.8-dev'
12+
13+
matrix:
14+
allow_failures:
15+
- python: '3.8-dev'
716

817
install:
918
- pip install tox-travis
1019

1120
script:
1221
- tox
13-
14-
branches:
15-
only:
16-
- master

ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def tearDown(self):
9494

9595
def start_response(self, status, response_headers, exc_info=None):
9696
# The span should have started already
97-
self.span_context_manager.__enter__.assert_called()
97+
self.span_context_manager.__enter__.assert_called_with()
9898

9999
self.status = status
100100
self.response_headers = response_headers
@@ -108,7 +108,9 @@ def validate_response(self, response, error=None):
108108
self.span_context_manager.__exit__.assert_not_called()
109109
self.assertEqual(value, b"*")
110110
except StopIteration:
111-
self.span_context_manager.__exit__.assert_called()
111+
self.span_context_manager.__exit__.assert_called_with(
112+
None, None, None
113+
)
112114
break
113115

114116
self.assertEqual(self.status, "200 OK")

opentelemetry-api/src/opentelemetry/context/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ async def main():
145145
__all__ = ['Context']
146146

147147

148-
Context: typing.Optional[BaseRuntimeContext]
148+
Context = ( # pylint: disable=invalid-name
149+
None
150+
) # type: typing.Optional[BaseRuntimeContext]
149151

150152
try:
151153
from .async_context import AsyncRuntimeContext

opentelemetry-api/src/opentelemetry/context/async_context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from contextvars import ContextVar
16-
import typing
16+
import typing # pylint: disable=unused-import
1717

1818
from . import base_context
1919

@@ -23,9 +23,10 @@ class Slot(base_context.BaseRuntimeContext.Slot):
2323
def __init__(self, name: str, default: 'object'):
2424
# pylint: disable=super-init-not-called
2525
self.name = name
26-
self.contextvar: 'ContextVar[object]' = ContextVar(name)
27-
self.default: typing.Callable[..., object]
28-
self.default = base_context.wrap_callable(default)
26+
self.contextvar = ContextVar(name) # type: ContextVar[object]
27+
self.default = base_context.wrap_callable(
28+
default
29+
) # type: typing.Callable[..., object]
2930

3031
def clear(self) -> None:
3132
self.contextvar.set(self.default())

opentelemetry-api/src/opentelemetry/context/base_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def set(self, value: 'object') -> None:
3737
raise NotImplementedError
3838

3939
_lock = threading.Lock()
40-
_slots: typing.Dict[str, 'BaseRuntimeContext.Slot'] = {}
40+
_slots = {} # type: typing.Dict[str, 'BaseRuntimeContext.Slot']
4141

4242
@classmethod
4343
def clear(cls) -> None:
@@ -112,7 +112,7 @@ def with_current_context(
112112

113113
def call_with_current_context(
114114
*args: 'object',
115-
**kwargs: 'object',
115+
**kwargs: 'object'
116116
) -> 'object':
117117
try:
118118
backup_context = self.snapshot()

opentelemetry-api/src/opentelemetry/context/thread_local_context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import threading
16-
import typing
16+
import typing # pylint: disable=unused-import
1717

1818
from . import base_context
1919

@@ -25,15 +25,16 @@ class Slot(base_context.BaseRuntimeContext.Slot):
2525
def __init__(self, name: str, default: 'object'):
2626
# pylint: disable=super-init-not-called
2727
self.name = name
28-
self.default: typing.Callable[..., object]
29-
self.default = base_context.wrap_callable(default)
28+
self.default = base_context.wrap_callable(
29+
default
30+
) # type: typing.Callable[..., object]
3031

3132
def clear(self) -> None:
3233
setattr(self._thread_local, self.name, self.default())
3334

3435
def get(self) -> 'object':
3536
try:
36-
got: object = getattr(self._thread_local, self.name)
37+
got = getattr(self._thread_local, self.name) # type: object
3738
return got
3839
except AttributeError:
3940
value = self.default()

opentelemetry-api/src/opentelemetry/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def my_factory_for_t(api_type: typing.Type[T]) -> typing.Optional[T]:
8383
# code.
8484
# ImplementationFactory = Callable[[Type[_T]], Optional[_T]]
8585

86-
_DEFAULT_FACTORY: Optional[_UntrustedImplFactory[object]] = None
86+
_DEFAULT_FACTORY = None # type: Optional[_UntrustedImplFactory[object]]
8787

8888

8989
def _try_load_impl_from_modname(

opentelemetry-api/src/opentelemetry/trace/__init__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,18 @@
6262
"""
6363

6464
from contextlib import contextmanager
65-
import typing
65+
from typing import Callable
66+
from typing import Dict
67+
from typing import Iterator
68+
from typing import Optional
69+
from typing import Type
70+
from typing import Union
6671

6772
from opentelemetry import loader
6873
from opentelemetry import types
6974

7075
# TODO: quarantine
71-
ParentSpan = typing.Optional[typing.Union['Span', 'SpanContext']]
76+
ParentSpan = Optional[Union['Span', 'SpanContext']]
7277

7378

7479
class Span:
@@ -155,7 +160,7 @@ def get_default(cls) -> 'TraceOptions':
155160
DEFAULT_TRACE_OPTIONS = TraceOptions.get_default()
156161

157162

158-
class TraceState(typing.Dict[str, str]):
163+
class TraceState(Dict[str, str]):
159164
"""A list of key-value pairs representing vendor-specific trace info.
160165
161166
Keys and values are strings of up to 256 printable US-ASCII characters.
@@ -278,7 +283,7 @@ def get_current_span(self) -> 'Span':
278283
def start_span(self,
279284
name: str,
280285
parent: ParentSpan = CURRENT_SPAN
281-
) -> typing.Iterator['Span']:
286+
) -> Iterator['Span']:
282287
"""Context manager for span creation.
283288
284289
Create a new span. Start the span and set it as the current span in
@@ -362,7 +367,7 @@ def create_span(self,
362367
return INVALID_SPAN
363368

364369
@contextmanager # type: ignore
365-
def use_span(self, span: 'Span') -> typing.Iterator[None]:
370+
def use_span(self, span: 'Span') -> Iterator[None]:
366371
"""Context manager for controlling a span's lifetime.
367372
368373
Start the given span and set it as the current span in this tracer's
@@ -378,9 +383,10 @@ def use_span(self, span: 'Span') -> typing.Iterator[None]:
378383
yield
379384

380385

381-
_TRACER: typing.Optional[Tracer] = None
382-
_TRACER_FACTORY: typing.Optional[
383-
typing.Callable[[typing.Type[Tracer]], typing.Optional[Tracer]]] = None
386+
FactoryType = Callable[[Type[Tracer]], Optional[Tracer]]
387+
388+
_TRACER = None # type: Optional[Tracer]
389+
_TRACER_FACTORY = None # type: Optional[FactoryType]
384390

385391

386392
def tracer() -> Tracer:
@@ -398,10 +404,7 @@ def tracer() -> Tracer:
398404
return _TRACER
399405

400406

401-
def set_preferred_tracer_implementation(
402-
factory: typing.Callable[
403-
[typing.Type[Tracer]], typing.Optional[Tracer]]
404-
) -> None:
407+
def set_preferred_tracer_implementation(factory: FactoryType) -> None:
405408
"""Set the factory to be used to create the tracer.
406409
407410
See :mod:`opentelemetry.loader` for details.

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[tox]
22
skipsdist = True
3+
skip_missing_interpreters = True
34
envlist =
4-
py{34,35,36,37}-test-{api,sdk}
5-
py{34,35,36,37}-test-ext-wsgi
5+
py3{4,5,6,7,8}-test-{api,sdk,ext-wsgi}
6+
pypy35-test-{api,sdk,ext-wsgi}
67
lint
78
py37-mypy
89
docs
@@ -24,6 +25,7 @@ changedir =
2425
test-ext-wsgi: ext/opentelemetry-ext-wsgi/tests
2526

2627
commands_pre =
28+
pip install -U pip setuptools wheel
2729
test: pip install -e {toxinidir}/opentelemetry-api
2830
test-sdk: pip install -e {toxinidir}/opentelemetry-sdk
2931
ext: pip install -e {toxinidir}/opentelemetry-api

0 commit comments

Comments
 (0)