From 33e72bb766ad1063d966f52fb2e058608c035325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= Date: Fri, 24 May 2024 15:35:51 +0100 Subject: [PATCH] test_schema.py: Adjust expectations to newer jsonschema versions --- tests/unit/utils/test_schema.py | 37 ++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/tests/unit/utils/test_schema.py b/tests/unit/utils/test_schema.py index ebe3698978fc..5343726e1237 100644 --- a/tests/unit/utils/test_schema.py +++ b/tests/unit/utils/test_schema.py @@ -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 ) @@ -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") @@ -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) @@ -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) @@ -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) @@ -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):