Skip to content

Commit

Permalink
test before fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JoschD committed Sep 16, 2024
1 parent 5f7cfb5 commit 3befb87
Showing 1 changed file with 68 additions and 10 deletions.
78 changes: 68 additions & 10 deletions tests/unit/test_check_corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
from generic_parser import DotDict
from matplotlib.figure import Figure

from omc3.check_corrections import (_get_measurement_filter,
correction_test_entrypoint)
from omc3.check_corrections import _get_measurement_filter, correction_test_entrypoint
from omc3.correction.constants import MODEL_MATCHED_FILENAME
from omc3.correction.handler import get_filename_from_parameter
from omc3.correction.model_appenders import add_coupling_to_model
from omc3.definitions.optics import (FILE_COLUMN_MAPPING, RDT_COLUMN_MAPPING,
TUNE_COLUMN, ColumnsAndLabels)
from omc3.definitions.optics import (
FILE_COLUMN_MAPPING,
RDT_COLUMN_MAPPING,
TUNE_COLUMN,
ColumnsAndLabels,
)
from omc3.model.constants import TWISS_DAT
from omc3.optics_measurements.constants import (EXT, MDL, NAME, NAME2, PHASE,
PHASE_ADV, TUNE, S)
from omc3.plotting.plot_checked_corrections import SPLIT_ID, show_plots
from omc3.optics_measurements.constants import (
EXT,
MDL,
NAME,
NAME2,
PHASE,
PHASE_ADV,
TUNE,
S,
)
from omc3.plotting.plot_checked_corrections import (
SINGLE_PLANE_FILES,
SPLIT_ID,
show_plots,
)
from omc3.scripts.fake_measurement_from_model import generate as fake_measurement
from tests.accuracy.test_global_correction import (get_normal_params, get_skew_params)
from tests.accuracy.test_global_correction import get_normal_params, get_skew_params


class TestFullRun:
Expand Down Expand Up @@ -261,7 +276,50 @@ def test_normal_params(self, monkeypatch):
assert plottab.title == "param1"
else:
assert plottab.title == "param 2"

@pytest.mark.basic
def test_single_plane_files(self, monkeypatch):
single_name = SINGLE_PLANE_FILES[0] # so far only one anyway

figure_dict = {
f"correction1{SPLIT_ID}{single_name}x": Figure(),
f"correction1{SPLIT_ID}param_2_x": Figure(),
f"correction1{SPLIT_ID}param_2_y": Figure(),
f"correction2{SPLIT_ID}{single_name}x": Figure(),
f"correction2{SPLIT_ID}param_2_x": Figure(),
f"correction2{SPLIT_ID}param_2_y": Figure(),
f"{single_name}x_PARAM1X": Figure(),
"param_2_x_PARAM2X": Figure(),
"param_2_y_PARAM2Y": Figure(),
}

monkeypatch.setattr("omc3.plotting.plot_checked_corrections.TabWidget", MockTabAndWindow)
monkeypatch.setattr("omc3.plotting.plot_checked_corrections.PlotWidget", MockPlotWidget)
window = MockTabAndWindow("")
monkeypatch.setattr("omc3.plotting.plot_checked_corrections.VerticalTabWindow", window)

show_plots(figure_dict)

assert window.title != "" # set to something else
assert window.shown

assert len(window.tabs) == 3 # 1 for all, 2 for correction[12]
for idx_tab, tab in enumerate(window.tabs):
if idx_tab:
assert tab.title == f"correction{idx_tab}"

assert len(tab.tabs) == 2 # two params

for idx, plottab in enumerate(tab.tabs):
assert isinstance(plottab, MockPlotWidget)
if idx == 0:
assert plottab.title == single_name.replace("_"," ").strip()
assert isinstance(plottab.fig1, Figure)
assert plottab.fig2 is None
else:
assert plottab.title == "param 2"
assert isinstance(plottab.fig1, Figure)
assert isinstance(plottab.fig2, Figure)

@pytest.mark.basic
def test_rdt_params(self, monkeypatch):
Expand Down Expand Up @@ -353,8 +411,8 @@ def show(self):
@dataclass
class MockPlotWidget:
fig1: Figure
fig2: Figure
title: str
fig2: Figure = None
title: str = ""


def _create_fake_measurement(tmp_path, model_path, twiss_path):
Expand Down

0 comments on commit 3befb87

Please sign in to comment.