Skip to content
Open
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
6 changes: 5 additions & 1 deletion hug/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def __init__(self, schema):
def __doc__(self):
return self.schema.__doc__ or self.schema.__class__.__name__

def __call__(self, value, context):
def __call__(self, value, context=None):
self.schema.context = context
# In marshmallow 2 schemas return tuple (`data`, `errors`) upon loading. They might also raise on invalid data
# if configured so, but will still return a tuple.
Expand All @@ -686,6 +686,8 @@ def __call__(self, value, context):
)
except ValidationError as e:
errors = e.messages
except ValueError as e:
errors = [str(e)]

if errors:
raise InvalidTypeData(
Expand Down Expand Up @@ -727,6 +729,8 @@ def __call__(self, value):
value = self.schema.dump(value)
except ValidationError as e:
errors = e.messages
except ValueError as e:
errors = [str(e)]

if errors:
raise InvalidTypeData(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class UserSchema(Schema):
name = fields.Str()

@post_dump()
def check_context(self, data):
def check_context(self, data, **kwargs):
assert self.context["test"] == "context"
self.context["test_number"] += 1

Expand Down Expand Up @@ -304,7 +304,7 @@ class UserSchema(Schema):
name = fields.Str()

@post_dump()
def check_context(self, data):
def check_context(self, data, **kwargs):
assert self.context["test"] == "context"
self.context["test_number"] += 1

Expand Down Expand Up @@ -479,7 +479,7 @@ class UserSchema(Schema):
name = fields.Str()

@post_dump()
def check_context(self, data):
def check_context(self, data, **kwargs):
assert self.context["test"] == "context"
self.context["test_number"] += 1

Expand Down
2 changes: 1 addition & 1 deletion tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class MarshmallowContextSchema(Schema):
name = fields.String()

@validates_schema
def check_context(self, data):
def check_context(self, data, **kwargs):
assert self.context == custom_context
self.context["marshmallow"] += 1

Expand Down
14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ envlist=py{35,36,37,38,py3}-marshmallow{2,3}, cython-marshmallow{2,3}
deps=
-rrequirements/build_common.txt
marshmallow2: marshmallow <3.0
marshmallow3: marshmallow==3.0.0rc6
marshmallow3: marshmallow>3.0

whitelist_externals=flake8
commands=py.test --durations 3 --cov-report html --cov hug -n auto tests

[testenv:py37-black]
deps=
-rrequirements/build_style_tools.txt
marshmallow==3.0.0rc6
marshmallow>3.0

whitelist_externals=flake8
commands=black --check --verbose -l 100 hug

[testenv:py37-vulture]
deps=
-rrequirements/build_style_tools.txt
marshmallow==3.0.0rc6
marshmallow>3.0

whitelist_externals=flake8
commands=vulture hug --min-confidence 100 --ignore-names req_succeeded
Expand All @@ -30,31 +30,31 @@ commands=vulture hug --min-confidence 100 --ignore-names req_succeeded
[testenv:py37-flake8]
deps=
-rrequirements/build_style_tools.txt
marshmallow==3.0.0rc6
marshmallow>3.0

whitelist_externals=flake8
commands=flake8 hug

[testenv:py37-bandit]
deps=
-rrequirements/build_style_tools.txt
marshmallow==3.0.0rc6
marshmallow>3.0

whitelist_externals=flake8
commands=bandit -r hug/ -ll

[testenv:py37-isort]
deps=
-rrequirements/build_style_tools.txt
marshmallow==3.0.0rc6
marshmallow>3.0

whitelist_externals=flake8
commands=isort -c --diff --recursive hug

[testenv:py37-safety]
deps=
-rrequirements/build_style_tools.txt
marshmallow==3.0.0rc6
marshmallow>3.0

whitelist_externals=flake8
commands=safety check -i 36810
Expand Down