55Using mock Text would not change this. Other mocks are used to retrieve
66information about calls.
77
8- Coverage: 94 %.
8+ Coverage: 100 %.
99'''
1010from idlelib import textview as tv
1111from test .support import requires
@@ -28,14 +28,20 @@ def tearDownModule():
2828 root .destroy () # Pyflakes falsely sees root as undefined.
2929 del root
3030
31+ # If we call TextViewer or wrapper functions with defaults
32+ # modal=True, _utest=False, test hangs on call to wait_window.
33+ # Have also gotten tk error 'can't invoke "event" command'.
34+
3135
3236class TV (tv .TextViewer ): # Used in TextViewTest.
3337 transient = Func ()
3438 grab_set = Func ()
3539 wait_window = Func ()
3640
37- class TextViewTest (unittest .TestCase ):
3841
42+ # Call wrapper class with mock wait_window.
43+ class TextViewTest (unittest .TestCase ):
44+
3945 def setUp (self ):
4046 TV .transient .__init__ ()
4147 TV .grab_set .__init__ ()
@@ -64,6 +70,7 @@ def test_ok(self):
6470 view .destroy ()
6571
6672
73+ # Call TextViewer with modal=False.
6774class ViewFunctionTest (unittest .TestCase ):
6875
6976 @classmethod
@@ -77,26 +84,34 @@ def tearDownClass(cls):
7784 del cls .orig_error
7885
7986 def test_view_text (self ):
80- # If modal True, get tk error 'can't invoke "event" command'.
8187 view = tv .view_text (root , 'Title' , 'test text' , modal = False )
8288 self .assertIsInstance (view , tv .TextViewer )
8389 view .Ok ()
8490
8591 def test_view_file (self ):
86- test_dir = os .path .dirname (__file__ )
87- testfile = os .path .join (test_dir , 'test_textview.py' )
88- view = tv .view_file (root , 'Title' , testfile , modal = False )
92+ view = tv .view_file (root , 'Title' , __file__ , modal = False )
8993 self .assertIsInstance (view , tv .TextViewer )
9094 self .assertIn ('Test' , view .textView .get ('1.0' , '1.end' ))
9195 view .Ok ()
9296
97+ def test_bad_file (self ):
9398 # Mock showerror will be used; view_file will return None.
94- testfile = os .path .join (test_dir , '../notthere.py' )
95- view = tv .view_file (root , 'Title' , testfile , modal = False )
99+ view = tv .view_file (root , 'Title' , 'abc.xyz' , modal = False )
96100 self .assertIsNone (view )
101+ self .assertEqual (tv .showerror .title , 'File Load Error' )
102+
103+ def test_bad_encoding (self ):
104+ p = os .path
105+ fn = p .abspath (p .join (p .dirname (__file__ ), '..' , 'CREDITS.txt' ))
106+ tv .showerror .title = None
107+ view = tv .view_file (root , 'Title' , fn , 'ascii' , modal = False )
108+ self .assertIsNone (view )
109+ self .assertEqual (tv .showerror .title , 'Unicode Decode Error' )
110+
97111
98112
99- class ButtonClickTextViewTest (unittest .TestCase ):
113+ # Call TextViewer with _utest=True.
114+ class ButtonClickTest (unittest .TestCase ):
100115
101116 def setUp (self ):
102117 self .view = None
0 commit comments