File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed
Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change 55import os
66import tempfile
77import unittest
8+ from unittest .mock import patch
89from test .support import requires
910from tkinter import Tk
1011from idlelib .editor import EditorWindow
@@ -67,20 +68,13 @@ def test_reload_no_file(self):
6768 # Ensure no filename is set
6869 io .filename = None
6970
70- # Mock the messagebox.showinfo
71- orig_showinfo = iomenu .messagebox .showinfo
72- showinfo_called = []
73- def mock_showinfo (* args , ** kwargs ):
74- showinfo_called .append ((args , kwargs ))
75- iomenu .messagebox .showinfo = mock_showinfo
76-
77- try :
71+ # Mock the messagebox.showinfo using unittest.mock
72+ with patch .object (iomenu .messagebox , 'showinfo' ) as mock_showinfo :
7873 result = io .reload (None )
7974 self .assertEqual (result , "break" )
80- self .assertEqual (len (showinfo_called ), 1 )
81- self .assertIn ("File Not Found" , showinfo_called [0 ][0 ])
82- finally :
83- iomenu .messagebox .showinfo = orig_showinfo
75+ mock_showinfo .assert_called_once ()
76+ args , kwargs = mock_showinfo .call_args
77+ self .assertIn ("File Not Found" , args [0 ])
8478
8579 def test_reload_with_file (self ):
8680 # Test reload with an actual file
You can’t perform that action at this time.
0 commit comments