ยปCore Development>Code coverage>Lib/tkinter/test/test_tkinter/test_text.py

Python code coverage for Lib/tkinter/test/test_tkinter/test_text.py

#countcontent
1n/aimport unittest
2n/aimport tkinter
3n/afrom test.support import requires, run_unittest
4n/afrom tkinter.test.support import AbstractTkTest
5n/a
6n/arequires('gui')
7n/a
8n/aclass TextTest(AbstractTkTest, unittest.TestCase):
9n/a
10n/a def setUp(self):
11n/a super().setUp()
12n/a self.text = tkinter.Text(self.root)
13n/a
14n/a def test_debug(self):
15n/a text = self.text
16n/a olddebug = text.debug()
17n/a try:
18n/a text.debug(0)
19n/a self.assertEqual(text.debug(), 0)
20n/a text.debug(1)
21n/a self.assertEqual(text.debug(), 1)
22n/a finally:
23n/a text.debug(olddebug)
24n/a self.assertEqual(text.debug(), olddebug)
25n/a
26n/a def test_search(self):
27n/a text = self.text
28n/a
29n/a # pattern and index are obligatory arguments.
30n/a self.assertRaises(tkinter.TclError, text.search, None, '1.0')
31n/a self.assertRaises(tkinter.TclError, text.search, 'a', None)
32n/a self.assertRaises(tkinter.TclError, text.search, None, None)
33n/a
34n/a # Invalid text index.
35n/a self.assertRaises(tkinter.TclError, text.search, '', 0)
36n/a
37n/a # Check if we are getting the indices as strings -- you are likely
38n/a # to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it.
39n/a text.insert('1.0', 'hi-test')
40n/a self.assertEqual(text.search('-test', '1.0', 'end'), '1.2')
41n/a self.assertEqual(text.search('test', '1.0', 'end'), '1.3')
42n/a
43n/a
44n/atests_gui = (TextTest, )
45n/a
46n/aif __name__ == "__main__":
47n/a run_unittest(*tests_gui)