Show More
@@ -109,20 +109,62 b' def test_line_split():' | |||||
109 | check_line_split(sp, [ map(str, p) for p in t] ) |
|
109 | check_line_split(sp, [ map(str, p) for p in t] ) | |
110 |
|
110 | |||
111 |
|
111 | |||
112 | def test_custom_completion_error(): |
|
112 | ||
|
113 | class NamedInstanceMetaclass(type): | |||
|
114 | def __getitem__(cls, item): | |||
|
115 | return cls.get_instance(item) | |||
|
116 | ||||
|
117 | class NamedInstanceClass(object, metaclass=NamedInstanceMetaclass): | |||
|
118 | def __init__(self, name): | |||
|
119 | if not hasattr(self.__class__, 'instances'): | |||
|
120 | self.__class__.instances = {} | |||
|
121 | self.__class__.instances[name] = self | |||
|
122 | ||||
|
123 | @classmethod | |||
|
124 | def _ipython_key_completions_(cls): | |||
|
125 | return cls.instances.keys() | |||
|
126 | ||||
|
127 | @classmethod | |||
|
128 | def get_instance(cls, name): | |||
|
129 | return cls.instances[name] | |||
|
130 | ||||
|
131 | class KeyCompletable(object): | |||
|
132 | def __init__(self, things=()): | |||
|
133 | self.things = things | |||
|
134 | ||||
|
135 | def _ipython_key_completions_(self): | |||
|
136 | return list(self.things) | |||
|
137 | ||||
|
138 | ||||
|
139 | class TestCompleter(unittest.TestCase): | |||
|
140 | ||||
|
141 | def setUp(self): | |||
|
142 | """ | |||
|
143 | We want to silence all PendingDeprecationWarning when testing the completer | |||
|
144 | """ | |||
|
145 | self._assertwarns = self.assertWarns(PendingDeprecationWarning) | |||
|
146 | self._assertwarns.__enter__() | |||
|
147 | ||||
|
148 | def tearDown(self): | |||
|
149 | try: | |||
|
150 | self._assertwarns.__exit__(None, None, None) | |||
|
151 | except AssertionError: | |||
|
152 | pass | |||
|
153 | ||||
|
154 | ||||
|
155 | def test_custom_completion_error(self): | |||
113 | """Test that errors from custom attribute completers are silenced.""" |
|
156 | """Test that errors from custom attribute completers are silenced.""" | |
114 | ip = get_ipython() |
|
157 | ip = get_ipython() | |
115 | class A(object): pass |
|
158 | class A(object): pass | |
116 |
ip.user_ns[' |
|
159 | ip.user_ns['x'] = A() | |
117 |
|
160 | |||
118 | @complete_object.register(A) |
|
161 | @complete_object.register(A) | |
119 | def complete_A(a, existing_completions): |
|
162 | def complete_A(a, existing_completions): | |
120 | raise TypeError("this should be silenced") |
|
163 | raise TypeError("this should be silenced") | |
121 |
|
164 | |||
122 |
ip.complete(" |
|
165 | ip.complete("x.") | |
123 |
|
||||
124 |
|
166 | |||
125 | def test_unicode_completions(): |
|
167 | def test_unicode_completions(self): | |
126 | ip = get_ipython() |
|
168 | ip = get_ipython() | |
127 | # Some strings that trigger different types of completion. Check them both |
|
169 | # Some strings that trigger different types of completion. Check them both | |
128 | # in str and unicode forms |
|
170 | # in str and unicode forms | |
@@ -136,7 +178,7 b' def test_unicode_completions():' | |||||
136 | nt.assert_true(isinstance(text, str)) |
|
178 | nt.assert_true(isinstance(text, str)) | |
137 | nt.assert_true(isinstance(matches, list)) |
|
179 | nt.assert_true(isinstance(matches, list)) | |
138 |
|
180 | |||
139 | def test_latex_completions(): |
|
181 | def test_latex_completions(self): | |
140 | from IPython.core.latex_symbols import latex_symbols |
|
182 | from IPython.core.latex_symbols import latex_symbols | |
141 | import random |
|
183 | import random | |
142 | ip = get_ipython() |
|
184 | ip = get_ipython() | |
@@ -159,7 +201,7 b' def test_latex_completions():' | |||||
159 |
|
201 | |||
160 |
|
202 | |||
161 |
|
203 | |||
162 | def test_back_latex_completion(): |
|
204 | def test_back_latex_completion(self): | |
163 | ip = get_ipython() |
|
205 | ip = get_ipython() | |
164 |
|
206 | |||
165 | # do not return more than 1 matches fro \beta, only the latex one. |
|
207 | # do not return more than 1 matches fro \beta, only the latex one. | |
@@ -167,7 +209,7 b' def test_back_latex_completion():' | |||||
167 | nt.assert_equal(len(matches), 1) |
|
209 | nt.assert_equal(len(matches), 1) | |
168 | nt.assert_equal(matches[0], '\\beta') |
|
210 | nt.assert_equal(matches[0], '\\beta') | |
169 |
|
211 | |||
170 | def test_back_unicode_completion(): |
|
212 | def test_back_unicode_completion(self): | |
171 | ip = get_ipython() |
|
213 | ip = get_ipython() | |
172 |
|
214 | |||
173 | name, matches = ip.complete('\\β €') |
|
215 | name, matches = ip.complete('\\β €') | |
@@ -175,7 +217,7 b' def test_back_unicode_completion():' | |||||
175 | nt.assert_equal(matches[0], '\\ROMAN NUMERAL FIVE') |
|
217 | nt.assert_equal(matches[0], '\\ROMAN NUMERAL FIVE') | |
176 |
|
218 | |||
177 |
|
219 | |||
178 | def test_forward_unicode_completion(): |
|
220 | def test_forward_unicode_completion(self): | |
179 | ip = get_ipython() |
|
221 | ip = get_ipython() | |
180 |
|
222 | |||
181 | name, matches = ip.complete('\\ROMAN NUMERAL FIVE') |
|
223 | name, matches = ip.complete('\\ROMAN NUMERAL FIVE') | |
@@ -184,7 +226,7 b' def test_forward_unicode_completion():' | |||||
184 |
|
226 | |||
185 | @nt.nottest # now we have a completion for \jmath |
|
227 | @nt.nottest # now we have a completion for \jmath | |
186 | @decorators.knownfailureif(sys.platform == 'win32', 'Fails if there is a C:\\j... path') |
|
228 | @decorators.knownfailureif(sys.platform == 'win32', 'Fails if there is a C:\\j... path') | |
187 | def test_no_ascii_back_completion(): |
|
229 | def test_no_ascii_back_completion(self): | |
188 | ip = get_ipython() |
|
230 | ip = get_ipython() | |
189 | with TemporaryWorkingDirectory(): # Avoid any filename completions |
|
231 | with TemporaryWorkingDirectory(): # Avoid any filename completions | |
190 | # single ascii letter that don't have yet completions |
|
232 | # single ascii letter that don't have yet completions | |
@@ -214,28 +256,28 b' class CompletionSplitterTestCase(unittest.TestCase):' | |||||
214 | check_line_split(self.sp, t) |
|
256 | check_line_split(self.sp, t) | |
215 |
|
257 | |||
216 |
|
258 | |||
217 | def test_has_open_quotes1(): |
|
259 | def test_has_open_quotes1(self): | |
218 | for s in ["'", "'''", "'hi' '"]: |
|
260 | for s in ["'", "'''", "'hi' '"]: | |
219 | nt.assert_equal(completer.has_open_quotes(s), "'") |
|
261 | nt.assert_equal(completer.has_open_quotes(s), "'") | |
220 |
|
262 | |||
221 |
|
263 | |||
222 | def test_has_open_quotes2(): |
|
264 | def test_has_open_quotes2(self): | |
223 | for s in ['"', '"""', '"hi" "']: |
|
265 | for s in ['"', '"""', '"hi" "']: | |
224 | nt.assert_equal(completer.has_open_quotes(s), '"') |
|
266 | nt.assert_equal(completer.has_open_quotes(s), '"') | |
225 |
|
267 | |||
226 |
|
268 | |||
227 | def test_has_open_quotes3(): |
|
269 | def test_has_open_quotes3(self): | |
228 | for s in ["''", "''' '''", "'hi' 'ipython'"]: |
|
270 | for s in ["''", "''' '''", "'hi' 'ipython'"]: | |
229 | nt.assert_false(completer.has_open_quotes(s)) |
|
271 | nt.assert_false(completer.has_open_quotes(s)) | |
230 |
|
272 | |||
231 |
|
273 | |||
232 | def test_has_open_quotes4(): |
|
274 | def test_has_open_quotes4(self): | |
233 | for s in ['""', '""" """', '"hi" "ipython"']: |
|
275 | for s in ['""', '""" """', '"hi" "ipython"']: | |
234 | nt.assert_false(completer.has_open_quotes(s)) |
|
276 | nt.assert_false(completer.has_open_quotes(s)) | |
235 |
|
277 | |||
236 |
|
278 | |||
237 | @decorators.knownfailureif(sys.platform == 'win32', "abspath completions fail on Windows") |
|
279 | @decorators.knownfailureif(sys.platform == 'win32', "abspath completions fail on Windows") | |
238 | def test_abspath_file_completions(): |
|
280 | def test_abspath_file_completions(self): | |
239 | ip = get_ipython() |
|
281 | ip = get_ipython() | |
240 | with TemporaryDirectory() as tmpdir: |
|
282 | with TemporaryDirectory() as tmpdir: | |
241 | prefix = os.path.join(tmpdir, 'foo') |
|
283 | prefix = os.path.join(tmpdir, 'foo') | |
@@ -255,7 +297,7 b' def test_abspath_file_completions():' | |||||
255 | nt.assert_equal(c, comp) |
|
297 | nt.assert_equal(c, comp) | |
256 |
|
298 | |||
257 |
|
299 | |||
258 | def test_local_file_completions(): |
|
300 | def test_local_file_completions(self): | |
259 | ip = get_ipython() |
|
301 | ip = get_ipython() | |
260 | with TemporaryWorkingDirectory(): |
|
302 | with TemporaryWorkingDirectory(): | |
261 | prefix = './foo' |
|
303 | prefix = './foo' | |
@@ -275,7 +317,7 b' def test_local_file_completions():' | |||||
275 | nt.assert_true(comp.issubset(set(c))) |
|
317 | nt.assert_true(comp.issubset(set(c))) | |
276 |
|
318 | |||
277 |
|
319 | |||
278 | def test_quoted_file_completions(): |
|
320 | def test_quoted_file_completions(self): | |
279 | ip = get_ipython() |
|
321 | ip = get_ipython() | |
280 | with TemporaryWorkingDirectory(): |
|
322 | with TemporaryWorkingDirectory(): | |
281 | name = "foo'bar" |
|
323 | name = "foo'bar" | |
@@ -306,7 +348,7 b' def test_quoted_file_completions():' | |||||
306 | nt.assert_equal(c, [escaped]) |
|
348 | nt.assert_equal(c, [escaped]) | |
307 |
|
349 | |||
308 |
|
350 | |||
309 | def test_jedi(): |
|
351 | def test_jedi(self): | |
310 | """ |
|
352 | """ | |
311 | A couple of issue we had with Jedi |
|
353 | A couple of issue we had with Jedi | |
312 | """ |
|
354 | """ | |
@@ -340,7 +382,7 b' def test_jedi():' | |||||
340 |
|
382 | |||
341 | yield _test_not_complete, 'does not mix types', 'a=(1,"foo");a[0].', 'capitalize' |
|
383 | yield _test_not_complete, 'does not mix types', 'a=(1,"foo");a[0].', 'capitalize' | |
342 |
|
384 | |||
343 | def test_completion_have_signature(): |
|
385 | def test_completion_have_signature(self): | |
344 | """ |
|
386 | """ | |
345 | Lets make sure jedi is capable of pulling out the signature of the function we are completing. |
|
387 | Lets make sure jedi is capable of pulling out the signature of the function we are completing. | |
346 | """ |
|
388 | """ | |
@@ -354,7 +396,7 b' def test_completion_have_signature():' | |||||
354 | assert 'encoding' in c.signature, "Signature of function was not found by completer" |
|
396 | assert 'encoding' in c.signature, "Signature of function was not found by completer" | |
355 |
|
397 | |||
356 |
|
398 | |||
357 | def test_deduplicate_completions(): |
|
399 | def test_deduplicate_completions(self): | |
358 | """ |
|
400 | """ | |
359 | Test that completions are correctly deduplicated (even if ranges are not the same) |
|
401 | Test that completions are correctly deduplicated (even if ranges are not the same) | |
360 | """ |
|
402 | """ | |
@@ -372,7 +414,7 b' def test_deduplicate_completions():' | |||||
372 | assert l[0].text == 'zoo' # and not `it.accumulate` |
|
414 | assert l[0].text == 'zoo' # and not `it.accumulate` | |
373 |
|
415 | |||
374 |
|
416 | |||
375 | def test_greedy_completions(): |
|
417 | def test_greedy_completions(self): | |
376 | """ |
|
418 | """ | |
377 | Test the capability of the Greedy completer. |
|
419 | Test the capability of the Greedy completer. | |
378 |
|
420 | |||
@@ -406,7 +448,7 b' def test_greedy_completions():' | |||||
406 | yield _, 'a[0].from_', 10, 'a[0].from_bytes', "Should have completed on a[0].from_: %s", Completion(5, 10, 'from_bytes') |
|
448 | yield _, 'a[0].from_', 10, 'a[0].from_bytes', "Should have completed on a[0].from_: %s", Completion(5, 10, 'from_bytes') | |
407 |
|
449 | |||
408 |
|
450 | |||
409 | def test_omit__names(): |
|
451 | def test_omit__names(self): | |
410 | # also happens to test IPCompleter as a configurable |
|
452 | # also happens to test IPCompleter as a configurable | |
411 | ip = get_ipython() |
|
453 | ip = get_ipython() | |
412 | ip._hidden_attr = 1 |
|
454 | ip._hidden_attr = 1 | |
@@ -469,7 +511,7 b' def test_omit__names():' | |||||
469 | del ip._x |
|
511 | del ip._x | |
470 |
|
512 | |||
471 |
|
513 | |||
472 | def test_limit_to__all__False_ok(): |
|
514 | def test_limit_to__all__False_ok(self): | |
473 | """ |
|
515 | """ | |
474 | Limit to all is deprecated, once we remove it this test can go away. |
|
516 | Limit to all is deprecated, once we remove it this test can go away. | |
475 | """ |
|
517 | """ | |
@@ -485,21 +527,21 b' def test_limit_to__all__False_ok():' | |||||
485 | nt.assert_in('d.x', matches) |
|
527 | nt.assert_in('d.x', matches) | |
486 |
|
528 | |||
487 |
|
529 | |||
488 | def test_get__all__entries_ok(): |
|
530 | def test_get__all__entries_ok(self): | |
489 | class A(object): |
|
531 | class A(object): | |
490 | __all__ = ['x', 1] |
|
532 | __all__ = ['x', 1] | |
491 | words = completer.get__all__entries(A()) |
|
533 | words = completer.get__all__entries(A()) | |
492 | nt.assert_equal(words, ['x']) |
|
534 | nt.assert_equal(words, ['x']) | |
493 |
|
535 | |||
494 |
|
536 | |||
495 | def test_get__all__entries_no__all__ok(): |
|
537 | def test_get__all__entries_no__all__ok(self): | |
496 | class A(object): |
|
538 | class A(object): | |
497 | pass |
|
539 | pass | |
498 | words = completer.get__all__entries(A()) |
|
540 | words = completer.get__all__entries(A()) | |
499 | nt.assert_equal(words, []) |
|
541 | nt.assert_equal(words, []) | |
500 |
|
542 | |||
501 |
|
543 | |||
502 | def test_func_kw_completions(): |
|
544 | def test_func_kw_completions(self): | |
503 | ip = get_ipython() |
|
545 | ip = get_ipython() | |
504 | c = ip.Completer |
|
546 | c = ip.Completer | |
505 | c.use_jedi = False |
|
547 | c.use_jedi = False | |
@@ -516,7 +558,7 b' def test_func_kw_completions():' | |||||
516 | nt.assert_in('key=', matches) |
|
558 | nt.assert_in('key=', matches) | |
517 |
|
559 | |||
518 |
|
560 | |||
519 | def test_default_arguments_from_docstring(): |
|
561 | def test_default_arguments_from_docstring(self): | |
520 | ip = get_ipython() |
|
562 | ip = get_ipython() | |
521 | c = ip.Completer |
|
563 | c = ip.Completer | |
522 | kwd = c._default_arguments_from_docstring( |
|
564 | kwd = c._default_arguments_from_docstring( | |
@@ -531,7 +573,7 b' def test_default_arguments_from_docstring():' | |||||
531 | '\n Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n') |
|
573 | '\n Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n') | |
532 | nt.assert_equal(kwd, ['ncall', 'resume', 'nsplit']) |
|
574 | nt.assert_equal(kwd, ['ncall', 'resume', 'nsplit']) | |
533 |
|
575 | |||
534 | def test_line_magics(): |
|
576 | def test_line_magics(self): | |
535 | ip = get_ipython() |
|
577 | ip = get_ipython() | |
536 | c = ip.Completer |
|
578 | c = ip.Completer | |
537 | s, matches = c.complete(None, 'lsmag') |
|
579 | s, matches = c.complete(None, 'lsmag') | |
@@ -540,7 +582,7 b' def test_line_magics():' | |||||
540 | nt.assert_in('%lsmagic', matches) |
|
582 | nt.assert_in('%lsmagic', matches) | |
541 |
|
583 | |||
542 |
|
584 | |||
543 | def test_cell_magics(): |
|
585 | def test_cell_magics(self): | |
544 | from IPython.core.magic import register_cell_magic |
|
586 | from IPython.core.magic import register_cell_magic | |
545 |
|
587 | |||
546 | @register_cell_magic |
|
588 | @register_cell_magic | |
@@ -556,7 +598,7 b' def test_cell_magics():' | |||||
556 | nt.assert_in('%%_foo_cellm', matches) |
|
598 | nt.assert_in('%%_foo_cellm', matches) | |
557 |
|
599 | |||
558 |
|
600 | |||
559 | def test_line_cell_magics(): |
|
601 | def test_line_cell_magics(self): | |
560 | from IPython.core.magic import register_line_cell_magic |
|
602 | from IPython.core.magic import register_line_cell_magic | |
561 |
|
603 | |||
562 | @register_line_cell_magic |
|
604 | @register_line_cell_magic | |
@@ -581,7 +623,7 b' def test_line_cell_magics():' | |||||
581 | nt.assert_in('%%_bar_cellm', matches) |
|
623 | nt.assert_in('%%_bar_cellm', matches) | |
582 |
|
624 | |||
583 |
|
625 | |||
584 | def test_magic_completion_order(): |
|
626 | def test_magic_completion_order(self): | |
585 | ip = get_ipython() |
|
627 | ip = get_ipython() | |
586 | c = ip.Completer |
|
628 | c = ip.Completer | |
587 |
|
629 | |||
@@ -590,7 +632,7 b' def test_magic_completion_order():' | |||||
590 | nt.assert_equal(matches, ["%timeit", "%%timeit"]) |
|
632 | nt.assert_equal(matches, ["%timeit", "%%timeit"]) | |
591 |
|
633 | |||
592 |
|
634 | |||
593 | def test_magic_completion_shadowing(): |
|
635 | def test_magic_completion_shadowing(self): | |
594 | ip = get_ipython() |
|
636 | ip = get_ipython() | |
595 | c = ip.Completer |
|
637 | c = ip.Completer | |
596 | c.use_jedi = False |
|
638 | c.use_jedi = False | |
@@ -610,7 +652,7 b' def test_magic_completion_shadowing():' | |||||
610 | text, matches = c.complete("mat") |
|
652 | text, matches = c.complete("mat") | |
611 | nt.assert_equal(matches, ["%matplotlib"]) |
|
653 | nt.assert_equal(matches, ["%matplotlib"]) | |
612 |
|
654 | |||
613 | def test_magic_completion_shadowing_explicit(): |
|
655 | def test_magic_completion_shadowing_explicit(self): | |
614 | """ |
|
656 | """ | |
615 | If the user try to complete a shadowed magic, and explicit % start should |
|
657 | If the user try to complete a shadowed magic, and explicit % start should | |
616 | still return the completions. |
|
658 | still return the completions. | |
@@ -629,7 +671,7 b' def test_magic_completion_shadowing_explicit():' | |||||
629 | text, matches = c.complete("%mat") |
|
671 | text, matches = c.complete("%mat") | |
630 | nt.assert_equal(matches, ["%matplotlib"]) |
|
672 | nt.assert_equal(matches, ["%matplotlib"]) | |
631 |
|
673 | |||
632 | def test_magic_config(): |
|
674 | def test_magic_config(self): | |
633 | ip = get_ipython() |
|
675 | ip = get_ipython() | |
634 | c = ip.Completer |
|
676 | c = ip.Completer | |
635 |
|
677 | |||
@@ -659,7 +701,7 b' def test_magic_config():' | |||||
659 | nt.assert_list_equal(['AliasManager.default_aliases'], matches) |
|
701 | nt.assert_list_equal(['AliasManager.default_aliases'], matches) | |
660 |
|
702 | |||
661 |
|
703 | |||
662 | def test_magic_color(): |
|
704 | def test_magic_color(self): | |
663 | ip = get_ipython() |
|
705 | ip = get_ipython() | |
664 | c = ip.Completer |
|
706 | c = ip.Completer | |
665 |
|
707 | |||
@@ -679,7 +721,7 b' def test_magic_color():' | |||||
679 | nt.assert_list_equal(['NoColor'], matches) |
|
721 | nt.assert_list_equal(['NoColor'], matches) | |
680 |
|
722 | |||
681 |
|
723 | |||
682 | def test_match_dict_keys(): |
|
724 | def test_match_dict_keys(self): | |
683 | """ |
|
725 | """ | |
684 | Test that match_dict_keys works on a couple of use case does return what |
|
726 | Test that match_dict_keys works on a couple of use case does return what | |
685 | expected, and does not crash |
|
727 | expected, and does not crash | |
@@ -701,7 +743,7 b' def test_match_dict_keys():' | |||||
701 | match_dict_keys |
|
743 | match_dict_keys | |
702 |
|
744 | |||
703 |
|
745 | |||
704 | def test_dict_key_completion_string(): |
|
746 | def test_dict_key_completion_string(self): | |
705 | """Test dictionary key completion for string keys""" |
|
747 | """Test dictionary key completion for string keys""" | |
706 | ip = get_ipython() |
|
748 | ip = get_ipython() | |
707 | complete = ip.Completer.complete |
|
749 | complete = ip.Completer.complete | |
@@ -780,7 +822,7 b' def test_dict_key_completion_string():' | |||||
780 | _, matches = complete(line_buffer="d['before-af") |
|
822 | _, matches = complete(line_buffer="d['before-af") | |
781 | nt.assert_in('before-after', matches) |
|
823 | nt.assert_in('before-after', matches) | |
782 |
|
824 | |||
783 | def test_dict_key_completion_contexts(): |
|
825 | def test_dict_key_completion_contexts(self): | |
784 | """Test expression contexts in which dict key completion occurs""" |
|
826 | """Test expression contexts in which dict key completion occurs""" | |
785 | ip = get_ipython() |
|
827 | ip = get_ipython() | |
786 | complete = ip.Completer.complete |
|
828 | complete = ip.Completer.complete | |
@@ -831,7 +873,7 b' def test_dict_key_completion_contexts():' | |||||
831 |
|
873 | |||
832 |
|
874 | |||
833 |
|
875 | |||
834 | def test_dict_key_completion_bytes(): |
|
876 | def test_dict_key_completion_bytes(self): | |
835 | """Test handling of bytes in dict key completion""" |
|
877 | """Test handling of bytes in dict key completion""" | |
836 | ip = get_ipython() |
|
878 | ip = get_ipython() | |
837 | complete = ip.Completer.complete |
|
879 | complete = ip.Completer.complete | |
@@ -860,7 +902,7 b' def test_dict_key_completion_bytes():' | |||||
860 | nt.assert_not_in("abd", matches) |
|
902 | nt.assert_not_in("abd", matches) | |
861 |
|
903 | |||
862 |
|
904 | |||
863 | def test_dict_key_completion_unicode_py3(): |
|
905 | def test_dict_key_completion_unicode_py3(self): | |
864 | """Test handling of unicode in dict key completion""" |
|
906 | """Test handling of unicode in dict key completion""" | |
865 | ip = get_ipython() |
|
907 | ip = get_ipython() | |
866 | complete = ip.Completer.complete |
|
908 | complete = ip.Completer.complete | |
@@ -889,7 +931,7 b' def test_dict_key_completion_unicode_py3():' | |||||
889 |
|
931 | |||
890 |
|
932 | |||
891 | @dec.skip_without('numpy') |
|
933 | @dec.skip_without('numpy') | |
892 | def test_struct_array_key_completion(): |
|
934 | def test_struct_array_key_completion(self): | |
893 | """Test dict key completion applies to numpy struct arrays""" |
|
935 | """Test dict key completion applies to numpy struct arrays""" | |
894 | import numpy |
|
936 | import numpy | |
895 | ip = get_ipython() |
|
937 | ip = get_ipython() | |
@@ -915,7 +957,7 b' def test_struct_array_key_completion():' | |||||
915 |
|
957 | |||
916 |
|
958 | |||
917 | @dec.skip_without('pandas') |
|
959 | @dec.skip_without('pandas') | |
918 | def test_dataframe_key_completion(): |
|
960 | def test_dataframe_key_completion(self): | |
919 | """Test dict key completion applies to pandas DataFrames""" |
|
961 | """Test dict key completion applies to pandas DataFrames""" | |
920 | import pandas |
|
962 | import pandas | |
921 | ip = get_ipython() |
|
963 | ip = get_ipython() | |
@@ -926,7 +968,7 b' def test_dataframe_key_completion():' | |||||
926 | nt.assert_in("world", matches) |
|
968 | nt.assert_in("world", matches) | |
927 |
|
969 | |||
928 |
|
970 | |||
929 | def test_dict_key_completion_invalids(): |
|
971 | def test_dict_key_completion_invalids(self): | |
930 | """Smoke test cases dict key completion can't handle""" |
|
972 | """Smoke test cases dict key completion can't handle""" | |
931 | ip = get_ipython() |
|
973 | ip = get_ipython() | |
932 | complete = ip.Completer.complete |
|
974 | complete = ip.Completer.complete | |
@@ -944,14 +986,7 b' def test_dict_key_completion_invalids():' | |||||
944 | _, matches = complete(line_buffer="name_error['") |
|
986 | _, matches = complete(line_buffer="name_error['") | |
945 | _, matches = complete(line_buffer="d['\\") # incomplete escape |
|
987 | _, matches = complete(line_buffer="d['\\") # incomplete escape | |
946 |
|
988 | |||
947 | class KeyCompletable(object): |
|
989 | def test_object_key_completion(self): | |
948 | def __init__(self, things=()): |
|
|||
949 | self.things = things |
|
|||
950 |
|
||||
951 | def _ipython_key_completions_(self): |
|
|||
952 | return list(self.things) |
|
|||
953 |
|
||||
954 | def test_object_key_completion(): |
|
|||
955 | ip = get_ipython() |
|
990 | ip = get_ipython() | |
956 | ip.user_ns['key_completable'] = KeyCompletable(['qwerty', 'qwick']) |
|
991 | ip.user_ns['key_completable'] = KeyCompletable(['qwerty', 'qwick']) | |
957 |
|
992 | |||
@@ -960,25 +995,8 b' def test_object_key_completion():' | |||||
960 | nt.assert_in('qwick', matches) |
|
995 | nt.assert_in('qwick', matches) | |
961 |
|
996 | |||
962 |
|
997 | |||
963 | class NamedInstanceMetaclass(type): |
|
|||
964 | def __getitem__(cls, item): |
|
|||
965 | return cls.get_instance(item) |
|
|||
966 |
|
||||
967 | class NamedInstanceClass(object, metaclass=NamedInstanceMetaclass): |
|
|||
968 | def __init__(self, name): |
|
|||
969 | if not hasattr(self.__class__, 'instances'): |
|
|||
970 | self.__class__.instances = {} |
|
|||
971 | self.__class__.instances[name] = self |
|
|||
972 |
|
||||
973 | @classmethod |
|
|||
974 | def _ipython_key_completions_(cls): |
|
|||
975 | return cls.instances.keys() |
|
|||
976 |
|
||||
977 | @classmethod |
|
|||
978 | def get_instance(cls, name): |
|
|||
979 | return cls.instances[name] |
|
|||
980 |
|
998 | |||
981 | def test_class_key_completion(): |
|
999 | def test_class_key_completion(self): | |
982 | ip = get_ipython() |
|
1000 | ip = get_ipython() | |
983 | NamedInstanceClass('qwerty') |
|
1001 | NamedInstanceClass('qwerty') | |
984 | NamedInstanceClass('qwick') |
|
1002 | NamedInstanceClass('qwick') | |
@@ -988,7 +1006,7 b' def test_class_key_completion():' | |||||
988 | nt.assert_in('qwerty', matches) |
|
1006 | nt.assert_in('qwerty', matches) | |
989 | nt.assert_in('qwick', matches) |
|
1007 | nt.assert_in('qwick', matches) | |
990 |
|
1008 | |||
991 | def test_tryimport(): |
|
1009 | def test_tryimport(self): | |
992 | """ |
|
1010 | """ | |
993 | Test that try-import don't crash on trailing dot, and import modules before |
|
1011 | Test that try-import don't crash on trailing dot, and import modules before | |
994 | """ |
|
1012 | """ | |
@@ -996,32 +1014,32 b' def test_tryimport():' | |||||
996 | assert(try_import("IPython.")) |
|
1014 | assert(try_import("IPython.")) | |
997 |
|
1015 | |||
998 |
|
1016 | |||
999 | def test_aimport_module_completer(): |
|
1017 | def test_aimport_module_completer(self): | |
1000 | ip = get_ipython() |
|
1018 | ip = get_ipython() | |
1001 | _, matches = ip.complete('i', '%aimport i') |
|
1019 | _, matches = ip.complete('i', '%aimport i') | |
1002 | nt.assert_in('io', matches) |
|
1020 | nt.assert_in('io', matches) | |
1003 | nt.assert_not_in('int', matches) |
|
1021 | nt.assert_not_in('int', matches) | |
1004 |
|
1022 | |||
1005 | def test_nested_import_module_completer(): |
|
1023 | def test_nested_import_module_completer(self): | |
1006 | ip = get_ipython() |
|
1024 | ip = get_ipython() | |
1007 | _, matches = ip.complete(None, 'import IPython.co', 17) |
|
1025 | _, matches = ip.complete(None, 'import IPython.co', 17) | |
1008 | nt.assert_in('IPython.core', matches) |
|
1026 | nt.assert_in('IPython.core', matches) | |
1009 | nt.assert_not_in('import IPython.core', matches) |
|
1027 | nt.assert_not_in('import IPython.core', matches) | |
1010 | nt.assert_not_in('IPython.display', matches) |
|
1028 | nt.assert_not_in('IPython.display', matches) | |
1011 |
|
1029 | |||
1012 | def test_import_module_completer(): |
|
1030 | def test_import_module_completer(self): | |
1013 | ip = get_ipython() |
|
1031 | ip = get_ipython() | |
1014 | _, matches = ip.complete('i', 'import i') |
|
1032 | _, matches = ip.complete('i', 'import i') | |
1015 | nt.assert_in('io', matches) |
|
1033 | nt.assert_in('io', matches) | |
1016 | nt.assert_not_in('int', matches) |
|
1034 | nt.assert_not_in('int', matches) | |
1017 |
|
1035 | |||
1018 | def test_from_module_completer(): |
|
1036 | def test_from_module_completer(self): | |
1019 | ip = get_ipython() |
|
1037 | ip = get_ipython() | |
1020 | _, matches = ip.complete('B', 'from io import B', 16) |
|
1038 | _, matches = ip.complete('B', 'from io import B', 16) | |
1021 | nt.assert_in('BytesIO', matches) |
|
1039 | nt.assert_in('BytesIO', matches) | |
1022 | nt.assert_not_in('BaseException', matches) |
|
1040 | nt.assert_not_in('BaseException', matches) | |
1023 |
|
1041 | |||
1024 | def test_snake_case_completion(): |
|
1042 | def test_snake_case_completion(self): | |
1025 | ip = get_ipython() |
|
1043 | ip = get_ipython() | |
1026 | ip.Completer.use_jedi = False |
|
1044 | ip.Completer.use_jedi = False | |
1027 | ip.user_ns['some_three'] = 3 |
|
1045 | ip.user_ns['some_three'] = 3 | |
@@ -1030,7 +1048,7 b' def test_snake_case_completion():' | |||||
1030 | nt.assert_in('some_three', matches) |
|
1048 | nt.assert_in('some_three', matches) | |
1031 | nt.assert_in('some_four', matches) |
|
1049 | nt.assert_in('some_four', matches) | |
1032 |
|
1050 | |||
1033 | def test_mix_terms(): |
|
1051 | def test_mix_terms(self): | |
1034 | ip = get_ipython() |
|
1052 | ip = get_ipython() | |
1035 | from textwrap import dedent |
|
1053 | from textwrap import dedent | |
1036 | ip.Completer.use_jedi = False |
|
1054 | ip.Completer.use_jedi = False |
General Comments 0
You need to be logged in to leave comments.
Login now