1 import unittest 2 import Tkinter 3 from test.test_support import requires, run_unittest 4 from ttk import setup_master 5 6 requires('gui') 7 8 class TextTest(unittest.TestCase): 9 10 def setUp(self): 11 self.root = setup_master() 12 self.text = Tkinter.Text(self.root) 13 14 def tearDown(self): 15 self.text.destroy() 16 17 18 def test_search(self): 19 text = self.text 20 21 # pattern and index are obligatory arguments. 22 self.assertRaises(Tkinter.TclError, text.search, None, '1.0') 23 self.assertRaises(Tkinter.TclError, text.search, 'a', None) 24 self.assertRaises(Tkinter.TclError, text.search, None, None) 25 26 # Invalid text index. 27 self.assertRaises(Tkinter.TclError, text.search, '', 0) 28 29 # Check if we are getting the indices as strings -- you are likely 30 # to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it. 31 text.insert('1.0', 'hi-test') 32 self.assertEqual(text.search('-test', '1.0', 'end'), '1.2') 33 self.assertEqual(text.search('test', '1.0', 'end'), '1.3') 34 35 36 tests_gui = (TextTest, ) 37 38 if __name__ == "__main__": 39 run_unittest(*tests_gui) 40