diff --git a/Makefile b/Makefile index 17a35d3..217416d 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,9 @@ build-macos-arm: build-clean build-linux: build-clean doit -n 8 fedora_rpm debian_deb +.PHONY: regenerate-reference-pdfs +regenerate-reference-pdfs: + pytest tests/test_cli.py -k regenerate --generate-reference-pdfs # Makefile self-help borrowed from the securedrop-client project # Explaination of the below shell command should it ever break. # 1. Set the field separator to ": ##" and any make targets that might appear between : and ## diff --git a/tests/conftest.py b/tests/conftest.py index 2f9673c..ab0441c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -160,3 +160,22 @@ def for_each_external_doc(glob_pattern: str = "*") -> Callable: class TestBase: sample_doc = str(test_docs_dir.joinpath(BASIC_SAMPLE_PDF)) + + +def pytest_addoption(parser): + parser.addoption( + "--generate-reference-pdfs", + action="store_true", + default=False, + help="Regenerate reference PDFs", + ) + + +def pytest_collection_modifyitems(config, items): + if not config.getoption("--generate-reference-pdfs"): + skip_generator = pytest.mark.skip( + reason="Only run when --generate-reference-pdfs is provided" + ) + for item in items: + if "reference_generator" in item.keywords: + item.add_marker(skip_generator) diff --git a/tests/test_cli.py b/tests/test_cli.py index f4b8e68..97c5f31 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -194,6 +194,14 @@ class TestCliConversion(TestCliBasic): result = self.run_cli([sample_pdf, "--ocr-lang", "piglatin"]) result.assert_failure() + @pytest.mark.reference_generator + @for_each_doc + def test_regenerate_reference(self, doc: Path) -> None: + reference = (doc.parent / "reference" / doc.stem).with_suffix(".pdf") + + result = self.run_cli([str(doc), "--output-filename", str(reference)]) + result.assert_success() + @for_each_doc def test_formats(self, doc: Path, tmp_path_factory: pytest.TempPathFactory) -> None: reference = (doc.parent / "reference" / doc.stem).with_suffix(".pdf")