diff --git a/foqus_lib/gui/tests/test_sdoe.py b/foqus_lib/gui/tests/test_sdoe.py index 54bc46114..0010f4829 100644 --- a/foqus_lib/gui/tests/test_sdoe.py +++ b/foqus_lib/gui/tests/test_sdoe.py @@ -42,7 +42,7 @@ def setup_frame_blank(main_window, flowsheet_session_file, request): @pytest.mark.usefixtures("setup_frame_blank") -class TestSDOE: +class TestUSF: @property def analysis_dialog(self) -> typing.Union[None, sdoeAnalysisDialog]: return self.__class__.frame._analysis_dialog @@ -100,3 +100,143 @@ def has_dialog(): qtbot.click(button="OK") qtbot.click(button="Open SDoE Dialog") qtbot.wait_until(has_dialog, timeout=10_000) + + +@pytest.mark.xfail( + reason="this test class will fail if run after another test in the same module" +) +@pytest.mark.usefixtures("setup_frame_blank") +class TestNUSF1: + @property + def analysis_dialog(self) -> typing.Union[None, sdoeAnalysisDialog]: + return self.__class__.frame._analysis_dialog + + def test_run_sdoe(self, qtbot, start_analysis): + assert self.analysis_dialog is not None + qtbot.focused = self.analysis_dialog + with qtbot.focusing_on(group_box="Desired Design Size and NUSF Weights"): + qtbot.using(spin_box="Design Size").enter_value(10) + dropdown_1, dropdown_2 = qtbot.locate(combo_box=..., index=[1, 2]) + qtbot.using(dropdown_1).set_option("10") + qtbot.using(dropdown_2).set_option("30") + with qtbot.focusing_on(group_box="Generate Design"): + with qtbot.focusing_on(table=...) as table: + qtbot.select_row(3) + qtbot.using(column="Type").set_option("Weight") + qtbot.click(button="Estimate Runtime") + + with qtbot.focusing_on(group_box="SDoE Progress"): + qtbot.using(combo_box="Number of Random Starts: n =").set_option("10") + run_button = qtbot.locate_widget(button="Run SDoE") + with qtbot.searching_within(self.analysis_dialog): + with qtbot.searching_within(group_box="Created Designs"): + created_designs_table = qtbot.locate_widget(table=any) + + def created_designs_table_is_populated() -> bool: + return created_designs_table.rowCount() > 0 + + qtbot.using(run_button).click() + + qtbot.wait_until(created_designs_table_is_populated, timeout=120_000) + with qtbot.searching_within(self.analysis_dialog): + with qtbot.searching_within(group_box="Created Designs"): + with qtbot.focusing_on(table=any): + for i in range(created_designs_table.rowCount()): + qtbot.select_row(i) + with qtbot.waiting_for_modal(timeout=10_000): + qtbot.using(column="Plot SDoE").click() + with qtbot.searching_within(sdoePreview): + with qtbot.searching_within(group_box="Plots"): + qtbot.click(button="Plot SDoE") + qtbot.wait(1000) + qtbot.click(button="OK") + + @pytest.fixture(scope="class") + def start_analysis(self, qtbot, foqus_examples_dir): + def has_dialog(): + return self.analysis_dialog is not None + + qtbot.focused = self.frame + with qtbot.file_selection( + foqus_examples_dir / "tutorial_files/SDOE/NUSFex1.csv" + ): + qtbot.click(button="Load Existing\n Set") + qtbot.click(button="Continue") + with qtbot.searching_within(group_box="Design Construction") as gb: + with qtbot.searching_within(table=...) as t: + qtbot.select_row(3) + qtbot.using(column="Descriptor").set_option( + "Non-Uniform Space Filling (NUSF)" + ) + qtbot.click(button="Open SDoE Dialog") + qtbot.wait_until(has_dialog, timeout=10_000) + + +@pytest.mark.xfail( + reason="this test class will fail if run after another test in the same module" +) +@pytest.mark.usefixtures("setup_frame_blank") +class Test_NUSF2: + @property + def analysis_dialog(self) -> typing.Union[None, sdoeAnalysisDialog]: + return self.__class__.frame._analysis_dialog + + def test_run_sdoe(self, qtbot, start_analysis): + assert self.analysis_dialog is not None + qtbot.focused = self.analysis_dialog + with qtbot.focusing_on(group_box="Desired Design Size and NUSF Weights"): + qtbot.using(spin_box="Design Size").enter_value(20) + dropdown_1, dropdown_2 = qtbot.locate(combo_box=..., index=[0, 1]) + qtbot.using(dropdown_1).set_option("2") + qtbot.using(dropdown_2).set_option("5") + with qtbot.focusing_on(group_box="Generate Design"): + with qtbot.focusing_on(table=...) as table: + qtbot.select_row(5) + qtbot.using(column="Type").set_option("Weight") + qtbot.click(button="Estimate Runtime") + + with qtbot.focusing_on(group_box="SDoE Progress"): + qtbot.using(combo_box="Number of Random Starts: n =").set_option("10") + run_button = qtbot.locate_widget(button="Run SDoE") + with qtbot.searching_within(self.analysis_dialog): + with qtbot.searching_within(group_box="Created Designs"): + created_designs_table = qtbot.locate_widget(table=any) + + def created_designs_table_is_populated() -> bool: + return created_designs_table.rowCount() > 0 + + qtbot.using(run_button).click() + + qtbot.wait_until(created_designs_table_is_populated, timeout=120_000) + with qtbot.searching_within(self.analysis_dialog): + with qtbot.searching_within(group_box="Created Designs"): + with qtbot.focusing_on(table=any): + for i in range(created_designs_table.rowCount()): + qtbot.select_row(i) + with qtbot.waiting_for_modal(timeout=10_000): + qtbot.using(column="Plot SDoE").click() + with qtbot.searching_within(sdoePreview): + with qtbot.searching_within(group_box="Plots"): + qtbot.click(button="Plot SDoE") + qtbot.wait(1000) + qtbot.click(button="OK") + + @pytest.fixture(scope="class") + def start_analysis(self, qtbot, foqus_examples_dir): + def has_dialog(): + return self.analysis_dialog is not None + + qtbot.focused = self.frame + with qtbot.file_selection( + foqus_examples_dir / "tutorial_files/SDOE/CCSIex.csv" + ): + qtbot.click(button="Load Existing\n Set") + qtbot.click(button="Continue") + with qtbot.searching_within(group_box="Design Construction") as gb: + with qtbot.searching_within(table=...) as t: + qtbot.select_row(3) + qtbot.using(column="Descriptor").set_option( + "Non-Uniform Space Filling (NUSF)" + ) + qtbot.click(button="Open SDoE Dialog") + qtbot.wait_until(has_dialog, timeout=10_000)