def test_fallback_plugin(): """Test the fallback plugin.""" p = FallbackPlugin() with open(FALLBACK_PLUGIN_FILE, 'rb') as fid: code = fid.read().decode('utf-8') code += '\nlog_dt' path, line = p.get_definition(CodeInfo('definition', code, len(code), __file__, is_python_like=True)) assert path.endswith('fallback_plugin.py') code += '\np.get_completions' path, line = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert path == 'dummy.py' assert 'def get_completions(' in code.splitlines()[line - 1] code += '\npython_like_mod_finder' path, line = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert path == 'dummy.py' # FIXME: we need to prioritize def over = assert 'def python_like_mod_finder' in code.splitlines()[line - 1] code += 'python_like_mod_finder' resp = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.py')) assert resp is None
def test_default_info(): """Test default info response.""" p = FallbackPlugin() source_code = 'foo' docs = p.get_info(CodeInfo('info', source_code, len(source_code), __file__)) assert sorted(list(docs.keys())) == sorted(['name', 'argspec', 'note', 'docstring', 'calltip']) assert not docs['name'] assert not docs['argspec'] assert not docs['note'] assert not docs['docstring'] assert not docs['calltip']
def test_default_info(): """Test default info response.""" p = FallbackPlugin() source_code = 'foo' docs = p.get_info(CodeInfo('info', source_code, len(source_code), __file__)) assert sorted(list(docs.keys())) == sorted( ['name', 'argspec', 'note', 'docstring', 'calltip']) assert not docs['name'] assert not docs['argspec'] assert not docs['note'] assert not docs['docstring'] assert not docs['calltip']
def test_get_definition_class(): """Test the get_definition method for classes.""" p = FallbackPlugin() code = """ class Test(object): def __init__(self): self.foo = bar t = Test() t.foo""" path, line = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert line == 4
def test_get_definition_method(): """Test the get_definition method for methods.""" p = FallbackPlugin() code = ''' def test(a, b): pass test(1,''' path, line = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert line == 2 code = 'import re\n\nre' path, line = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert path == 'dummy.py' and line == 1
def test_get_definition_class(): """Test the get_definition method for classes.""" p = FallbackPlugin() code = """ class Test(object): def __init__(self): self.foo = bar t = Test() t.foo""" path, line = p.get_definition( CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert line == 4
def test_get_completions(): """Test the get_completions method from the Fallback plugin.""" p = FallbackPlugin() code = 'self.proxy.widget; self.p' comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.py')) assert ('proxy', '') in comp, comp code = 'self.sigMessageReady.emit; self.s' comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.py')) assert ('sigMessageReady', '') in comp code = 'bob = 1; bo' comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.m')) assert ('bob', '') in comp code = 'functi' comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.sh')) assert ('function', '') in comp, comp
def test_get_definition_method(): """Test the get_definition method for methods.""" p = FallbackPlugin() code = ''' def test(a, b): pass test(1,''' path, line = p.get_definition( CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert line == 2 code = 'import re\n\nre' path, line = p.get_definition( CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert path == 'dummy.py' and line == 1
def test_get_completions(): """Test the get_completions method from the Fallback plugin.""" p = FallbackPlugin() code = 'self.proxy.widget; self.p' comp = p.get_completions( CodeInfo('completions', code, len(code), 'dummy.py')) assert ('proxy', '') in comp, comp code = 'self.sigMessageReady.emit; self.s' comp = p.get_completions( CodeInfo('completions', code, len(code), 'dummy.py')) assert ('sigMessageReady', '') in comp code = 'bob = 1; bo' comp = p.get_completions( CodeInfo('completions', code, len(code), 'dummy.m')) assert ('bob', '') in comp code = 'functi' comp = p.get_completions( CodeInfo('completions', code, len(code), 'dummy.sh')) assert ('function', '') in comp, comp
def test_fallback_plugin(): """Test the fallback plugin.""" p = FallbackPlugin() with open(FALLBACK_PLUGIN_FILE, 'rb') as fid: code = fid.read().decode('utf-8') code += '\nlog_dt' path, line = p.get_definition( CodeInfo('definition', code, len(code), __file__, is_python_like=True)) assert path.endswith('fallback_plugin.py') code += '\np.get_completions' path, line = p.get_definition( CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert path == 'dummy.py' assert 'def get_completions(' in code.splitlines()[line - 1] code += '\npython_like_mod_finder' path, line = p.get_definition( CodeInfo('definition', code, len(code), 'dummy.py', is_python_like=True)) assert path == 'dummy.py' # FIXME: we need to prioritize def over = assert 'def python_like_mod_finder' in code.splitlines()[line - 1] code += 'python_like_mod_finder' resp = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.py')) assert resp is None