Skip to content

Commit 3f5dd9d

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 3f5dd9d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

orangecanvas/application/tests/test_mainwindow.py

Lines changed: 7 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

@@ -178,12 +178,16 @@ def test_save(self):
178178
w.current_document().setPath("")
179179

180180
def exec(myself):
181+
myself.setAcceptMode(QFileDialog.AcceptSave)
181182
myself.setOption(QFileDialog.DontUseNativeDialog)
182183
myself.setOption(QFileDialog.DontConfirmOverwrite)
183184
myself.selectFile(self.filename)
184185
myself.accept()
186+
return True
185187

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

0 commit comments

Comments
 (0)