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

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

#countcontent
1n/a''' Test autocomplete and autocomple_w
2n/a
3n/aCoverage of autocomple: 56%
4n/a'''
5n/aimport unittest
6n/afrom test.support import requires
7n/afrom tkinter import Tk, Text
8n/a
9n/aimport idlelib.autocomplete as ac
10n/aimport idlelib.autocomplete_w as acw
11n/afrom idlelib.idle_test.mock_idle import Func
12n/afrom idlelib.idle_test.mock_tk import Event
13n/a
14n/aclass AutoCompleteWindow:
15n/a def complete():
16n/a return
17n/a
18n/aclass DummyEditwin:
19n/a def __init__(self, root, text):
20n/a self.root = root
21n/a self.text = text
22n/a self.indentwidth = 8
23n/a self.tabwidth = 8
24n/a self.context_use_ps1 = True
25n/a
26n/a
27n/aclass AutoCompleteTest(unittest.TestCase):
28n/a
29n/a @classmethod
30n/a def setUpClass(cls):
31n/a requires('gui')
32n/a cls.root = Tk()
33n/a cls.text = Text(cls.root)
34n/a cls.editor = DummyEditwin(cls.root, cls.text)
35n/a
36n/a @classmethod
37n/a def tearDownClass(cls):
38n/a del cls.editor, cls.text
39n/a cls.root.destroy()
40n/a del cls.root
41n/a
42n/a def setUp(self):
43n/a self.editor.text.delete('1.0', 'end')
44n/a self.autocomplete = ac.AutoComplete(self.editor)
45n/a
46n/a def test_init(self):
47n/a self.assertEqual(self.autocomplete.editwin, self.editor)
48n/a
49n/a def test_make_autocomplete_window(self):
50n/a testwin = self.autocomplete._make_autocomplete_window()
51n/a self.assertIsInstance(testwin, acw.AutoCompleteWindow)
52n/a
53n/a def test_remove_autocomplete_window(self):
54n/a self.autocomplete.autocompletewindow = (
55n/a self.autocomplete._make_autocomplete_window())
56n/a self.autocomplete._remove_autocomplete_window()
57n/a self.assertIsNone(self.autocomplete.autocompletewindow)
58n/a
59n/a def test_force_open_completions_event(self):
60n/a # Test that force_open_completions_event calls _open_completions
61n/a o_cs = Func()
62n/a self.autocomplete.open_completions = o_cs
63n/a self.autocomplete.force_open_completions_event('event')
64n/a self.assertEqual(o_cs.args, (True, False, True))
65n/a
66n/a def test_try_open_completions_event(self):
67n/a Equal = self.assertEqual
68n/a autocomplete = self.autocomplete
69n/a trycompletions = self.autocomplete.try_open_completions_event
70n/a o_c_l = Func()
71n/a autocomplete._open_completions_later = o_c_l
72n/a
73n/a # _open_completions_later should not be called with no text in editor
74n/a trycompletions('event')
75n/a Equal(o_c_l.args, None)
76n/a
77n/a # _open_completions_later should be called with COMPLETE_ATTRIBUTES (1)
78n/a self.text.insert('1.0', 're.')
79n/a trycompletions('event')
80n/a Equal(o_c_l.args, (False, False, False, 1))
81n/a
82n/a # _open_completions_later should be called with COMPLETE_FILES (2)
83n/a self.text.delete('1.0', 'end')
84n/a self.text.insert('1.0', '"./Lib/')
85n/a trycompletions('event')
86n/a Equal(o_c_l.args, (False, False, False, 2))
87n/a
88n/a def test_autocomplete_event(self):
89n/a Equal = self.assertEqual
90n/a autocomplete = self.autocomplete
91n/a
92n/a # Test that the autocomplete event is ignored if user is pressing a
93n/a # modifier key in addition to the tab key
94n/a ev = Event(mc_state=True)
95n/a self.assertIsNone(autocomplete.autocomplete_event(ev))
96n/a del ev.mc_state
97n/a
98n/a # Test that tab after whitespace is ignored.
99n/a self.text.insert('1.0', ' """Docstring.\n ')
100n/a self.assertIsNone(autocomplete.autocomplete_event(ev))
101n/a self.text.delete('1.0', 'end')
102n/a
103n/a # If autocomplete window is open, complete() method is called
104n/a self.text.insert('1.0', 're.')
105n/a # This must call autocomplete._make_autocomplete_window()
106n/a Equal(self.autocomplete.autocomplete_event(ev), 'break')
107n/a
108n/a # If autocomplete window is not active or does not exist,
109n/a # open_completions is called. Return depends on its return.
110n/a autocomplete._remove_autocomplete_window()
111n/a o_cs = Func() # .result = None
112n/a autocomplete.open_completions = o_cs
113n/a Equal(self.autocomplete.autocomplete_event(ev), None)
114n/a Equal(o_cs.args, (False, True, True))
115n/a o_cs.result = True
116n/a Equal(self.autocomplete.autocomplete_event(ev), 'break')
117n/a Equal(o_cs.args, (False, True, True))
118n/a
119n/a def test_open_completions_later(self):
120n/a # Test that autocomplete._delayed_completion_id is set
121n/a pass
122n/a
123n/a def test_delayed_open_completions(self):
124n/a # Test that autocomplete._delayed_completion_id set to None and that
125n/a # open_completions only called if insertion index is the same as
126n/a # _delayed_completion_index
127n/a pass
128n/a
129n/a def test_open_completions(self):
130n/a # Test completions of files and attributes as well as non-completion
131n/a # of errors
132n/a pass
133n/a
134n/a def test_fetch_completions(self):
135n/a # Test that fetch_completions returns 2 lists:
136n/a # For attribute completion, a large list containing all variables, and
137n/a # a small list containing non-private variables.
138n/a # For file completion, a large list containing all files in the path,
139n/a # and a small list containing files that do not start with '.'
140n/a pass
141n/a
142n/a def test_get_entity(self):
143n/a # Test that a name is in the namespace of sys.modules and
144n/a # __main__.__dict__
145n/a pass
146n/a
147n/a
148n/aif __name__ == '__main__':
149n/a unittest.main(verbosity=2)