Skip to content

Commit feff7b5

Browse files
committed
Fix for TestMainWindowLoad::test_save.
- Add suffix to filename for file created by tempfile to be compatible with enforcing 'ows' extension. - Mocked `exec` method for QFileDialog now return True, because it was never reach out branch `if dialog.exec():`.
1 parent 25a0d32 commit feff7b5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

orangecanvas/application/tests/test_mainwindow.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
import os
33
import tempfile
4-
from unittest.mock import patch
4+
from unittest.mock import patch, Mock
55

66
from AnyQt.QtGui import QWhatsThisClickedEvent
77
from AnyQt.QtWidgets import (
@@ -149,7 +149,7 @@ class TestMainWindowLoad(TestMainWindowBase):
149149

150150
def setUp(self):
151151
super().setUp()
152-
fd, filename = tempfile.mkstemp()
152+
fd, filename = tempfile.mkstemp(suffix=".ows")
153153
self.file = os.fdopen(fd, "w+b")
154154
self.filename = filename
155155

@@ -182,8 +182,11 @@ def exec(myself):
182182
myself.setOption(QFileDialog.DontConfirmOverwrite)
183183
myself.selectFile(self.filename)
184184
myself.accept()
185+
return True
185186

186-
with patch("AnyQt.QtWidgets.QFileDialog.exec", exec):
187+
with (patch("AnyQt.QtWidgets.QFileDialog.exec", exec),
188+
patch("AnyQt.QtWidgets.QMessageBox.question",
189+
new=Mock(return_value=QMessageBox.Yes))):
187190
w.save_scheme()
188191
self.assertTrue(os.path.samefile(w.current_document().path(), self.filename))
189192

0 commit comments

Comments
 (0)