53 lines
2.6 KiB
Python
53 lines
2.6 KiB
Python
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class ReportPluginTests(unittest.TestCase):
|
|
def test_public_cli_renders_diagnostic_from_standalone_checkout(self):
|
|
fixture = ROOT / "plugins/diagnostics/tests/fixtures/legacy/windiagnostics-v1.json"
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
output = Path(directory) / "diagnostic.pdf"
|
|
result = subprocess.run([str(ROOT / "build.sh"), "render", "diagnostic", str(fixture),
|
|
"--output", str(output)], text=True, capture_output=True)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertTrue(output.read_bytes().startswith(b"%PDF-"))
|
|
|
|
def test_public_cli_batch_preserves_relative_paths(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
work = Path(directory)
|
|
source = work / "source/nested"
|
|
source.mkdir(parents=True)
|
|
(source / "item.yaml").write_bytes((ROOT / "examples/example-report.yaml").read_bytes())
|
|
output = work / "output"
|
|
result = subprocess.run([str(ROOT / "build.sh"), "render-all", "report", str(work / "source"),
|
|
"--output-dir", str(output)], text=True, capture_output=True)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertTrue((output / "nested/item.pdf").read_bytes().startswith(b"%PDF-"))
|
|
|
|
def test_report_renders_with_its_own_typst_model(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
output = Path(directory) / "report.pdf"
|
|
result = subprocess.run([str(ROOT / "render.sh"), str(ROOT / "examples/example-report.yaml"),
|
|
"--output", str(output)], text=True, capture_output=True)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
pdf = output.read_bytes()
|
|
self.assertTrue(pdf.startswith(b"%PDF-"))
|
|
self.assertGreater(len(pdf), 1024)
|
|
|
|
def test_existing_output_requires_force(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
output = Path(directory) / "report.pdf"
|
|
output.write_text("existing")
|
|
result = subprocess.run([str(ROOT / "render.sh"), str(ROOT / "examples/example-report.yaml"),
|
|
"--output", str(output)], text=True, capture_output=True)
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertEqual(output.read_text(), "existing")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|