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