Skip to content

Commit e048ae5

Browse files
committed
Revise POET weights dialog test coverage
Reworks `test_weights_dialog.py` to match the updated POET download dialog behavior. The tests now validate default destination/status UI, progress updates, successful download completion and cleanup signaling, failure cleanup control restoration, and reject behavior during active vs idle download states.
1 parent 40ba669 commit e048ae5

1 file changed

Lines changed: 60 additions & 45 deletions

File tree

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,113 @@
1+
from __future__ import annotations
2+
13
from PySide6.QtCore import Qt
2-
from PySide6.QtWidgets import QFileDialog
4+
from PySide6.QtWidgets import QDialog
35

46
from dlclivegui.gui.misc.weights_dialog import PoetWeightsDialog
57

68

7-
def test_dialog_without_initial_path_disables_use_button(
9+
def test_dialog_shows_download_destination(
10+
qtbot,
11+
) -> None:
12+
dialog = PoetWeightsDialog()
13+
qtbot.addWidget(dialog)
14+
15+
assert dialog.path_label.full_text == str(dialog._destination)
16+
assert dialog.path_label.text()
17+
assert dialog.path_label.textInteractionFlags() & Qt.TextInteractionFlag.TextSelectableByMouse
18+
assert dialog.status_label.text() == "Ready to download."
19+
assert dialog.progress_bar.value() == 0
20+
assert dialog.download_button.isEnabled()
21+
assert dialog.close_button.isEnabled()
22+
23+
24+
def test_update_progress_updates_progress_and_status(
825
qtbot,
926
) -> None:
1027
dialog = PoetWeightsDialog()
1128
qtbot.addWidget(dialog)
1229

13-
assert dialog.path_label.text() == "No weights selected"
14-
assert not dialog.use_button.isEnabled()
15-
assert not dialog.progress_bar.isVisible()
30+
dialog._update_progress(42)
1631

32+
assert dialog.progress_bar.value() == 42
33+
assert dialog.status_label.text() == "Downloading POET weights... 42%"
1734

18-
def test_dialog_accepts_valid_initial_path(
35+
36+
def test_download_finished_records_completed_path(
1937
qtbot,
2038
tmp_path,
2139
) -> None:
2240
path = tmp_path / "weights.pth"
2341
path.touch()
2442

25-
dialog = PoetWeightsDialog(initial_path=str(path))
43+
dialog = PoetWeightsDialog()
2644
qtbot.addWidget(dialog)
2745

28-
assert dialog.path_label.text() == str(path)
29-
assert dialog.use_button.isEnabled()
46+
dialog._download_finished(str(path))
47+
48+
assert dialog._completed_path == str(path)
49+
assert dialog.progress_bar.value() == 100
50+
assert dialog.status_label.text() == ("Download complete. Returning to the main window...")
3051

3152

32-
def test_use_selected_emits_path(
53+
def test_download_cleanup_emits_path_and_accepts(
3354
qtbot,
3455
tmp_path,
3556
) -> None:
3657
path = tmp_path / "weights.pth"
3758
path.touch()
3859

39-
dialog = PoetWeightsDialog(initial_path=str(path))
60+
dialog = PoetWeightsDialog()
4061
qtbot.addWidget(dialog)
62+
dialog._completed_path = str(path)
4163

4264
with qtbot.waitSignal(
43-
dialog.weights_selected,
65+
dialog.weights_downloaded,
4466
timeout=1000,
4567
) as blocker:
46-
qtbot.mouseClick(
47-
dialog.use_button,
48-
Qt.MouseButton.LeftButton,
49-
)
68+
dialog._download_cleanup()
5069

5170
assert blocker.args == [str(path)]
71+
assert dialog.result() == QDialog.DialogCode.Accepted
72+
assert dialog._download_thread is None
73+
assert dialog._download_worker is None
5274

5375

54-
def test_browse_sets_selected_path(
76+
def test_download_cleanup_after_failure_restores_controls(
5577
qtbot,
56-
monkeypatch,
57-
tmp_path,
5878
) -> None:
59-
path = tmp_path / "weights.pth"
60-
path.touch()
79+
dialog = PoetWeightsDialog()
80+
qtbot.addWidget(dialog)
6181

62-
monkeypatch.setattr(
63-
QFileDialog,
64-
"getOpenFileName",
65-
lambda *args, **kwargs: (
66-
str(path),
67-
"POET weights (*.pt *.pth)",
68-
),
69-
)
82+
dialog.download_button.setEnabled(False)
83+
dialog.close_button.setEnabled(False)
84+
dialog._completed_path = None
85+
86+
dialog._download_cleanup()
87+
88+
assert dialog.download_button.isEnabled()
89+
assert dialog.close_button.isEnabled()
7090

91+
92+
def test_reject_is_ignored_while_download_is_active(
93+
qtbot,
94+
) -> None:
7195
dialog = PoetWeightsDialog()
7296
qtbot.addWidget(dialog)
7397

74-
dialog._browse()
98+
dialog._download_thread = object()
99+
100+
dialog.reject()
75101

76-
assert dialog.path_label.text() == str(path)
77-
assert dialog.use_button.isEnabled()
102+
assert dialog.result() == 0
78103

79104

80-
def test_download_cleanup_restores_controls(
105+
def test_reject_closes_when_idle(
81106
qtbot,
82-
tmp_path,
83107
) -> None:
84-
path = tmp_path / "weights.pth"
85-
path.touch()
86-
87108
dialog = PoetWeightsDialog()
88109
qtbot.addWidget(dialog)
89110

90-
dialog._set_selected_path(str(path))
91-
dialog.browse_button.setEnabled(False)
92-
dialog.download_button.setEnabled(False)
93-
94-
dialog._download_cleanup()
111+
dialog.reject()
95112

96-
assert dialog.browse_button.isEnabled()
97-
assert dialog.download_button.isEnabled()
98-
assert dialog.use_button.isEnabled()
113+
assert dialog.result() == QDialog.DialogCode.Rejected

0 commit comments

Comments
 (0)