Skip to content

Commit a6cdf72

Browse files
sonic2kkDavidoTek
andauthored
test_util: Implement test for get_combobox_index_by_value (#533)
* test_util: Implement test for `get_combobox_index_by_value` * test_util: Improve handling of QApplication * test_ctmods: Improve handling of QApplication --------- Co-authored-by: DavidoTek <54072917+DavidoTek@users.noreply.github.com>
1 parent bf6bdbf commit a6cdf72

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/test_ctmods.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_ctmod_loader() -> None:
1414
"""
1515
Test loading of ctmods using CtLoader.
1616
"""
17-
QApplication()
17+
app = QApplication()
1818

1919
dummy_main_window = DummyMainWindow({})
2020

@@ -29,3 +29,5 @@ def test_ctmod_loader() -> None:
2929

3030
# Ensure that no advanced mode ctmods are loaded when advanced_mode is False
3131
assert(all(["advmode" not in ctmod.CT_LAUNCHERS for ctmod in ct_loader.get_ctmods(launcher=None, advanced_mode=False)]))
32+
33+
QApplication.shutdown(app)

tests/test_util.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,26 @@ def test_compat_tool_available(compat_tool_name: str, ctobjs: list[dict[str, str
303303
result: bool = compat_tool_available(compat_tool_name, ctobjs)
304304

305305
assert result == expected
306+
307+
308+
@pytest.mark.parametrize(
309+
'combobox_values, value, expected_index', [
310+
pytest.param(['a', 'b', 'c', 'd', 'e'], 'c', 2, id = 'Simple list'),
311+
pytest.param(['Steam', 'Lutris',' Heroic'], 'Lutris', 1, id = 'List of Launcher Names'),
312+
pytest.param(['GE-Proton', 'Proton-tkg', 'SteamTinkerLaunch'], 'SteamTinkerLaunch', 2, id = 'List of Compatibility Tool names'),
313+
]
314+
)
315+
def test_get_combobox_index_by_value(combobox_values: list[str], value: str, expected_index: int) -> None:
316+
317+
app = QApplication()
318+
319+
combobox: QComboBox = QComboBox()
320+
321+
combobox.addItems(combobox_values)
322+
323+
result: int = get_combobox_index_by_value(combobox, value)
324+
325+
assert combobox_values[result] == value
326+
assert result == expected_index
327+
328+
QApplication.shutdown(app)

0 commit comments

Comments
 (0)