##// END OF EJS Templates
Fix tests of IPython completion machinery
Thomas Kluyver -
Show More
@@ -1101,28 +1101,31 b' class IPCompleter(Completer):'
1101 1101 #use this if positional argument name is also needed
1102 1102 #= re.compile(r'[\s|\[]*(\w+)(?:\s*=?\s*.*)')
1103 1103
1104 # All active matcher routines for completion
1104 self.magic_arg_matchers = [
1105 self.magic_config_matches,
1106 self.magic_color_matches,
1107 ]
1108
1109 # This is set externally by InteractiveShell
1110 self.custom_completers = None
1111
1112 @property
1113 def matchers(self):
1114 """All active matcher routines for completion"""
1105 1115 if self.use_jedi:
1106 self.matchers = [
1116 return [
1107 1117 self.file_matches,
1108 1118 self.magic_matches,
1109 1119 self.dict_key_matches,
1110 1120 ]
1111 1121 else:
1112 self.matchers = [
1122 return [
1113 1123 self.python_matches,
1114 1124 self.file_matches,
1115 1125 self.magic_matches,
1116 1126 self.python_func_kw_matches,
1117 1127 self.dict_key_matches,
1118 1128 ]
1119 self.magic_arg_matchers = [
1120 self.magic_config_matches,
1121 self.magic_color_matches,
1122 ]
1123
1124 # This is set externally by InteractiveShell
1125 self.custom_completers = None
1126 1129
1127 1130 def all_completions(self, text):
1128 1131 """
@@ -1985,6 +1985,7 b' class InteractiveShell(SingletonConfigurable):'
1985 1985 self.set_hook('complete_command', reset_completer, str_key = '%reset')
1986 1986
1987 1987
1988 @skip_doctest
1988 1989 def complete(self, text, line=None, cursor_pos=None):
1989 1990 """Return the completed text and a list of completions.
1990 1991
@@ -380,10 +380,13 b' def test_greedy_completions():'
380 380 "Shouldn't have completed on a[0]: %s"%c)
381 381 with greedy_completion(), provisionalcompleter():
382 382 def _(line, cursor_pos, expect, message, completion):
383 ip.Completer.use_jedi = False
383 384 _,c = ip.complete('.', line=line, cursor_pos=cursor_pos)
385 nt.assert_in(expect, c, message % c)
386
387 ip.Completer.use_jedi = True
384 388 with provisionalcompleter():
385 389 completions = ip.Completer.completions(line, cursor_pos)
386 nt.assert_in(expect, c, message%c)
387 390 nt.assert_in(completion, completions)
388 391
389 392 yield _, 'a[0].', 5, 'a[0].real', "Should have completed on a[0].: %s", Completion(5,5, 'real')
@@ -404,13 +407,14 b' def test_omit__names():'
404 407 cfg.IPCompleter.omit__names = 0
405 408 c.update_config(cfg)
406 409 with provisionalcompleter():
410 c.use_jedi = False
407 411 s,matches = c.complete('ip.')
408 completions = set(c.completions('ip.', 3))
409
410 412 nt.assert_in('ip.__str__', matches)
411 nt.assert_in(Completion(3, 3, '__str__'), completions)
412
413 413 nt.assert_in('ip._hidden_attr', matches)
414
415 c.use_jedi = True
416 completions = set(c.completions('ip.', 3))
417 nt.assert_in(Completion(3, 3, '__str__'), completions)
414 418 nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
415 419
416 420
@@ -418,33 +422,37 b' def test_omit__names():'
418 422 cfg.IPCompleter.omit__names = 1
419 423 c.update_config(cfg)
420 424 with provisionalcompleter():
425 c.use_jedi = False
421 426 s,matches = c.complete('ip.')
422 completions = set(c.completions('ip.', 3))
423
424 427 nt.assert_not_in('ip.__str__', matches)
425 nt.assert_not_in(Completion(3,3,'__str__'), completions)
426
427 428 # nt.assert_in('ip._hidden_attr', matches)
429
430 c.use_jedi = True
431 completions = set(c.completions('ip.', 3))
432 nt.assert_not_in(Completion(3,3,'__str__'), completions)
428 433 nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
429 434
430 435 cfg = Config()
431 436 cfg.IPCompleter.omit__names = 2
432 437 c.update_config(cfg)
433 438 with provisionalcompleter():
439 c.use_jedi = False
434 440 s,matches = c.complete('ip.')
435 completions = set(c.completions('ip.', 3))
436
437 441 nt.assert_not_in('ip.__str__', matches)
438 nt.assert_not_in(Completion(3,3,'__str__'), completions)
439
440 442 nt.assert_not_in('ip._hidden_attr', matches)
443
444 c.use_jedi = True
445 completions = set(c.completions('ip.', 3))
446 nt.assert_not_in(Completion(3,3,'__str__'), completions)
441 447 nt.assert_not_in(Completion(3,3, "_hidden_attr"), completions)
442 448
443 449 with provisionalcompleter():
450 c.use_jedi = False
444 451 s,matches = c.complete('ip._x.')
445 completions = set(c.completions('ip._x.', 6))
446
447 452 nt.assert_in('ip._x.keys', matches)
453
454 c.use_jedi = True
455 completions = set(c.completions('ip._x.', 6))
448 456 nt.assert_in(Completion(6,6, "keys"), completions)
449 457
450 458 del ip._hidden_attr
@@ -457,6 +465,7 b' def test_limit_to__all__False_ok():'
457 465 """
458 466 ip = get_ipython()
459 467 c = ip.Completer
468 c.use_jedi = False
460 469 ip.ex('class D: x=24')
461 470 ip.ex('d=D()')
462 471 cfg = Config()
@@ -483,6 +492,7 b' def test_get__all__entries_no__all__ok():'
483 492 def test_func_kw_completions():
484 493 ip = get_ipython()
485 494 c = ip.Completer
495 c.use_jedi = False
486 496 ip.ex('def myfunc(a=1,b=2): return a+b')
487 497 s, matches = c.complete(None, 'myfunc(1,b')
488 498 nt.assert_in('b=', matches)
@@ -573,6 +583,7 b' def test_magic_completion_order():'
573 583 def test_magic_completion_shadowing():
574 584 ip = get_ipython()
575 585 c = ip.Completer
586 c.use_jedi = False
576 587
577 588 # Before importing matplotlib, %matplotlib magic should be the only option.
578 589 text, matches = c.complete("mat")
@@ -1002,6 +1013,7 b' def test_from_module_completer():'
1002 1013
1003 1014 def test_snake_case_completion():
1004 1015 ip = get_ipython()
1016 ip.Completer.use_jedi = False
1005 1017 ip.user_ns['some_three'] = 3
1006 1018 ip.user_ns['some_four'] = 4
1007 1019 _, matches = ip.complete("s_", "print(s_f")
General Comments 0
You need to be logged in to leave comments. Login now