Stages/test/tuned: handle "improved" jsonschema messages

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] 8875c2ecb1 (diff-c21226b904760a669a70785494cd8ecf5fb1e7415fd25765dd02f0ad00394099R231)

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2024-12-20 13:56:47 +01:00 committed by Brian C. Lane
parent 806f949e8c
commit 6a4a7c31c6

View file

@ -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", (