Debian Codegraph @

test/integration/targets/ansible-test-coverage-windows/test-coverage.py

raw
1 from __future__ import annotations
2
3 import json
4 import os
5 import os.path
6 import pathlib
7
8
9 def main() -> None:
10 collection_root = pathlib.Path(os.getcwd())
11 print(f"Running windows-integration coverage test in '{collection_root}'")
12
13 result_path = collection_root / "tests" / "output" / "coverage" / "coverage-powershell"
14 adjacent_modules_path = collection_root / "tests" / "integration" / "targets" / "win_collection" / "library"
15 adjacent_utils_path = collection_root / "tests" / "integration" / "targets" / "win_collection" / "module_utils"
16 collection_modules_path = collection_root / "plugins" / "modules"
17 collection_utils_path = collection_root / "plugins" / "module_utils"
18
19 expected_hits = {
20 str(adjacent_modules_path / 'test_win_collection_async.ps1'): {'5': 1, '6': 1},
21 str(adjacent_modules_path / 'test_win_collection_become.ps1'): {'5': 1, '6': 1},
22 str(adjacent_modules_path / 'test_win_collection_normal.ps1'): {'6': 1, '7': 1, '8': 1},
23 str(adjacent_utils_path / 'Ansible.ModuleUtils.AdjacentPwshCoverage.psm1'): {'6': 1, '9': 1},
24 str(collection_modules_path / 'win_collection.ps1'): {'6': 1, '7': 1, '8': 1},
25 str(collection_utils_path / 'CollectionPwshCoverage.psm1'): {'6': 1, '9': 1},
26 }
27 found_hits = set()
28
29 with open(result_path, mode="rb") as fd:
30 data = json.load(fd)
31
32 for path, result in data.items():
33 print(f"Testing result for path '{path}' -> {result!r}")
34 assert path in expected_hits, f"Found unexpected coverage result path '{path}'"
35
36 expected = expected_hits[path]
37 assert result == expected, f"Coverage result for {path} was {result!r} but was expecting {expected!r}"
38 found_hits.add(path)
39
40 missing_hits = set(expected_hits.keys()).difference(found_hits)
41 assert not missing_hits, f"Expected coverage results for {', '.join(missing_hits)} but they were not present"
42
43
44 if __name__ == '__main__':
45 main()