From b8a5692021dd3505ba721376c3a712f634e82600 Mon Sep 17 00:00:00 2001 From: Frederick Wagner Date: Wed, 5 Dec 2018 16:45:22 -0500 Subject: [PATCH 1/7] TST: Update tests to work with Click==7.0 The automatic `Try " --help" for help.` output text was added in Click 7.0. This commit changes the tests to only check the portion of the output under our control. --- straitlets/ext/tests/test_click.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/straitlets/ext/tests/test_click.py b/straitlets/ext/tests/test_click.py index 0f1e603..74032cd 100644 --- a/straitlets/ext/tests/test_click.py +++ b/straitlets/ext/tests/test_click.py @@ -59,9 +59,7 @@ def missing_attr_instance(): multi_error_output = re.compile( dedent( """\ - ^Usage: main \[OPTIONS\] - - Error: Invalid value for "--config": Failed to validate the schema: + Failed to validate the schema: bool: No default value found for bool trait of <.+?> @@ -69,18 +67,16 @@ def missing_attr_instance(): No default value found for int trait of <.+?> unicode: No default value found for unicode trait of <.+?> - $""", + """, ), ) single_error_output = re.compile( dedent( """\ - ^Usage: main \[OPTIONS\] - - Error: Invalid value for "--config": Failed to validate the schema: + Failed to validate the schema: No default value found for int trait of <.+?> - $""", + """, ), ) @@ -128,7 +124,7 @@ def main(config): # pragma: no cover catch_exceptions=False, ) assert result.exit_code - assert multi_error_output.match(result.output) + assert multi_error_output.search(result.output) def test_json_single_error(runner, missing_attr_instance): @@ -148,7 +144,7 @@ def main(config): # pragma: no cover catch_exceptions=False, ) assert result.exit_code - assert single_error_output.match(result.output) + assert single_error_output.search(result.output) def test_yaml_file(runner, expected_instance): @@ -194,7 +190,7 @@ def main(config): # pragma: no cover catch_exceptions=False, ) assert result.exit_code - assert multi_error_output.match(result.output) + assert multi_error_output.search(result.output) def test_yaml_single_error(runner, missing_attr_instance): @@ -214,4 +210,4 @@ def main(config): # pragma: no cover catch_exceptions=False, ) assert result.exit_code - assert single_error_output.match(result.output) + assert single_error_output.search(result.output) From e5294051ac46a54591c39654d473581360156e39 Mon Sep 17 00:00:00 2001 From: Frederick Wagner Date: Wed, 5 Dec 2018 16:55:31 -0500 Subject: [PATCH 2/7] MAINT: flake8 fixes --- straitlets/tests/test_serializable.py | 2 +- straitlets/to_primitive.py | 1 + straitlets/traits.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/straitlets/tests/test_serializable.py b/straitlets/tests/test_serializable.py index 6132447..bb70a6a 100644 --- a/straitlets/tests/test_serializable.py +++ b/straitlets/tests/test_serializable.py @@ -109,7 +109,7 @@ class DynamicDefaults(Serializable): def _d_default(self): return self.DEFAULT_D - l = List() + l = List() # noqa DEFAULT_L = [1, 2, not_ascii, 3] def _l_default(self): diff --git a/straitlets/to_primitive.py b/straitlets/to_primitive.py index f93f757..0de461b 100644 --- a/straitlets/to_primitive.py +++ b/straitlets/to_primitive.py @@ -13,6 +13,7 @@ def to_primitive(obj): ) ) + _base_handler = to_primitive.dispatch(object) diff --git a/straitlets/traits.py b/straitlets/traits.py index ce743ad..c19730b 100644 --- a/straitlets/traits.py +++ b/straitlets/traits.py @@ -106,6 +106,7 @@ def _get_default_value_sentinel(t): "Can't find default value sentinel for type %s" % t ) + _NOTPASSED = object() _TRAITLETS_CONTAINER_TYPES = frozenset([tr.List, tr.Set, tr.Dict, tr.Tuple]) _DEFAULT_VALUE_SENTINELS = { From e0a455e45a855fef58d11ee6ffcaf5daa0c9f194 Mon Sep 17 00:00:00 2001 From: Frederick Wagner Date: Wed, 5 Dec 2018 17:31:43 -0500 Subject: [PATCH 3/7] MAINT: Resolve DeprecationWarning from getargspec --- straitlets/compat.py | 3 +++ straitlets/traits.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/straitlets/compat.py b/straitlets/compat.py index 0108f30..d9a510c 100644 --- a/straitlets/compat.py +++ b/straitlets/compat.py @@ -1,9 +1,11 @@ from six import PY3 if PY3: # pragma: no cover + from inspect import getfullargspec as argspec # noqa long = int unicode = str else: # pragma: no cover + from inspect import getargspec as argspec # noqa long = long unicode = unicode @@ -25,6 +27,7 @@ def ensure_unicode(s, encoding='utf-8'): __all__ = [ + 'argspec', 'ensure_bytes', 'ensure_unicode', 'long', diff --git a/straitlets/traits.py b/straitlets/traits.py index c19730b..e831131 100644 --- a/straitlets/traits.py +++ b/straitlets/traits.py @@ -8,10 +8,10 @@ - More strict handling of default values than traitlets' built-in behavior. """ from contextlib import contextmanager -import inspect import traitlets as tr +from . import compat from .to_primitive import to_primitive, can_convert_to_primitive @@ -97,7 +97,7 @@ def _get_default_value_sentinel(t): # signature. if t is tr.Tuple: return tr.Undefined - argspec = inspect.getargspec(t.__init__) + argspec = compat.argspec(t.__init__) for name, value in zip(reversed(argspec.args), reversed(argspec.defaults)): if name == 'default_value': return value From 64ab255abee172ecee50cecc6991ad2490e6b310 Mon Sep 17 00:00:00 2001 From: Frederick Wagner Date: Wed, 5 Dec 2018 18:13:34 -0500 Subject: [PATCH 4/7] BLD: Test more Python versions Apparently Travis still only offers 3.7-dev. We should fix this once a stable 3.7 is available. --- .travis.yml | 4 ++++ tox.ini | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 711e44c..257bbec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ python: - "2.7" - "3.4" - "3.5" + - "3.6" + - "3.7-dev" before_script: - pip install tox @@ -12,3 +14,5 @@ script: - if [[ $TRAVIS_PYTHON_VERSION = '2.7' ]]; then tox -e py27; fi - if [[ $TRAVIS_PYTHON_VERSION = '3.4' ]]; then tox -e py34; fi - if [[ $TRAVIS_PYTHON_VERSION = '3.5' ]]; then tox -e py35; fi + - if [[ $TRAVIS_PYTHON_VERSION = '3.6' ]]; then tox -e py36; fi + - if [[ $TRAVIS_PYTHON_VERSION = '3.7-dev' ]]; then tox -e py37; fi diff --git a/tox.ini b/tox.ini index 83d2983..b50371d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py{27,34,35} +envlist=py{27,34,35,36,37} skip_missing_interpreters=True [testenv] From 7f79ea1dbe98d6ebed07a649125f616d0d9e296f Mon Sep 17 00:00:00 2001 From: Frederick Wagner Date: Wed, 5 Dec 2018 18:30:57 -0500 Subject: [PATCH 5/7] BLD: Ignore third-party warning --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index b50371d..539ce56 100644 --- a/tox.ini +++ b/tox.ini @@ -10,3 +10,6 @@ commands= [pytest] addopts = --pep8 --cov straitlets --cov-report term-missing --cov-report html testpaths = straitlets +filterwarnings = + # PyYAML==3.13 + ignore:Using or importing the ABCs:DeprecationWarning:yaml.constructor:126 From 029541ac90a250a0ac12dda3464e6ba55e6e0e49 Mon Sep 17 00:00:00 2001 From: Frederick Wagner Date: Wed, 5 Dec 2018 18:36:49 -0500 Subject: [PATCH 6/7] MAINT: Resolve DeprecationWarnings Resolves the following two DeprecationWarnings from traitlets 4.1: DeprecationWarning: Traits should be given as instances, not types (for example, `Int()`, not `Int`). Passing types is deprecated in traitlets 4.1. DeprecationWarning: metadata {'example': 97} was set from the constructor. With traitlets 4.1, metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2') --- straitlets/builtin_models.py | 2 +- straitlets/tests/test_examples.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/straitlets/builtin_models.py b/straitlets/builtin_models.py index c871ba4..7592169 100644 --- a/straitlets/builtin_models.py +++ b/straitlets/builtin_models.py @@ -127,7 +127,7 @@ def _password_requires_user(self, proposal): return new hosts = List( - trait=Unicode, + trait=Unicode(), minlen=1, help=( "List of hosts in the replicaset. " diff --git a/straitlets/tests/test_examples.py b/straitlets/tests/test_examples.py index eb42432..90acc81 100644 --- a/straitlets/tests/test_examples.py +++ b/straitlets/tests/test_examples.py @@ -152,14 +152,14 @@ def test_nested_example(): class C(Serializable): point = Instance(Point) - unicode_ = Unicode(example='foo') + unicode_ = Unicode().tag(example='foo') class B(Serializable): - value = Integer(example=ord('b')) + value = Integer().tag(example=ord('b')) next_ = Instance(C) class A(Serializable): - value = Integer(example=ord('a')) + value = Integer().tag(example=ord('a')) next_ = Instance(B) expected = A( From 109e3a2fd7effd52246f3478ea291e6f016b5e54 Mon Sep 17 00:00:00 2001 From: Frederick Wagner Date: Tue, 11 Dec 2018 15:24:17 -0500 Subject: [PATCH 7/7] BLD: Update Travis configuration for Python 3.7 --- .travis.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 257bbec..dd8fcfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,14 @@ python: - "3.4" - "3.5" - "3.6" - - "3.7-dev" + +# Python 3.7 requires OpenSSL 1.0.2+, which is only available on Travis +# via xenial and sudo. Require them for only the build that needs them. +matrix: + include: + - python: "3.7" + dist: xenial + sudo: true before_script: - pip install tox @@ -15,4 +22,4 @@ script: - if [[ $TRAVIS_PYTHON_VERSION = '3.4' ]]; then tox -e py34; fi - if [[ $TRAVIS_PYTHON_VERSION = '3.5' ]]; then tox -e py35; fi - if [[ $TRAVIS_PYTHON_VERSION = '3.6' ]]; then tox -e py36; fi - - if [[ $TRAVIS_PYTHON_VERSION = '3.7-dev' ]]; then tox -e py37; fi + - if [[ $TRAVIS_PYTHON_VERSION = '3.7' ]]; then tox -e py37; fi