Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DilwoarH/pdf-visual-regression/llms.txt
Use this file to discover all available pages before exploring further.
Test suite overview
The project uses Python’s built-inunittest framework to ensure reliability and catch regressions. Tests are located in the tests/ directory and cover the core comparison scenarios.
Running tests
make test command automatically:
- Sets up the test environment
- Generates test PDF fixtures
- Runs all test cases
- Reports results
Test PDFs are automatically generated on first run. If you need to regenerate them, run
make clean followed by make test.Test structure
Test files
| File | Purpose |
|---|---|
tests/test_diff_script.py | Main test suite with comparison test cases |
tests/create_test_pdfs.py | Test fixture generator for PDF samples |
tests/test_pdfs/ | Directory containing generated test PDFs |
tests/test_output/ | Directory for test output (cleaned by make clean) |
Test fixtures
Thecreate_test_pdfs.py script generates four test PDFs using ReportLab:
tests/create_test_pdfs.py:22-34):
test1_original.pdf
test1_original.pdf
A simple single-page PDF with the text “This is a test.”Used as the baseline for all comparison tests.
test1_identical.pdf
test1_identical.pdf
An exact duplicate of
test1_original.pdf.Used to test that identical PDFs produce no differences.test2_different_text.pdf
test2_different_text.pdf
A single-page PDF with different text: “This is a different test.”Used to verify that text differences are detected.
test3_different_pages.pdf
test3_different_pages.pdf
A two-page PDF where:
- Page 1: “This is a test.” (identical to test1_original)
- Page 2: “Page 2” (extra page)
Test cases
TheTestPdfVisualDiff class contains three core test scenarios:
Test 1: Identical PDFs
tests/test_diff_script.py:14-25):
- Identical PDFs return success status
- No diff images are generated
- Correct console output message
Test 2: Different text content
tests/test_diff_script.py:27-38):
- Text differences are detected via SSIM
- Diff images are generated for changed pages
- Page numbers are correctly reported
Test 3: Different page counts
tests/test_diff_script.py:40-53):
- Warning message for mismatched page counts
- Comparison continues for overlapping pages
- Extra pages are handled without errors
Test setup and teardown
setUp method
Before each test, the suite ensures test PDFs exist:tests/test_diff_script.py:7-12
Cleanup
Runmake clean to remove all generated test files:
tests/test_output/- Test execution outputstests/test_pdfs/- Generated fixture PDFs__pycache__/directoriesdiff_output/- Default output directory
Makefile:24-29
Makefile targets
The project includes several Make targets for development:Adding new tests
To add a new test case:Test coverage
The current test suite covers:- ✅ Identical PDF comparison
- ✅ Text content differences
- ✅ Different page count handling
- ✅ Output directory creation
- ✅ Console output messages
- ✅ Diff image generation
Coverage gaps
Areas that could benefit from additional testing:- Custom SSIM threshold values
- Different page dimensions
- Image-heavy PDFs
- Multi-page diff scenarios
- JSON output validation
- Performance with large PDFs
- Edge cases (empty PDFs, corrupted files)
Consider using
coverage.py to measure code coverage: