Skip to content

Commit

Permalink
Merge 9443f00 into e7fac6a
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteMasterEric committed Aug 24, 2017
2 parents e7fac6a + 9443f00 commit 35e1604
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions pykwalify/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
is_builtin_type,
is_collection_type,
is_number,
is_string,
mapping_aliases,
sequence_aliases,
type_class,
Expand Down Expand Up @@ -380,9 +381,9 @@ def init(self, schema, path):
t = DEFAULT_TYPE
self.type = t
else:
if not isinstance(schema["type"], str):
if not is_string(schema["type"]):
raise RuleError(
msg=u"Key 'type' in schema rule is not a string type",
msg=u"Key 'type' in schema rule is not a string type (found %s)" % type(schema["type"]).__name__,
error_key=u"type.not_string",
path=path,
)
Expand Down Expand Up @@ -448,7 +449,7 @@ def init(self, schema, path):
def init_format_value(self, v, rule, path):
log.debug(u"Init format value : %s", path)

if isinstance(v, basestring):
if is_string(v):
self._format = [v]
elif isinstance(v, list):
valid = True
Expand Down Expand Up @@ -491,7 +492,7 @@ def init_version(self, v, rule, path):
def init_example(self, v, rule, path):
log.debug(u'Init example value : {0}'.format(path))

if not isinstance(v, basestring):
if not is_string(v):
raise RuleError(
msg=u"Value: {0} for keyword example must be a string".format(v),
error_key=u"example.not_string",
Expand Down Expand Up @@ -636,7 +637,7 @@ def init_length_value(self, v, rule, path):
def init_func(self, v, rule, path):
"""
"""
if not isinstance(v, str):
if not is_string(v):
raise RuleError(
msg=u"Value: {0} for func keyword must be a string".format(v),
error_key=u"func.notstring",
Expand Down Expand Up @@ -725,7 +726,7 @@ def init_name_value(self, v, rule, path):
"""
log.debug(u"Init name value : %s", path)

if not isinstance(v, basestring):
if not is_string(v):
raise RuleError(
msg=u"Value: {0} for keyword name must be a string".format(v),
error_key=u"name.not_string",
Expand All @@ -739,7 +740,7 @@ def init_desc_value(self, v, rule, path):
"""
log.debug(u"Init descr value : %s", path)

if not isinstance(v, basestring):
if not is_string(v):
raise RuleError(
msg=u"Value: {0} for keyword desc must be a string".format(v),
error_key=u"desc.not_string",
Expand All @@ -753,7 +754,7 @@ def init_required_value(self, v, rule, path):
"""
log.debug(u"Init required value : %s", path)

if not isinstance(v, bool):
if not is_bool(v):
raise RuleError(
msg=u"Value: '{0}' for required keyword must be a boolean".format(v),
error_key=u"required.not_bool",
Expand All @@ -766,7 +767,7 @@ def init_pattern_value(self, v, rule, path):
"""
log.debug(u"Init pattern value : %s", path)

if not isinstance(v, str):
if not is_string(v):
raise RuleError(
msg=u"Value of pattern keyword: '{0}' is not a string".format(v),
error_key=u"pattern.not_string",
Expand Down Expand Up @@ -836,7 +837,7 @@ def init_assert_value(self, v, rule, path):
"""
log.debug(u"Init assert value : %s", path)

if not isinstance(v, str):
if not is_string(v):
raise RuleError(
msg=u"Value: '{0}' for keyword 'assert' is not a string".format(v),
error_key=u"assert.not_str",
Expand Down Expand Up @@ -992,7 +993,7 @@ def init_ident_value(self, v, rule, path):
"""
log.debug(u"Init ident value : %s", path)

if v is None or not isinstance(v, bool):
if v is None or not is_bool(v):
raise RuleError(
msg=u"Value: '{0}' of 'ident' is not a boolean value".format(v),
error_key=u"ident.not_bool",
Expand Down Expand Up @@ -1028,7 +1029,7 @@ def init_unique_value(self, v, rule, path):
"""
log.debug(u"Init unique value : %s", path)

if not isinstance(v, bool):
if not is_bool(v):
raise RuleError(
msg=u"Value: '{0}' for 'unique' keyword is not boolean".format(v),
error_key=u"unique.not_bool",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def test_type_value(self):
# Test that type key must be string otherwise exception is raised
with pytest.raises(RuleError) as r:
Rule(schema={"type": 1})
assert str(r.value) == "<RuleError: error code 4: Key 'type' in schema rule is not a string type: Path: '/'>"
assert str(r.value) == "<RuleError: error code 4: Key 'type' in schema rule is not a string type (found int): Path: '/'>"
assert r.value.error_key == 'type.not_string'

# this tests that the type key must be a string
with pytest.raises(RuleError) as r:
Rule(schema={"type": 1}, parent=None)
assert str(r.value) == "<RuleError: error code 4: Key 'type' in schema rule is not a string type: Path: '/'>"
assert str(r.value) == "<RuleError: error code 4: Key 'type' in schema rule is not a string type (found int): Path: '/'>"
assert r.value.error_key == 'type.not_string'

def test_name_value(self):
Expand Down

0 comments on commit 35e1604

Please sign in to comment.