Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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