diff --git a/Lib/idlelib/idle_test/test_textview.py b/Lib/idlelib/idle_test/test_textview.py index 4af7b49a805..adbb3eef87a 100644 --- a/Lib/idlelib/idle_test/test_textview.py +++ b/Lib/idlelib/idle_test/test_textview.py @@ -8,7 +8,11 @@ from idlelib import textView as tv from idlelib.idle_test.mock_idle import Func from idlelib.idle_test.mock_tk import Mbox -orig_mbox = tv.tkMessageBox + +class TV(tv.TextViewer): # used by TextViewTest + transient = Func() + grab_set = Func() + wait_window = Func() class textviewClassTest(unittest.TestCase): @@ -16,26 +20,18 @@ class textviewClassTest(unittest.TestCase): def setUpClass(cls): requires('gui') cls.root = Tk() - cls.TV = TV = tv.TextViewer - TV.transient = Func() - TV.grab_set = Func() - TV.wait_window = Func() @classmethod def tearDownClass(cls): - del cls.TV cls.root.destroy() del cls.root def setUp(self): - TV = self.TV TV.transient.__init__() TV.grab_set.__init__() TV.wait_window.__init__() - def test_init_modal(self): - TV = self.TV view = TV(self.root, 'Title', 'test text') self.assertTrue(TV.transient.called) self.assertTrue(TV.grab_set.called) @@ -43,7 +39,6 @@ class textviewClassTest(unittest.TestCase): view.Ok() def test_init_nonmodal(self): - TV = self.TV view = TV(self.root, 'Title', 'test text', modal=False) self.assertFalse(TV.transient.called) self.assertFalse(TV.grab_set.called) @@ -51,7 +46,7 @@ class textviewClassTest(unittest.TestCase): view.Ok() def test_ok(self): - view = self.TV(self.root, 'Title', 'test text', modal=False) + view = TV(self.root, 'Title', 'test text', modal=False) view.destroy = Func() view.Ok() self.assertTrue(view.destroy.called) @@ -59,19 +54,21 @@ class textviewClassTest(unittest.TestCase): view.destroy -class textviewTest(unittest.TestCase): +class ViewFunctionTest(unittest.TestCase): @classmethod def setUpClass(cls): requires('gui') cls.root = Tk() + cls.orig_mbox = tv.tkMessageBox tv.tkMessageBox = Mbox @classmethod def tearDownClass(cls): cls.root.destroy() del cls.root - tv.tkMessageBox = orig_mbox + tv.tkMessageBox = cls.orig_mbox + del cls.orig_mbox def test_view_text(self): # If modal True, tkinter will error with 'can't invoke "event" command' @@ -91,5 +88,6 @@ class textviewTest(unittest.TestCase): view = tv.view_file(self.root, 'Title', testfile, modal=False) self.assertIsNone(view) + if __name__ == '__main__': unittest.main(verbosity=2)