This directory contains comprehensive tests for graphics file generation and validation in gleplot.
The graphics testing suite includes:
-
Graphics Compilation Tests (
test_graphics_compilation.py)- Tests compilation of GLE scripts to PDF, EPS, and PNG formats
- Validates file existence, format correctness, and file sizes
- Tests with various plot types and features
-
Graphics Validation Tests (
test_graphics_validation.py)- Advanced validation using image analysis utilities
- Verifies file structure and integrity
- Tests formatting consistency across different formats
- Extracts and validates metadata (page count, bounding box, dimensions, etc.)
-
Graphics Analysis Module (
graphics_analysis.py)PDFAnalyzer: Analyze PDF structure and metadataEPSAnalyzer: Analyze EPS/PostScript structurePNGAnalyzer: Analyze PNG image propertiesvalidate_graphics_file(): Generic validation helper
pytest tests/integration/test_graphics_compilation.py tests/integration/test_graphics_validation.py -vpytest tests/integration/test_graphics_compilation.py::TestGraphicsCompilation -vpytest tests/integration/test_graphics_compilation.py::TestGraphicsCompilation::test_compile_to_pdf -vpytest tests/integration/test_graphics_*.py --cov=gleplot --cov-report=htmlTests basic compilation functionality:
test_save_gle_script: GLE file generationtest_compile_to_pdf: PDF compilationtest_compile_to_eps: EPS compilationtest_compile_to_png: PNG compilation with custom DPItest_pdf_contains_elements: PDF structure validationtest_eps_contains_elements: EPS structure validationtest_png_valid_header: PNG header validation
Tests file size and format properties:
test_pdf_file_size_reasonable: PDF file size validationtest_eps_file_size_reasonable: EPS file size validationtest_png_file_size_reasonable: PNG file size validation
Tests compilation with advanced plot features:
test_compile_with_fill_between: Fill between curvestest_compile_with_log_scale: Logarithmic scalestest_compile_with_multiple_colors: Multiple colors
Advanced validation tests:
test_validate_pdf_structure: Detailed PDF analysistest_validate_eps_structure: Detailed EPS analysistest_validate_png_structure: PNG validationtest_pdf_has_page_info: Extract page informationtest_eps_has_bounding_box: Extract bounding boxtest_png_has_dimensions: Extract image dimensionstest_png_color_depth: Validate color depthtest_validate_graphics_file_helper: Generic validation helper
Tests consistency across formats:
test_same_figure_multiple_formats: Same figure to PDF, EPS, PNGtest_complex_plot_all_formats: Complex plots across formats
- GLE (Graphics Layout Engine) installed on the system
- Available on PATH or can be found at standard locations
For more advanced image analysis:
pip install Pillow # For advanced PNG analysis
# or
pip install pdf2image # For advanced PDF analysisTests are automatically skipped if GLE is not available:
SKIPPED [100%] GLE compiler not available
To install GLE:
- macOS:
brew install gle - Linux:
apt-get install gleoryum install gle - Windows: Download from GLE website
Successful test runs produce:
- Valid PDF files with proper headers and structure
- Valid EPS files with PostScript headers and showpage
- Valid PNG files with PNG signatures and valid dimensions
tests/integration/test_graphics_compilation.py::TestGraphicsCompilation::test_compile_to_pdf PASSED
tests/integration/test_graphics_validation.py::TestGraphicsValidation::test_pdf_has_page_info PASSED
tests/integration/test_graphics_validation.py::TestGraphicsFormattingConsistency::test_same_figure_multiple_formats PASSED
Ensure GLE is installed and in PATH:
which gle
or
gle -infoIncrease timeout in GLECompiler if needed (default: 30 seconds)
Some PNG files may not have accessible dimension data. Check if PNG is valid first with PNGAnalyzer.is_valid_png()
graphics_analysis.py
├── PDFAnalyzer
│ ├── is_valid_pdf()
│ ├── get_file_size()
│ ├── has_valid_structure()
│ └── get_page_count()
├── EPSAnalyzer
│ ├── is_valid_eps()
│ ├── get_file_size()
│ ├── has_valid_structure()
│ └── get_bounding_box()
├── PNGAnalyzer
│ ├── is_valid_png()
│ ├── get_file_size()
│ ├── get_image_dimensions()
│ └── get_color_depth()
└── validate_graphics_file()
Potential additions:
- Pixel-level comparison: Compare rendered images pixel-by-pixel with reference images
- Text extraction: Extract and validate text from PDF/EPS files
- Color analysis: Verify correct colors are rendered
- Performance metrics: Track compilation time and file sizes
- Batch testing: Test collections of plots simultaneously