mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-08-25 23:11:14 +00:00
Visualize reworked v2 (#267)
* initial commit * Delete duplicate openapi.json * revert temp cahnges * test fixed * mypy fixes * mypy fixed * Financial Overview included * test data save path * almost done * mypy fix * Update visualize.py * ruff fix * config, label * improved start_hour vis * fix * fix2
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from matplotlib.testing.compare import compare_images
|
||||
|
||||
from akkudoktoreos.config.config import get_config
|
||||
from akkudoktoreos.visualize import visualisiere_ergebnisse
|
||||
|
||||
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)
|
||||
|
||||
DIR_TESTDATA = Path(__file__).parent / "testdata"
|
||||
DIR_IMAGEDATA = DIR_TESTDATA / "images"
|
||||
reference_file = DIR_TESTDATA / "test_example_report.pdf"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"fn_in, fn_out, fn_out_base",
|
||||
[("visualize_input_1.json", "visualize_output_1.pdf", "visualize_base_output_1.pdf")],
|
||||
)
|
||||
def test_visualisiere_ergebnisse(fn_in, fn_out, fn_out_base):
|
||||
with open(DIR_TESTDATA / fn_in, "r") as f:
|
||||
input_data = json.load(f)
|
||||
visualisiere_ergebnisse(**input_data)
|
||||
def test_generate_pdf_main():
|
||||
# Delete the old generated file if it exists
|
||||
if os.path.isfile(output_file):
|
||||
os.remove(output_file)
|
||||
|
||||
config = get_config()
|
||||
output_dir = config.data_output_path
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
output_file = output_dir.joinpath(fn_out)
|
||||
# Execute the __main__ block of visualize.py by running it as a script
|
||||
script_path = Path(__file__).parent.parent / "src" / "akkudoktoreos" / "utils" / "visualize.py"
|
||||
subprocess.run(["python", str(script_path)], check=True)
|
||||
|
||||
assert output_file.is_file()
|
||||
assert (
|
||||
compare_images(
|
||||
str(output_file),
|
||||
str(DIR_IMAGEDATA / fn_out_base),
|
||||
0,
|
||||
)
|
||||
is None
|
||||
)
|
||||
# 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}"
|
||||
|
Reference in New Issue
Block a user