Skip to content

Commit 1dd5a24

Browse files
franflamesotorrio1lbianchi-lbl
authored
Improving SDoE GUI Testing Coverage (#1220)
* 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 <sotorrio1@llnl.gov> Co-authored-by: Ludovico Bianchi <lbianchi@lbl.gov>
1 parent c33fd58 commit 1dd5a24

1 file changed

Lines changed: 141 additions & 1 deletion

File tree

foqus_lib/gui/tests/test_sdoe.py

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def setup_frame_blank(main_window, flowsheet_session_file, request):
4242

4343

4444
@pytest.mark.usefixtures("setup_frame_blank")
45-
class TestSDOE:
45+
class TestUSF:
4646
@property
4747
def analysis_dialog(self) -> typing.Union[None, sdoeAnalysisDialog]:
4848
return self.__class__.frame._analysis_dialog
@@ -100,3 +100,143 @@ def has_dialog():
100100
qtbot.click(button="OK")
101101
qtbot.click(button="Open SDoE Dialog")
102102
qtbot.wait_until(has_dialog, timeout=10_000)
103+
104+
105+
@pytest.mark.xfail(
106+
reason="this test class will fail if run after another test in the same module"
107+
)
108+
@pytest.mark.usefixtures("setup_frame_blank")
109+
class TestNUSF1:
110+
@property
111+
def analysis_dialog(self) -> typing.Union[None, sdoeAnalysisDialog]:
112+
return self.__class__.frame._analysis_dialog
113+
114+
def test_run_sdoe(self, qtbot, start_analysis):
115+
assert self.analysis_dialog is not None
116+
qtbot.focused = self.analysis_dialog
117+
with qtbot.focusing_on(group_box="Desired Design Size and NUSF Weights"):
118+
qtbot.using(spin_box="Design Size").enter_value(10)
119+
dropdown_1, dropdown_2 = qtbot.locate(combo_box=..., index=[1, 2])
120+
qtbot.using(dropdown_1).set_option("10")
121+
qtbot.using(dropdown_2).set_option("30")
122+
with qtbot.focusing_on(group_box="Generate Design"):
123+
with qtbot.focusing_on(table=...) as table:
124+
qtbot.select_row(3)
125+
qtbot.using(column="Type").set_option("Weight")
126+
qtbot.click(button="Estimate Runtime")
127+
128+
with qtbot.focusing_on(group_box="SDoE Progress"):
129+
qtbot.using(combo_box="Number of Random Starts: n =").set_option("10")
130+
run_button = qtbot.locate_widget(button="Run SDoE")
131+
with qtbot.searching_within(self.analysis_dialog):
132+
with qtbot.searching_within(group_box="Created Designs"):
133+
created_designs_table = qtbot.locate_widget(table=any)
134+
135+
def created_designs_table_is_populated() -> bool:
136+
return created_designs_table.rowCount() > 0
137+
138+
qtbot.using(run_button).click()
139+
140+
qtbot.wait_until(created_designs_table_is_populated, timeout=120_000)
141+
with qtbot.searching_within(self.analysis_dialog):
142+
with qtbot.searching_within(group_box="Created Designs"):
143+
with qtbot.focusing_on(table=any):
144+
for i in range(created_designs_table.rowCount()):
145+
qtbot.select_row(i)
146+
with qtbot.waiting_for_modal(timeout=10_000):
147+
qtbot.using(column="Plot SDoE").click()
148+
with qtbot.searching_within(sdoePreview):
149+
with qtbot.searching_within(group_box="Plots"):
150+
qtbot.click(button="Plot SDoE")
151+
qtbot.wait(1000)
152+
qtbot.click(button="OK")
153+
154+
@pytest.fixture(scope="class")
155+
def start_analysis(self, qtbot, foqus_examples_dir):
156+
def has_dialog():
157+
return self.analysis_dialog is not None
158+
159+
qtbot.focused = self.frame
160+
with qtbot.file_selection(
161+
foqus_examples_dir / "tutorial_files/SDOE/NUSFex1.csv"
162+
):
163+
qtbot.click(button="Load Existing\n Set")
164+
qtbot.click(button="Continue")
165+
with qtbot.searching_within(group_box="Design Construction") as gb:
166+
with qtbot.searching_within(table=...) as t:
167+
qtbot.select_row(3)
168+
qtbot.using(column="Descriptor").set_option(
169+
"Non-Uniform Space Filling (NUSF)"
170+
)
171+
qtbot.click(button="Open SDoE Dialog")
172+
qtbot.wait_until(has_dialog, timeout=10_000)
173+
174+
175+
@pytest.mark.xfail(
176+
reason="this test class will fail if run after another test in the same module"
177+
)
178+
@pytest.mark.usefixtures("setup_frame_blank")
179+
class Test_NUSF2:
180+
@property
181+
def analysis_dialog(self) -> typing.Union[None, sdoeAnalysisDialog]:
182+
return self.__class__.frame._analysis_dialog
183+
184+
def test_run_sdoe(self, qtbot, start_analysis):
185+
assert self.analysis_dialog is not None
186+
qtbot.focused = self.analysis_dialog
187+
with qtbot.focusing_on(group_box="Desired Design Size and NUSF Weights"):
188+
qtbot.using(spin_box="Design Size").enter_value(20)
189+
dropdown_1, dropdown_2 = qtbot.locate(combo_box=..., index=[0, 1])
190+
qtbot.using(dropdown_1).set_option("2")
191+
qtbot.using(dropdown_2).set_option("5")
192+
with qtbot.focusing_on(group_box="Generate Design"):
193+
with qtbot.focusing_on(table=...) as table:
194+
qtbot.select_row(5)
195+
qtbot.using(column="Type").set_option("Weight")
196+
qtbot.click(button="Estimate Runtime")
197+
198+
with qtbot.focusing_on(group_box="SDoE Progress"):
199+
qtbot.using(combo_box="Number of Random Starts: n =").set_option("10")
200+
run_button = qtbot.locate_widget(button="Run SDoE")
201+
with qtbot.searching_within(self.analysis_dialog):
202+
with qtbot.searching_within(group_box="Created Designs"):
203+
created_designs_table = qtbot.locate_widget(table=any)
204+
205+
def created_designs_table_is_populated() -> bool:
206+
return created_designs_table.rowCount() > 0
207+
208+
qtbot.using(run_button).click()
209+
210+
qtbot.wait_until(created_designs_table_is_populated, timeout=120_000)
211+
with qtbot.searching_within(self.analysis_dialog):
212+
with qtbot.searching_within(group_box="Created Designs"):
213+
with qtbot.focusing_on(table=any):
214+
for i in range(created_designs_table.rowCount()):
215+
qtbot.select_row(i)
216+
with qtbot.waiting_for_modal(timeout=10_000):
217+
qtbot.using(column="Plot SDoE").click()
218+
with qtbot.searching_within(sdoePreview):
219+
with qtbot.searching_within(group_box="Plots"):
220+
qtbot.click(button="Plot SDoE")
221+
qtbot.wait(1000)
222+
qtbot.click(button="OK")
223+
224+
@pytest.fixture(scope="class")
225+
def start_analysis(self, qtbot, foqus_examples_dir):
226+
def has_dialog():
227+
return self.analysis_dialog is not None
228+
229+
qtbot.focused = self.frame
230+
with qtbot.file_selection(
231+
foqus_examples_dir / "tutorial_files/SDOE/CCSIex.csv"
232+
):
233+
qtbot.click(button="Load Existing\n Set")
234+
qtbot.click(button="Continue")
235+
with qtbot.searching_within(group_box="Design Construction") as gb:
236+
with qtbot.searching_within(table=...) as t:
237+
qtbot.select_row(3)
238+
qtbot.using(column="Descriptor").set_option(
239+
"Non-Uniform Space Filling (NUSF)"
240+
)
241+
qtbot.click(button="Open SDoE Dialog")
242+
qtbot.wait_until(has_dialog, timeout=10_000)

0 commit comments

Comments
 (0)