37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
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):
|
|
manifest = json.loads((ROOT / "reports/docs/legacy-source-manifest.json").read_text())
|
|
for entry in manifest["files"]:
|
|
if not (entry["destination"] or "").startswith(("reports/", "diagnostics/")):
|
|
continue
|
|
path = ROOT / "reports" / entry["destination"]
|
|
with self.subTest(source=entry["destination"]):
|
|
self.assertTrue(path.is_file(), f"Missing preserved source: {path}")
|
|
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()
|