from pathlib import Path import json import os import subprocess import tempfile import unittest ROOT = Path(__file__).resolve().parents[2] class SourceTests(unittest.TestCase): def test_stored_sources_have_expected_sets(self): self.assertEqual(len(list((ROOT / "reports/reports").glob("*.yaml"))), 7) self.assertEqual(len(list((ROOT / "reports/diagnostics").glob("*.json"))), 10) for path in (ROOT / "reports/diagnostics").glob("*.json"): document = json.loads(path.read_text()) self.assertEqual(document["report_type"], "windows_system_maintenance") def test_diagnostic_plugin_renders_raw_capture(self): capture = next((ROOT / "reports/diagnostics").glob("*.json")) with tempfile.TemporaryDirectory() as directory: output = Path(directory) / "diagnostic.pdf" result = subprocess.run([str(ROOT / "reporter/build.sh"), "render", "diagnostic", str(capture), "--output", str(output)], text=True, capture_output=True, env=os.environ.copy()) self.assertEqual(result.returncode, 0, result.stderr) self.assertTrue(output.read_bytes().startswith(b"%PDF-")) if __name__ == "__main__": unittest.main()