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