diff options
author | Erik Skultety <eskultet@redhat.com> | 2023-03-29 16:54:56 +0200 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2023-03-30 08:00:42 +0000 |
commit | a15fb83509a6208fb8f66bdda3a8bbfeef1a462e (patch) | |
tree | c39568efe4d8ed62b63ca01a853ca8f7bc33d933 | |
parent | bd9b208e36556d72e9ab68b603252aa79f1cf3f1 (diff) | |
download | libvirt-ci-a15fb83509a6208fb8f66bdda3a8bbfeef1a462e.zip libvirt-ci-a15fb83509a6208fb8f66bdda3a8bbfeef1a462e.tar.gz libvirt-ci-a15fb83509a6208fb8f66bdda3a8bbfeef1a462e.tar.bz2 |
tests: utils: Drop the now unused assert helpers
With all tests converted to use the 'diff' style equality check, we
don't need the original recursive assert helpers.
Signed-off-by: Erik Skultety <eskultet@redhat.com>
-rw-r--r-- | tests/test_utils/utils.py | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/tests/test_utils/utils.py b/tests/test_utils/utils.py index c430249..9751379 100644 --- a/tests/test_utils/utils.py +++ b/tests/test_utils/utils.py @@ -34,33 +34,6 @@ def format_err_msg(indices, err_msg): return err_msg -def assert_equal_list(actual, expected, indices, kind): - len_err = None - if len(actual) != len(expected): - # stash the error for later: printing the first different element - # has higher priority, but actual and expected will not be - # available later to print the error - len_err = format_err_msg(indices, f"expected {len(expected)} {kind}s, got {len(actual)}, ") - if len(actual) < len(expected): - len_err += f"first missing element: {repr(expected[len(actual)])}" - expected = expected[:len(actual)] - else: - len_err += f"first extra element: {repr(actual[len(expected)])}" - actual = actual[:len(expected)] - - indices.append(None) - try: - n = 0 - for i, j in zip(iter(actual), iter(expected)): - indices[-1] = f"at {kind} {n}" - assert_equal(i, j, indices) - n += 1 - finally: - indices.pop() - if len_err: - raise AssertionError(len_err) - - class Diff: def __init__(self, diffobj): self._obj = diffobj @@ -146,63 +119,6 @@ def _assert_equal(actual, expected, test_tmp_dir): ) -def assert_equal(actual, expected, indices): - if not isinstance(actual, type(expected)): - raise AssertionError(format_err_msg(indices, f"expected {type(expected)}, got {type(actual)}")) - - if isinstance(expected, list): - assert_equal_list(actual, expected, indices, "item") - - elif isinstance(expected, str) and "\n" in expected: - actual_lines = actual.split("\n") - expected_lines = expected.split("\n") - assert_equal_list(actual_lines, expected_lines, indices, "line") - - elif isinstance(expected, dict): - actual_keys = sorted(actual.keys()) - expected_keys = sorted(expected.keys()) - assert_equal_list(actual_keys, expected_keys, indices, "key") - - indices.append(None) - try: - for i in actual_keys: - indices[-1] = f"at key {i}" - assert_equal(actual[i], expected[i], indices) - finally: - indices.pop() - - elif actual != expected: - raise AssertionError(format_err_msg(indices, f"expected {repr(expected)}, got {repr(actual)}")) - - -def assert_yaml_matches_file(actual, expected_path, allow_regenerate=True): - if pytest.custom_args["regenerate_output"] and allow_regenerate: - # Make sure the target directory exists, since creating the - # output file would fail otherwise - expected_path.parent.mkdir(parents=True, exist_ok=True) - with open(expected_path, "w") as fd: - yaml.safe_dump(actual, stream=fd) - - with open(expected_path) as fd: - expected = yaml.safe_load(fd) - - assert_equal(actual, expected, [f"comparing against {expected_path}"]) - - -def assert_matches_file(actual, expected_path, allow_regenerate=True): - if pytest.custom_args["regenerate_output"] and allow_regenerate: - # Make sure the target directory exists, since creating the - # output file would fail otherwise - expected_path.parent.mkdir(parents=True, exist_ok=True) - with open(expected_path, "w") as fd: - fd.write(actual) - - with open(expected_path) as fd: - expected = fd.read() - - assert_equal(actual, expected, [f"comparing against {expected_path}"]) - - # Force loading the facts, for example to avoid conflicts with monkeypatching def force_load(packages=None, projects=None, targets=None): if packages: |