2024-12-24 13:10:31 +01:00
|
|
|
import os
|
2024-11-10 23:22:30 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from matplotlib.testing.compare import compare_images
|
|
|
|
|
2024-12-15 14:40:03 +01:00
|
|
|
from akkudoktoreos.config.config import get_config
|
2024-12-29 18:42:49 +01:00
|
|
|
from akkudoktoreos.utils.visualize import generate_example_report
|
2024-12-24 13:10:31 +01:00
|
|
|
|
|
|
|
filename = "example_report.pdf"
|
|
|
|
|
|
|
|
config = get_config()
|
|
|
|
output_dir = config.data_output_path
|
|
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
output_file = os.path.join(output_dir, filename)
|
2024-11-10 23:22:30 +01:00
|
|
|
|
|
|
|
DIR_TESTDATA = Path(__file__).parent / "testdata"
|
2024-12-24 13:10:31 +01:00
|
|
|
reference_file = DIR_TESTDATA / "test_example_report.pdf"
|
|
|
|
|
|
|
|
|
2024-12-29 18:42:49 +01:00
|
|
|
def test_generate_pdf_example():
|
|
|
|
"""Test generation of example visualization report."""
|
2024-12-24 13:10:31 +01:00
|
|
|
# Delete the old generated file if it exists
|
|
|
|
if os.path.isfile(output_file):
|
|
|
|
os.remove(output_file)
|
|
|
|
|
2024-12-29 18:42:49 +01:00
|
|
|
generate_example_report(filename)
|
2024-12-24 13:10:31 +01:00
|
|
|
|
|
|
|
# Check if the file exists
|
|
|
|
assert os.path.isfile(output_file)
|
|
|
|
|
|
|
|
# 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}"
|