From f8442810c60f5bb376b63b851485c4dc956e2eb6 2018-01-03 17:40:34 From: Thomas Kluyver Date: 2018-01-03 17:40:34 Subject: [PATCH] Fix tests of IPython completion machinery --- diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 8c8e4b8..4c817c9 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -1101,28 +1101,31 @@ class IPCompleter(Completer): #use this if positional argument name is also needed #= re.compile(r'[\s|\[]*(\w+)(?:\s*=?\s*.*)') - # All active matcher routines for completion + self.magic_arg_matchers = [ + self.magic_config_matches, + self.magic_color_matches, + ] + + # This is set externally by InteractiveShell + self.custom_completers = None + + @property + def matchers(self): + """All active matcher routines for completion""" if self.use_jedi: - self.matchers = [ + return [ self.file_matches, self.magic_matches, self.dict_key_matches, ] else: - self.matchers = [ + return [ self.python_matches, self.file_matches, self.magic_matches, self.python_func_kw_matches, self.dict_key_matches, ] - self.magic_arg_matchers = [ - self.magic_config_matches, - self.magic_color_matches, - ] - - # This is set externally by InteractiveShell - self.custom_completers = None def all_completions(self, text): """ diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 115e931..05d7a7e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1985,6 +1985,7 @@ class InteractiveShell(SingletonConfigurable): self.set_hook('complete_command', reset_completer, str_key = '%reset') + @skip_doctest def complete(self, text, line=None, cursor_pos=None): """Return the completed text and a list of completions. diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index b3dd790..a6f6db7 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -380,10 +380,13 @@ def test_greedy_completions(): "Shouldn't have completed on a[0]: %s"%c) with greedy_completion(), provisionalcompleter(): def _(line, cursor_pos, expect, message, completion): + ip.Completer.use_jedi = False _,c = ip.complete('.', line=line, cursor_pos=cursor_pos) + nt.assert_in(expect, c, message % c) + + ip.Completer.use_jedi = True with provisionalcompleter(): completions = ip.Completer.completions(line, cursor_pos) - nt.assert_in(expect, c, message%c) nt.assert_in(completion, completions) yield _, 'a[0].', 5, 'a[0].real', "Should have completed on a[0].: %s", Completion(5,5, 'real') @@ -404,13 +407,14 @@ def test_omit__names(): cfg.IPCompleter.omit__names = 0 c.update_config(cfg) with provisionalcompleter(): + c.use_jedi = False s,matches = c.complete('ip.') - completions = set(c.completions('ip.', 3)) - nt.assert_in('ip.__str__', matches) - nt.assert_in(Completion(3, 3, '__str__'), completions) - nt.assert_in('ip._hidden_attr', matches) + + c.use_jedi = True + completions = set(c.completions('ip.', 3)) + nt.assert_in(Completion(3, 3, '__str__'), completions) nt.assert_in(Completion(3,3, "_hidden_attr"), completions) @@ -418,33 +422,37 @@ def test_omit__names(): cfg.IPCompleter.omit__names = 1 c.update_config(cfg) with provisionalcompleter(): + c.use_jedi = False s,matches = c.complete('ip.') - completions = set(c.completions('ip.', 3)) - nt.assert_not_in('ip.__str__', matches) - nt.assert_not_in(Completion(3,3,'__str__'), completions) - # nt.assert_in('ip._hidden_attr', matches) + + c.use_jedi = True + completions = set(c.completions('ip.', 3)) + nt.assert_not_in(Completion(3,3,'__str__'), completions) nt.assert_in(Completion(3,3, "_hidden_attr"), completions) cfg = Config() cfg.IPCompleter.omit__names = 2 c.update_config(cfg) with provisionalcompleter(): + c.use_jedi = False s,matches = c.complete('ip.') - completions = set(c.completions('ip.', 3)) - nt.assert_not_in('ip.__str__', matches) - nt.assert_not_in(Completion(3,3,'__str__'), completions) - nt.assert_not_in('ip._hidden_attr', matches) + + c.use_jedi = True + completions = set(c.completions('ip.', 3)) + nt.assert_not_in(Completion(3,3,'__str__'), completions) nt.assert_not_in(Completion(3,3, "_hidden_attr"), completions) with provisionalcompleter(): + c.use_jedi = False s,matches = c.complete('ip._x.') - completions = set(c.completions('ip._x.', 6)) - nt.assert_in('ip._x.keys', matches) + + c.use_jedi = True + completions = set(c.completions('ip._x.', 6)) nt.assert_in(Completion(6,6, "keys"), completions) del ip._hidden_attr @@ -457,6 +465,7 @@ def test_limit_to__all__False_ok(): """ ip = get_ipython() c = ip.Completer + c.use_jedi = False ip.ex('class D: x=24') ip.ex('d=D()') cfg = Config() @@ -483,6 +492,7 @@ def test_get__all__entries_no__all__ok(): def test_func_kw_completions(): ip = get_ipython() c = ip.Completer + c.use_jedi = False ip.ex('def myfunc(a=1,b=2): return a+b') s, matches = c.complete(None, 'myfunc(1,b') nt.assert_in('b=', matches) @@ -573,6 +583,7 @@ def test_magic_completion_order(): def test_magic_completion_shadowing(): ip = get_ipython() c = ip.Completer + c.use_jedi = False # Before importing matplotlib, %matplotlib magic should be the only option. text, matches = c.complete("mat") @@ -1002,6 +1013,7 @@ def test_from_module_completer(): def test_snake_case_completion(): ip = get_ipython() + ip.Completer.use_jedi = False ip.user_ns['some_three'] = 3 ip.user_ns['some_four'] = 4 _, matches = ip.complete("s_", "print(s_f")