Files
EOS/tests/test_genetic0visualize.py
T

38 lines
1.1 KiB
Python
Raw Normal View History

2024-11-10 23:22:30 +01:00
from pathlib import Path
from matplotlib.testing.compare import compare_images
2026-08-01 12:45:19 +02:00
from akkudoktoreos.optimization.genetic0.genetic0visualize import (
genetic0_generate_example_report,
)
2024-12-24 13:10:31 +01:00
filename = "example_report.pdf"
2024-11-10 23:22:30 +01:00
2026-08-01 12:45:19 +02:00
DIR_TESTDATA = Path(__file__).parent / "testdata" / "genetic0"
2024-12-24 13:10:31 +01:00
reference_file = DIR_TESTDATA / "test_example_report.pdf"
2026-08-01 12:45:19 +02:00
reference_png_file = DIR_TESTDATA / "test_example_report_pdf.png"
2026-07-15 16:38:53 +02:00
output_file = DIR_TESTDATA / "test_example_report_new.pdf"
2026-08-01 12:45:19 +02:00
output_png_file = DIR_TESTDATA / "test_example_report_new_pdf.png"
2024-11-10 23:22:30 +01:00
def test_generate_pdf_example(config_eos):
2024-12-29 18:42:49 +01:00
"""Test generation of example visualization report."""
# Generate PDF
2026-08-01 12:45:19 +02:00
genetic0_generate_example_report(filename=str(output_file))
2024-11-11 21:38:13 +01:00
2024-12-24 13:10:31 +01:00
# Check if the file exists
assert output_file.exists()
2024-12-24 13:10:31 +01:00
# Compare the generated file with the reference file
comparison = compare_images(str(reference_file), str(output_file), tol=0)
# Assert that there are no differences
assert comparison is None, f"Images differ: {comparison}"
2026-08-01 12:45:19 +02:00
# Everything passed, remove compare file
reference_png_file.unlink()
output_file.unlink()
output_png_file.unlink()