Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion menu_tools/rate_plots/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def __init__(self, cfg, data, offline_pt: bool):

## Overwrite outdir
self._outdir = os.path.join(
"outputs", self.cfg.version, "object_performance", "rates"
"outputs", self.cfg.version, "rate_plots"
#"outputs", self.cfg.version, "object_performance", "rates"
)

@property
Expand Down
26 changes: 23 additions & 3 deletions menu_tools/rate_plots/tests/test_rate_plots_v29.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
from unittest.mock import patch
import re
import sys
from datetime import datetime, timedelta
from pathlib import Path

import numpy as np
import pytest

from menu_tools.rate_plots import plotter



testdata = [
"HTRates",
]


@pytest.mark.parametrize("test_name", testdata)
def test_matching_plots_reproduced(test_name):
# Prepare patching of the command line arguments for argparse
Expand All @@ -25,15 +27,31 @@ def test_matching_plots_reproduced(test_name):
f"menu_tools/rate_plots/tests/reference_data/{test_name}.yaml",
]

# Record time before creating output
time_stamp = datetime.now()

# Run Plotting
with patch.object(sys, "argv", testargs):
plotter.main()
pass

# Load result and assert correct outcome (Offline)
for online_offline in ["Online", "Offline"]:

output_path = Path(f"outputs/V29/rate_plots/V29_{online_offline}_{test_name}.json")
output_dir = "outputs/V29/rate_plots"
# Assert: Check whether output files were created
assert output_path.exists(), f"Expected output {output_path} does not exist."

# Assert: Check if file was put in correct directory
assert output_path.parent == Path(output_dir), f"Output file was not created in specified directory {output_dir}."

#Assert: Check whether new file was created or rather just existed before
file_creation_time = datetime.fromtimestamp(output_path.stat().st_mtime)
assert file_creation_time >= time_stamp, f"{output_path} already existed before plotter was called."

with open(
f"outputs/rate_plots/V29_{online_offline}_{test_name}.json",
f"outputs/V29/rate_plots/V29_{online_offline}_{test_name}.json",
"r",
) as f:
test_result = json.load(f)
Expand Down Expand Up @@ -61,3 +79,5 @@ def test_matching_plots_reproduced(test_name):
raise e
else:
assert val == test_result[key]