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