Skip to content

Commit

Permalink
test_schema.py: Adjust expectations to newer jsonschema versions
Browse files Browse the repository at this point in the history
  • Loading branch information
meaksh committed May 24, 2024
1 parent e6e2563 commit 33e72bb
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions tests/unit/utils/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ class Requirements(BaseRequirements):
jsonschema.validate(
{"personal_access_token": "foo"}, Requirements.serialize()
)
if JSONSCHEMA_VERSION >= Version("3.0.0"):
if JSONSCHEMA_VERSION >= Version("3.0.0") and JSONSCHEMA_VERSION < Version(
"4.8.0"
):
self.assertIn(
"'ssh_key_file' is a required property", excinfo.exception.message
)
Expand Down Expand Up @@ -899,13 +901,20 @@ class TestConf(schema.Schema):
except jsonschema.exceptions.ValidationError as exc:
self.fail(f"ValidationError raised: {exc}")

with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
if JSONSCHEMA_VERSION < Version("4.0.0"):
with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
jsonschema.validate(
{"item": "3"},
TestConf.serialize(),
format_checker=jsonschema.FormatChecker(),
)
self.assertIn("is not a", excinfo.exception.message)
else:
jsonschema.validate(
{"item": "3"},
TestConf.serialize(),
format_checker=jsonschema.FormatChecker(),
)
self.assertIn("is not a", excinfo.exception.message)

def test_datetime_config(self):
item = schema.DateTimeItem(title="Foo", description="Foo Item")
Expand Down Expand Up @@ -1878,7 +1887,9 @@ class TestConf(schema.Schema):
jsonschema.validate(
{"item": {"sides": "4", "color": "blue"}}, TestConf.serialize()
)
if JSONSCHEMA_VERSION >= Version("3.0.0"):
if JSONSCHEMA_VERSION >= Version("3.0.0") and JSONSCHEMA_VERSION < Version(
"4.8.0"
):
self.assertIn("'4'", excinfo.exception.message)
self.assertIn("is not of type", excinfo.exception.message)
self.assertIn("'boolean'", excinfo.exception.message)
Expand Down Expand Up @@ -2003,7 +2014,9 @@ class TestConf(schema.Schema):

with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
jsonschema.validate({"item": ["maybe"]}, TestConf.serialize())
if JSONSCHEMA_VERSION >= Version("3.0.0"):
if JSONSCHEMA_VERSION >= Version("3.0.0") and JSONSCHEMA_VERSION < Version(
"4.8.0"
):
self.assertIn("'maybe'", excinfo.exception.message)
self.assertIn("is not one of", excinfo.exception.message)
self.assertIn("'yes'", excinfo.exception.message)
Expand Down Expand Up @@ -2067,7 +2080,9 @@ class TestConf(schema.Schema):

with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
jsonschema.validate({"item": ["maybe"]}, TestConf.serialize())
if JSONSCHEMA_VERSION >= Version("3.0.0"):
if JSONSCHEMA_VERSION >= Version("3.0.0") and JSONSCHEMA_VERSION < Version(
"4.8.0"
):
self.assertIn("'maybe'", excinfo.exception.message)
self.assertIn("is not one of", excinfo.exception.message)
self.assertIn("'yes'", excinfo.exception.message)
Expand Down Expand Up @@ -2154,11 +2169,17 @@ class TestConf(schema.Schema):

with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
jsonschema.validate({"item": [True]}, TestConf.serialize())
self.assertIn("is not allowed for", excinfo.exception.message)
if JSONSCHEMA_VERSION >= Version("4.0.0"):
self.assertIn("should not be valid under", excinfo.exception.message)
else:
self.assertIn("is not allowed for", excinfo.exception.message)

with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
jsonschema.validate({"item": [False]}, TestConf.serialize())
self.assertIn("is not allowed for", excinfo.exception.message)
if JSONSCHEMA_VERSION >= Version("4.0.0"):
self.assertIn("should not be valid under", excinfo.exception.message)
else:
self.assertIn("is not allowed for", excinfo.exception.message)

def test_item_name_override_class_attrname(self):
class TestConf(schema.Schema):
Expand Down

0 comments on commit 33e72bb

Please sign in to comment.