From 6a4a7c31c6a3067874b9ba8cfa49099fe5ffbe46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Fri, 20 Dec 2024 13:56:47 +0100 Subject: [PATCH] Stages/test/tuned: handle "improved" jsonschema messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit python-jsonschema improved the error messages for some special cases since v4.21.0 [0], which means that we need to handle multiple versions of the error message in unit tests. [0] https://github.com/python-jsonschema/jsonschema/commit/8875c2ecb1094d8ba265a071d4c1ce9df1a94733#diff-c21226b904760a669a70785494cd8ecf5fb1e7415fd25765dd02f0ad00394099R231 Signed-off-by: Tomáš Hozza --- stages/test/test_tuned.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/stages/test/test_tuned.py b/stages/test/test_tuned.py index eebeb060..23898eaa 100644 --- a/stages/test/test_tuned.py +++ b/stages/test/test_tuned.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +import re + import pytest from osbuild.testutil import ( @@ -12,12 +14,12 @@ STAGE_NAME = "org.osbuild.tuned" @pytest.mark.parametrize("test_data,expected_err", [ # bad - ({"profiles": {}}, "{} is not of type 'array'"), - ({"profiles": ""}, "'' is not of type 'array'"), - ({"profiles": []}, "[] is too short"), - ({"profiles": [0]}, "0 is not of type 'string'"), - ({"profiles": [""]}, "'' is too short"), - ({}, "'profiles' is a required property"), + ({"profiles": {}}, r"{} is not of type 'array'"), + ({"profiles": ""}, r"'' is not of type 'array'"), + ({"profiles": []}, r"(\[\] is too short|\[\] should be non-empty)"), + ({"profiles": [0]}, r"0 is not of type 'string'"), + ({"profiles": [""]}, r"('' is too short|'' should be non-empty)"), + ({}, r"'profiles' is a required property"), # good ({"profiles": ["balanced"]}, ""), ({"profiles": ["balanced", "sap-hana"]}, ""), @@ -34,7 +36,7 @@ def test_schema_validation(stage_schema, test_data, expected_err): assert res.valid is True, f"err: {[e.as_dict() for e in res.errors]}" else: assert res.valid is False - assert_jsonschema_error_contains(res, expected_err, expected_num_errs=1) + assert_jsonschema_error_contains(res, re.compile(expected_err), expected_num_errs=1) @pytest.mark.parametrize("fake_tree,available_profiles", (