Skip to content

Commit 79edaf0

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 79edaf0

File tree

9 files changed

+45
-26
lines changed

9 files changed

+45
-26
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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,15 @@ def use_span(self, span: 'Span') -> typing.Iterator[None]:
378378
yield
379379

380380

381-
_TRACER: typing.Optional[Tracer] = None
382-
_TRACER_FACTORY: typing.Optional[
383-
typing.Callable[[typing.Type[Tracer]], typing.Optional[Tracer]]] = None
381+
# Once https://github.com/python/mypy/issues/7092 is resolved,
382+
# the following type definition should be replaced with
383+
# from opentelemetry.loader import ImplementationFactory
384+
ImplementationFactory = typing.Callable[
385+
[typing.Type[Tracer]], typing.Optional[Tracer]
386+
]
387+
388+
_TRACER = None # type: typing.Optional[Tracer]
389+
_TRACER_FACTORY = None # type: typing.Optional[ImplementationFactory]
384390

385391

386392
def tracer() -> Tracer:
@@ -399,9 +405,8 @@ def tracer() -> Tracer:
399405

400406

401407
def set_preferred_tracer_implementation(
402-
factory: typing.Callable[
403-
[typing.Type[Tracer]], typing.Optional[Tracer]]
404-
) -> None:
408+
factory: ImplementationFactory
409+
) -> None:
405410
"""Set the factory to be used to create the tracer.
406411
407412
See :mod:`opentelemetry.loader` for details.

tox.ini

Lines changed: 5 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
@@ -36,6 +38,7 @@ commands =
3638
test: python -m unittest discover
3739

3840
[testenv:lint]
41+
basepython: python3.7
3942
deps =
4043
pylint~=2.3
4144
flake8~=3.7

0 commit comments

Comments
 (0)