mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
refactor(tests): Use mock.patch for messagebox dialogs
This commit is contained in:
parent
66e0495276
commit
a154c9f344
1 changed files with 4 additions and 12 deletions
|
|
@ -119,16 +119,12 @@ def test_reload_with_unsaved_changes_cancel(self):
|
|||
io.set_saved(False)
|
||||
|
||||
# Mock askokcancel to return False (cancel)
|
||||
orig_askokcancel = iomenu.messagebox.askokcancel
|
||||
iomenu.messagebox.askokcancel = lambda *args, **kwargs: False
|
||||
|
||||
try:
|
||||
with patch('idlelib.iomenu.messagebox.askokcancel', return_value=False) as mock_askokcancel:
|
||||
result = io.reload(None)
|
||||
self.assertEqual(result, "break")
|
||||
# Content should not change
|
||||
self.assertIn("# Unsaved change", text.get('1.0', 'end-1c'))
|
||||
finally:
|
||||
iomenu.messagebox.askokcancel = orig_askokcancel
|
||||
mock_askokcancel.assert_called_once()
|
||||
|
||||
def test_reload_with_unsaved_changes_confirm(self):
|
||||
# Test reload with unsaved changes and user confirms
|
||||
|
|
@ -149,16 +145,12 @@ def test_reload_with_unsaved_changes_confirm(self):
|
|||
io.set_saved(False)
|
||||
|
||||
# Mock askokcancel to return True (confirm)
|
||||
orig_askokcancel = iomenu.messagebox.askokcancel
|
||||
iomenu.messagebox.askokcancel = lambda *args, **kwargs: True
|
||||
|
||||
try:
|
||||
with patch('idlelib.iomenu.messagebox.askokcancel', return_value=True) as mock_askokcancel:
|
||||
result = io.reload(None)
|
||||
self.assertEqual(result, "break")
|
||||
# Content should be reverted to original
|
||||
self.assertEqual(text.get('1.0', 'end-1c'), "# Original content\n")
|
||||
finally:
|
||||
iomenu.messagebox.askokcancel = orig_askokcancel
|
||||
mock_askokcancel.assert_called_once()
|
||||
|
||||
|
||||
def _extension_in_filetypes(extension):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue