Coverage for idle_test/test_search.py: 7%
50 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-11 13:22 -0700
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-11 13:22 -0700
1"Test search, coverage 69%."
3from idlelib import search
4import unittest
5from test.support import requires
6requires('gui')
7from tkinter import Tk, Text, BooleanVar
8from idlelib import searchengine
10# Does not currently test the event handler wrappers.
11# A usage test should simulate clicks and check highlighting.
12# Tests need to be coordinated with SearchDialogBase tests
13# to avoid duplication.
16class SearchDialogTest(unittest.TestCase):
18 @classmethod
19 def setUpClass(cls):
20 cls.root = Tk()
22 @classmethod
23 def tearDownClass(cls):
24 cls.root.destroy()
25 del cls.root
27 def setUp(self):
28 self.engine = searchengine.SearchEngine(self.root)
29 self.dialog = search.SearchDialog(self.root, self.engine)
30 self.dialog.bell = lambda: None
31 self.text = Text(self.root)
32 self.text.insert('1.0', 'Hello World!')
34 def test_find_again(self):
35 # Search for various expressions
36 text = self.text
38 self.engine.setpat('')
39 self.assertFalse(self.dialog.find_again(text))
40 self.dialog.bell = lambda: None
42 self.engine.setpat('Hello')
43 self.assertTrue(self.dialog.find_again(text))
45 self.engine.setpat('Goodbye')
46 self.assertFalse(self.dialog.find_again(text))
48 self.engine.setpat('World!')
49 self.assertTrue(self.dialog.find_again(text))
51 self.engine.setpat('Hello World!')
52 self.assertTrue(self.dialog.find_again(text))
54 # Regular expression
55 self.engine.revar = BooleanVar(self.root, True)
56 self.engine.setpat('W[aeiouy]r')
57 self.assertTrue(self.dialog.find_again(text))
59 def test_find_selection(self):
60 # Select some text and make sure it's found
61 text = self.text
62 # Add additional line to find
63 self.text.insert('2.0', 'Hello World!')
65 text.tag_add('sel', '1.0', '1.4') # Select 'Hello'
66 self.assertTrue(self.dialog.find_selection(text))
68 text.tag_remove('sel', '1.0', 'end')
69 text.tag_add('sel', '1.6', '1.11') # Select 'World!'
70 self.assertTrue(self.dialog.find_selection(text))
72 text.tag_remove('sel', '1.0', 'end')
73 text.tag_add('sel', '1.0', '1.11') # Select 'Hello World!'
74 self.assertTrue(self.dialog.find_selection(text))
76 # Remove additional line
77 text.delete('2.0', 'end')
79if __name__ == '__main__':
80 unittest.main(verbosity=2, exit=2)