Skip to content

Commit

Permalink
Improving SDoE GUI Testing Coverage (#1220)
Browse files Browse the repository at this point in the history
* TestNUSF in progress

For issue #1218

* Working NUSF Dropdown Selection

* Formatting

* Implement Run SDoE in Test

* Add Test for NUSF Plotting

* Check Generated Design rows instead of run button

* Working test for NUSF-2 Tutorial

* Placing NUSF and NUSF2 tests together causes other error

* NUSF and NUSF2 now in separate files

The two tests succeed when run individually, but not when all tests are run together

* Change window fixture scope to "module"

* Run black .

* Revert conftest.py change

* Move NUSF tests to test_sdoe.py

* Try uploading coverage report even if pytest step fails

---------

Co-authored-by: Pedro Sotorrio <[email protected]>
Co-authored-by: Ludovico Bianchi <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent c33fd58 commit 1dd5a24
Showing 1 changed file with 141 additions and 1 deletion.
142 changes: 141 additions & 1 deletion foqus_lib/gui/tests/test_sdoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 1dd5a24

Please sign in to comment.