Skip to content

Commit

Permalink
Merge branch 'pull_#492'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaiarocci committed May 7, 2019
2 parents 1428bfd + 45c4347 commit 41115aa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
12 changes: 10 additions & 2 deletions .readthedocs.yml
@@ -1,5 +1,13 @@
version: 2

build:
image: latest

formats: all

python:
setup_py_install: true
version: 3.6
version: 3.7
install:
- path: .
method: pip
- requirements: docs/requirements.txt
3 changes: 1 addition & 2 deletions cerberus/schema.py
Expand Up @@ -403,9 +403,8 @@ def _check_with_type(self, field, value):
value = set((value,)) if isinstance(value, _str_type) else set(value)
invalid_constraints = value - set(self.target_validator.types)
if invalid_constraints:
path = self.document_path + (field,)
self._error(
path, 'Unsupported types: {}'.format(', '.join(invalid_constraints))
field, 'Unsupported types: {}'.format(', '.join(invalid_constraints))
)

def _expand_rules_set_refs(self, schema):
Expand Down
6 changes: 4 additions & 2 deletions cerberus/tests/__init__.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

import re

import pytest

from cerberus import errors, Validator, SchemaError, DocumentError
Expand All @@ -12,10 +14,10 @@ def assert_exception(exception, document={}, schema=None, validator=None, msg=No
if validator is None:
validator = Validator()
if msg is None:
with pytest.raises(exception) as excinfo:
with pytest.raises(exception):
validator(document, schema)
else:
with pytest.raises(exception, message=msg) as excinfo: # noqa: F841
with pytest.raises(exception, match=re.escape(msg)):
validator(document, schema)


Expand Down
24 changes: 12 additions & 12 deletions cerberus/tests/test_schema.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

import re

import pytest

from cerberus import Validator, errors, SchemaError
Expand All @@ -9,14 +11,14 @@

def test_empty_schema():
validator = Validator()
with pytest.raises(SchemaError, message=errors.SCHEMA_ERROR_MISSING):
with pytest.raises(SchemaError, match=errors.SCHEMA_ERROR_MISSING):
validator({}, schema=None)


def test_bad_schema_type(validator):
schema = "this string should really be dict"
exp_msg = errors.SCHEMA_ERROR_DEFINITION_TYPE.format(schema)
with pytest.raises(SchemaError, message=exp_msg):
msg = errors.SCHEMA_ERROR_DEFINITION_TYPE.format(schema)
with pytest.raises(SchemaError, match=msg):
validator.schema = schema


Expand All @@ -28,23 +30,21 @@ def test_bad_schema_type_field(validator):


def test_unknown_rule(validator):
message = "{'foo': [{'unknown': ['unknown rule']}]}"
with pytest.raises(SchemaError, message=message):
msg = "{'foo': [{'unknown': ['unknown rule']}]}"
with pytest.raises(SchemaError, match=re.escape(msg)):
validator.schema = {'foo': {'unknown': 'rule'}}


def test_unknown_type(validator):
field = 'name'
value = 'catch_me'
message = str({field: [{'type': ['unallowed value %s' % value]}]})
with pytest.raises(SchemaError, message=message):
validator.schema = {'foo': {'unknown': 'rule'}}
msg = str({'foo': [{'type': ['Unsupported types: unknown']}]})
with pytest.raises(SchemaError, match=re.escape(msg)):
validator.schema = {'foo': {'type': 'unknown'}}


def test_bad_schema_definition(validator):
field = 'name'
message = str({field: ['must be of dict type']})
with pytest.raises(SchemaError, message=message):
msg = str({field: ['must be of dict type']})
with pytest.raises(SchemaError, match=re.escape(msg)):
validator.schema = {field: 'this should really be a dict'}


Expand Down
2 changes: 1 addition & 1 deletion requirements-docs.txt → docs/requirements.txt
@@ -1,3 +1,3 @@
# requirements to build documentation
Sphinx
Sphinx<2.0
sphinxcontrib-issuetracker
4 changes: 2 additions & 2 deletions tox.ini
Expand Up @@ -6,14 +6,14 @@ deps=pytest
commands=pytest cerberus/tests

[testenv:doclinks]
deps=-rrequirements-docs.txt
deps=-rdocs/requirements.txt
whitelist_externals=make
changedir=docs
commands=make linkcheck

[testenv:doctest]
deps=PyYAML
-rrequirements-docs.txt
-rdocs/requirements.txt
whitelist_externals=make
changedir=docs
commands=make doctest
Expand Down

0 comments on commit 41115aa

Please sign in to comment.