ยปCore Development>Code coverage>Lib/idlelib/idle_test/test_search.py

Python code coverage for Lib/idlelib/idle_test/test_search.py

#countcontent
1n/a"""Test SearchDialog class in idlelib.search.py"""
2n/a
3n/a# Does not currently test the event handler wrappers.
4n/a# A usage test should simulate clicks and check hilighting.
5n/a# Tests need to be coordinated with SearchDialogBase tests
6n/a# to avoid duplication.
7n/a
8n/afrom test.support import requires
9n/arequires('gui')
10n/a
11n/aimport unittest
12n/aimport tkinter as tk
13n/afrom tkinter import BooleanVar
14n/aimport idlelib.searchengine as se
15n/aimport idlelib.search as sd
16n/a
17n/a
18n/aclass SearchDialogTest(unittest.TestCase):
19n/a
20n/a @classmethod
21n/a def setUpClass(cls):
22n/a cls.root = tk.Tk()
23n/a
24n/a @classmethod
25n/a def tearDownClass(cls):
26n/a cls.root.destroy()
27n/a del cls.root
28n/a
29n/a def setUp(self):
30n/a self.engine = se.SearchEngine(self.root)
31n/a self.dialog = sd.SearchDialog(self.root, self.engine)
32n/a self.dialog.bell = lambda: None
33n/a self.text = tk.Text(self.root)
34n/a self.text.insert('1.0', 'Hello World!')
35n/a
36n/a def test_find_again(self):
37n/a # Search for various expressions
38n/a text = self.text
39n/a
40n/a self.engine.setpat('')
41n/a self.assertFalse(self.dialog.find_again(text))
42n/a self.dialog.bell = lambda: None
43n/a
44n/a self.engine.setpat('Hello')
45n/a self.assertTrue(self.dialog.find_again(text))
46n/a
47n/a self.engine.setpat('Goodbye')
48n/a self.assertFalse(self.dialog.find_again(text))
49n/a
50n/a self.engine.setpat('World!')
51n/a self.assertTrue(self.dialog.find_again(text))
52n/a
53n/a self.engine.setpat('Hello World!')
54n/a self.assertTrue(self.dialog.find_again(text))
55n/a
56n/a # Regular expression
57n/a self.engine.revar = BooleanVar(self.root, True)
58n/a self.engine.setpat('W[aeiouy]r')
59n/a self.assertTrue(self.dialog.find_again(text))
60n/a
61n/a def test_find_selection(self):
62n/a # Select some text and make sure it's found
63n/a text = self.text
64n/a # Add additional line to find
65n/a self.text.insert('2.0', 'Hello World!')
66n/a
67n/a text.tag_add('sel', '1.0', '1.4') # Select 'Hello'
68n/a self.assertTrue(self.dialog.find_selection(text))
69n/a
70n/a text.tag_remove('sel', '1.0', 'end')
71n/a text.tag_add('sel', '1.6', '1.11') # Select 'World!'
72n/a self.assertTrue(self.dialog.find_selection(text))
73n/a
74n/a text.tag_remove('sel', '1.0', 'end')
75n/a text.tag_add('sel', '1.0', '1.11') # Select 'Hello World!'
76n/a self.assertTrue(self.dialog.find_selection(text))
77n/a
78n/a # Remove additional line
79n/a text.delete('2.0', 'end')
80n/a
81n/aif __name__ == '__main__':
82n/a unittest.main(verbosity=2, exit=2)