32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class ReportPluginTests(unittest.TestCase):
|
|
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()
|