diff options
author | terryjreedy <tjreedy@udel.edu> | 2017-06-09 19:59:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-09 19:59:31 (GMT) |
commit | bbeaccc76b2a4a7e2601579446c84cb12fea5f05 (patch) | |
tree | 866527d3768b61f1df245972cc0aec315660935f | |
parent | af609a00a64fd58bd67c102f208ed9fe15c2748d (diff) | |
download | cpython-bbeaccc76b2a4a7e2601579446c84cb12fea5f05.zip cpython-bbeaccc76b2a4a7e2601579446c84cb12fea5f05.tar.gz cpython-bbeaccc76b2a4a7e2601579446c84cb12fea5f05.tar.bz2 |
[3.6] IDLE test_textview: add comments and test, increase coverage to 100% (GH-1641) (#2018)
(cherry picked from commit 295304d412700cc6621bb592109fa42249a9dcdb)
-rw-r--r-- | Lib/idlelib/idle_test/test_textview.py | 33 | ||||
-rw-r--r-- | Lib/idlelib/textview.py | 1 |
2 files changed, 25 insertions, 9 deletions
diff --git a/Lib/idlelib/idle_test/test_textview.py b/Lib/idlelib/idle_test/test_textview.py index 67fc0b7..57b886a 100644 --- a/Lib/idlelib/idle_test/test_textview.py +++ b/Lib/idlelib/idle_test/test_textview.py @@ -5,7 +5,7 @@ is a widget containing multiple widgets, all tests must be gui tests. Using mock Text would not change this. Other mocks are used to retrieve information about calls. -Coverage: 94%. +Coverage: 100%. ''' from idlelib import textview as tv from test.support import requires @@ -28,14 +28,20 @@ def tearDownModule(): root.destroy() # Pyflakes falsely sees root as undefined. del root +# If we call TextViewer or wrapper functions with defaults +# modal=True, _utest=False, test hangs on call to wait_window. +# Have also gotten tk error 'can't invoke "event" command'. + class TV(tv.TextViewer): # Used in TextViewTest. transient = Func() grab_set = Func() wait_window = Func() -class TextViewTest(unittest.TestCase): +# Call wrapper class with mock wait_window. +class TextViewTest(unittest.TestCase): + def setUp(self): TV.transient.__init__() TV.grab_set.__init__() @@ -64,6 +70,7 @@ class TextViewTest(unittest.TestCase): view.destroy() +# Call TextViewer with modal=False. class ViewFunctionTest(unittest.TestCase): @classmethod @@ -77,26 +84,34 @@ class ViewFunctionTest(unittest.TestCase): del cls.orig_error def test_view_text(self): - # If modal True, get tk error 'can't invoke "event" command'. view = tv.view_text(root, 'Title', 'test text', modal=False) self.assertIsInstance(view, tv.TextViewer) view.Ok() def test_view_file(self): - test_dir = os.path.dirname(__file__) - testfile = os.path.join(test_dir, 'test_textview.py') - view = tv.view_file(root, 'Title', testfile, modal=False) + view = tv.view_file(root, 'Title', __file__, modal=False) self.assertIsInstance(view, tv.TextViewer) self.assertIn('Test', view.textView.get('1.0', '1.end')) view.Ok() + def test_bad_file(self): # Mock showerror will be used; view_file will return None. - testfile = os.path.join(test_dir, '../notthere.py') - view = tv.view_file(root, 'Title', testfile, modal=False) + view = tv.view_file(root, 'Title', 'abc.xyz', modal=False) self.assertIsNone(view) + self.assertEqual(tv.showerror.title, 'File Load Error') + + def test_bad_encoding(self): + p = os.path + fn = p.abspath(p.join(p.dirname(__file__), '..', 'CREDITS.txt')) + tv.showerror.title = None + view = tv.view_file(root, 'Title', fn, 'ascii', modal=False) + self.assertIsNone(view) + self.assertEqual(tv.showerror.title, 'Unicode Decode Error') + -class ButtonClickTextViewTest(unittest.TestCase): +# Call TextViewer with _utest=True. +class ButtonClickTest(unittest.TestCase): def setUp(self): self.view = None diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py index f33ac32..dc1a7bf 100644 --- a/Lib/idlelib/textview.py +++ b/Lib/idlelib/textview.py @@ -87,6 +87,7 @@ def view_file(parent, title, filename, encoding=None, modal=True, _utest=False): parent=parent) else: return view_text(parent, title, contents, modal, _utest=_utest) + return None if __name__ == '__main__': |