Debian Codegraph @

python/unit_tests/test_test_data.py

raw
1 # SPDX-FileCopyrightText: Peter Pentchev <[email protected]>
2 # SPDX-License-Identifier: BSD-2-Clause
3
4 """Make sure the test data is up to date."""
5
6 import pathlib
7 from typing import Set
8
9
10 def test_test_data() -> None:
11 """Compare the test data to the one in the source t/ directory."""
12
13 def get_files(path: pathlib.Path) -> Set[pathlib.Path]:
14 """Get the relevant files from the test data directory."""
15 tdefs = path / "defs/tests"
16 files_ini = set(path.glob("*.ini"))
17 files_tests = set(tdefs.glob("*.json"))
18 assert files_ini
19 assert files_tests
20 files = files_ini | files_tests
21 assert (path.is_file() for path in files)
22 return files
23
24 local = pathlib.Path(__file__).parent.parent / "test_data"
25 local_tests = get_files(local)
26
27 upstream = pathlib.Path(__file__).parent.parent.parent / "t"
28 if not upstream.is_dir():
29 return
30 upstream_tests = get_files(upstream)
31
32 for test in sorted(upstream_tests):
33 local_test = local / test.relative_to(upstream)
34 assert local_test.is_file()
35 assert local_test.read_text(encoding="UTF-8") == test.read_text(encoding="UTF-8")
36
37 for test in sorted(local_tests):
38 upstream_test = upstream / test.relative_to(local)
39 assert upstream_test.is_file()