Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General maintenance #10

Merged
merged 7 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"

# 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
Expand All @@ -12,3 +21,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' ]]; then tox -e py37; fi
2 changes: 1 addition & 1 deletion straitlets/builtin_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down
3 changes: 3 additions & 0 deletions straitlets/compat.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -25,6 +27,7 @@ def ensure_unicode(s, encoding='utf-8'):


__all__ = [
'argspec',
'ensure_bytes',
'ensure_unicode',
'long',
Expand Down
20 changes: 8 additions & 12 deletions straitlets/ext/tests/test_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,24 @@ 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 <.+?>
int:
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 <.+?>
$""",
""",
),
)

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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)
6 changes: 3 additions & 3 deletions straitlets/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion straitlets/tests/test_serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions straitlets/to_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def to_primitive(obj):
)
)


_base_handler = to_primitive.dispatch(object)


Expand Down
5 changes: 3 additions & 2 deletions straitlets/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py{27,34,35}
envlist=py{27,34,35,36,37}
skip_missing_interpreters=True

[testenv]
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these two warnings about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one warning, from PyYAML. Full output:

straitlets/ext/tests/test_click.py::test_yaml_file
  site-packages/yaml/constructor.py:126: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    if not isinstance(key, collections.Hashable):

We require pyyaml>=3.11, so it should go away once it's fixed upstream. There's a couple open PRs with a fix already.

Apparently there is a Situation with PyYAML releases that we might want to keep an eye on, though: see yaml/pyyaml#193, yaml/pyyaml#194.