|
2 | 2 | import code |
3 | 3 | from contextlib import contextmanager |
4 | 4 | from functools import partial |
5 | | -from mock import Mock |
| 5 | +from mock import Mock, patch |
6 | 6 | import os |
7 | 7 | from StringIO import StringIO |
8 | 8 | import sys |
@@ -153,6 +153,46 @@ def test_tab_completes_common_sequence(self): |
153 | 153 | self.repl.matches_iter.substitute_cseq.assert_called_once_with() |
154 | 154 |
|
155 | 155 |
|
| 156 | +class TestCurtsiesReplFilenameCompletion(unittest.TestCase): |
| 157 | + def setUp(self): |
| 158 | + self.repl = create_repl() |
| 159 | + |
| 160 | + def test_list_win_visible_and_match_selected_on_tab_when_multiple_options(self): |
| 161 | + self.repl._current_line = " './'" |
| 162 | + self.repl._cursor_offset = 2 |
| 163 | + with patch('bpython.autocomplete.get_completer_bpython') as mock: |
| 164 | + mock.return_value = (['./abc', './abcd', './bcd'], autocomplete.FilenameCompletion) |
| 165 | + self.repl.update_completion() |
| 166 | + self.assertEqual(self.repl.list_win_visible, False) |
| 167 | + self.repl.on_tab() |
| 168 | + self.assertEqual(self.repl.current_match, './abc') |
| 169 | + self.assertEqual(self.repl.list_win_visible, True) |
| 170 | + |
| 171 | + def test_list_win_not_visible_and_cseq_if_cseq(self): |
| 172 | + self.repl._current_line = " './a'" |
| 173 | + self.repl._cursor_offset = 5 |
| 174 | + with patch('bpython.autocomplete.get_completer_bpython') as mock: |
| 175 | + mock.return_value = (['./abcd', './abce'], autocomplete.FilenameCompletion) |
| 176 | + self.repl.update_completion() |
| 177 | + self.assertEqual(self.repl.list_win_visible, False) |
| 178 | + self.repl.on_tab() |
| 179 | + self.assertEqual(self.repl._current_line, " './abc'") |
| 180 | + self.assertEqual(self.repl.current_match, None) |
| 181 | + self.assertEqual(self.repl.list_win_visible, False) |
| 182 | + |
| 183 | + def test_list_win_not_visible_and_match_selected_if_one_option(self): |
| 184 | + self.repl._current_line = " './a'" |
| 185 | + self.repl._cursor_offset = 5 |
| 186 | + with patch('bpython.autocomplete.get_completer_bpython') as mock: |
| 187 | + mock.return_value = (['./abcd'], autocomplete.FilenameCompletion) |
| 188 | + self.repl.update_completion() |
| 189 | + self.assertEqual(self.repl.list_win_visible, False) |
| 190 | + self.repl.on_tab() |
| 191 | + self.assertEqual(self.repl._current_line, " './abcd'") |
| 192 | + self.assertEqual(self.repl.current_match, None) |
| 193 | + self.assertEqual(self.repl.list_win_visible, False) |
| 194 | + |
| 195 | + |
156 | 196 | @contextmanager # from http://stackoverflow.com/a/17981937/398212 - thanks @rkennedy |
157 | 197 | def captured_output(): |
158 | 198 | new_out, new_err = StringIO(), StringIO() |
|
0 commit comments