| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6a38aab commit fed23ca
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -313,12 +313,10 @@ def locate(self, current_offset, line): | |||
| 313 | 313 | import jedi | |
| 314 | 314 | except ImportError: | |
| 315 | 315 | class MultilineJediCompletion(BaseCompletionType): | |
| 316 | - @classmethod | ||
| 317 | - def matches(cls, cursor_offset, line, **kwargs): | ||
| 316 | + def matches(self, cursor_offset, line, **kwargs): | ||
| 318 | 317 | return None | |
| 319 | 318 | else: | |
| 320 | 319 | class JediCompletion(BaseCompletionType): | |
| 321 | - @classmethod | ||
| 322 | 320 | def matches(self, cursor_offset, line, history, **kwargs): | |
| 323 | 321 | if not lineparts.current_word(cursor_offset, line): | |
| 324 | 322 | return None | |
@@ -338,7 +336,7 @@ def matches(self, cursor_offset, line, history, **kwargs): | |||
| 338 | 336 | return None # Too general - giving completions starting with multiple letters | |
| 339 | 337 | else: | |
| 340 | 338 | # case-sensitive matches only | |
| 341 | - return [m for m in matches if m.startswith(first_letter)] | ||
| 339 | + return set([m for m in matches if m.startswith(first_letter)]) | ||
| 342 | 340 | ||
| 343 | 341 | def locate(self, cursor_offset, line): | |
| 344 | 342 | start = self._orig_start | |
@@ -347,11 +345,10 @@ def locate(self, cursor_offset, line): | |||
| 347 | 345 | ||
| 348 | 346 | ||
| 349 | 347 | class MultilineJediCompletion(JediCompletion): | |
| 350 | - @classmethod | ||
| 351 | - def matches(cls, cursor_offset, line, current_block, history, **kwargs): | ||
| 348 | + def matches(self, cursor_offset, line, current_block, history, **kwargs): | ||
| 352 | 349 | if '\n' in current_block: | |
| 353 | 350 | assert cursor_offset <= len(line), "%r %r" % (cursor_offset, line) | |
| 354 | - results = JediCompletion.matches(cursor_offset, line, history) | ||
| 351 | + results = JediCompletion.matches(self, cursor_offset, line, history) | ||
| 355 | 352 | return results | |
| 356 | 353 | else: | |
| 357 | 354 | return None | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + from collections import namedtuple | ||
| 1 | 2 | from bpython import autocomplete | |
| 2 | 3 | ||
| 3 | 4 | import mock | |
@@ -6,6 +7,12 @@ | |||
| 6 | 7 | except ImportError: | |
| 7 | 8 | import unittest | |
| 8 | 9 | ||
| 10 | + try: | ||
| 11 | + import jedi | ||
| 12 | + has_jedi = True | ||
| 13 | + except ImportError: | ||
| 14 | + has_jedi = False | ||
| 15 | + | ||
| 9 | 16 | ||
| 10 | 17 | class TestSafeEval(unittest.TestCase): | |
| 11 | 18 | def test_catches_syntax_error(self): | |
@@ -191,4 +198,37 @@ def test_magic_methods_complete_after_double_underscores(self): | |||
| 191 | 198 | block = "class Something(object)\n def __" | |
| 192 | 199 | self.assertSetEqual(com.matches(10, ' def __', block), set(autocomplete.MAGIC_METHODS)) | |
| 193 | 200 | ||
| 194 | - | ||
| 201 | + Comp = namedtuple('Completion', ['name', 'complete']) | ||
| 202 | + | ||
| 203 | + class TestMultilineJediCompletion(unittest.TestCase): | ||
| 204 | + | ||
| 205 | + @unittest.skipIf(not has_jedi, "jedi not available") | ||
| 206 | + def test_returns_none_with_single_line(self): | ||
| 207 | + com = autocomplete.MultilineJediCompletion() | ||
| 208 | + self.assertEqual(com.matches(2, 'Va', 'Va', []), None) | ||
| 209 | + | ||
| 210 | + @unittest.skipIf(not has_jedi, "jedi not available") | ||
| 211 | + def test_returns_non_with_blank_second_line(self): | ||
| 212 | + com = autocomplete.MultilineJediCompletion() | ||
| 213 | + self.assertEqual(com.matches(0, '', 'class Foo():\n', ['class Foo():']), None) | ||
| 214 | + | ||
| 215 | + def matches_from_completions(self, cursor, line, block, history, completions): | ||
| 216 | + with mock.patch('bpython.autocomplete.jedi.Script') as Script: | ||
| 217 | + script = Script.return_value | ||
| 218 | + script.completions.return_value = completions | ||
| 219 | + com = autocomplete.MultilineJediCompletion() | ||
| 220 | + return com.matches(cursor, line, block, history) | ||
| 221 | + | ||
| 222 | + @unittest.skipIf(not has_jedi, "jedi not available") | ||
| 223 | + def test_completions_starting_with_different_letters(self): | ||
| 224 | + matches = self.matches_from_completions( | ||
| 225 | + 2, ' a', 'class Foo:\n a', ['adsf'], | ||
| 226 | + [Comp('Abc', 'bc'), Comp('Cbc', 'bc')]) | ||
| 227 | + self.assertEqual(matches, None) | ||
| 228 | + | ||
| 229 | + @unittest.skipIf(not has_jedi, "jedi not available") | ||
| 230 | + def test_completions_starting_with_different_cases(self): | ||
| 231 | + matches = self.matches_from_completions( | ||
| 232 | + 2, ' a', 'class Foo:\n a', ['adsf'], | ||
| 233 | + [Comp('Abc', 'bc'), Comp('ade', 'de')]) | ||
| 234 | + self.assertSetEqual(matches, set(['ade'])) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments