Пример #1
0
def test_get_docstring():
    source_code = dedent('''
    def test(a, b):
        """Test docstring"""
        pass
    test(1,''')
    path, line = p.get_definition(CodeInfo('definition', source_code,
                                           len(source_code), 'dummy.txt',
                                           is_python_like=True))
    assert line == 2

    docs = p.get_info(CodeInfo('info', source_code, len(source_code),
                               __file__))
    assert 'Test docstring' in docs['docstring']
Пример #2
0
def test_numpy_returns():
    source_code = dedent('''
    import numpy as np
    x = np.array([1,2,3])
    x.a''')
    completions = p.get_completions(CodeInfo('completions', source_code,
                                             len(source_code)))
    assert ('argmax', 'function') in completions
Пример #3
0
def test_matplotlib_fig_returns():
    source_code = dedent('''
    import matplotlib.pyplot as plt
    fig = plt.figure()
    fig.''')
    completions = p.get_completions(CodeInfo('completions', source_code,
                                             len(source_code)))
    assert ('add_axes', 'function') in completions
Пример #4
0
def test_completions_custom_path():
    source_code = dedent('import test_')
    completions = p.get_completions(
        CodeInfo('completions',
                 source_code,
                 len(source_code),
                 sys_path=[LOCATION]))
    assert ('test_jedi_plugin', 'module') in completions
Пример #5
0
def test_get_completions_custom_path():
    source_code = "import test_rope_plugin; test_"
    completions = p.get_completions(
        CodeInfo('completions',
                 source_code,
                 len(source_code),
                 sys_path=[LOCATION]))
    assert ('test_rope_plugin', 'module') in completions
Пример #6
0
def test_default_info():
    """Test default info response."""
    source_code = 'foo'
    docs = p.get_info(CodeInfo('info', source_code, len(source_code),
                               __file__, is_python_like=True))
    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']
Пример #7
0
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
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
0
def test_get_completions_2():
    source_code = "import a"
    completions = p.get_completions(
        CodeInfo('completions', source_code, len(source_code), __file__))
    assert not completions
Пример #12
0
def test_get_completions_1():
    source_code = "import numpy; n"
    completions = p.get_completions(
        CodeInfo('completions', source_code, len(source_code), __file__))
    assert ('numpy', 'module') in completions
Пример #13
0
def test_get_info():
    source_code = "import numpy; numpy.ones"
    docs = p.get_info(CodeInfo('info', source_code, len(source_code),
                               __file__))
    assert docs['calltip'].startswith('ones(') and docs['name'] == 'ones'
Пример #14
0
def test_get_path():
    source_code = 'from spyder.utils.introspection.manager import CodeInfo'
    path, line_nr = p.get_definition(CodeInfo('definition', source_code,
                                              len(source_code), __file__))
    assert 'utils' in path and 'introspection' in path
Пример #15
0
def test_get_completions():
    source_code = "import o"
    completions = p.get_completions(CodeInfo('completions', source_code,
                                             len(source_code)))
    assert ('os', 'module') in completions
Пример #16
0
def test_get_info():
    source_code = "import os; os.walk"
    docs = p.get_info(CodeInfo('info', source_code, len(source_code)))
    assert docs['calltip'].startswith('walk(') and docs['name'] == 'walk'
Пример #17
0
def test_get_info_from_method():
    """Regression test for issue 6516."""
    source_code = "L = [1]; L.append"
    docs = p.get_info(CodeInfo('info', source_code, len(source_code)))
    assert docs['calltip'].startswith('L.append(')
    assert docs['name'] == 'L.append'
Пример #18
0
                if not line_nr:
                    module_path = None
        if not ext in self.all_editable_exts():
            line_nr = None
        return module_path, line_nr


if __name__ == '__main__':

    from spyder.utils.introspection.manager import CodeInfo

    p = JediPlugin()
    p.load_plugin()

    source_code = "import numpy; numpy.ones("
    docs = p.get_info(CodeInfo('info', source_code, len(source_code)))

    assert docs['calltip'].startswith('ones(') and docs['name'] == 'ones'

    source_code = "import n"
    completions = p.get_completions(
        CodeInfo('completions', source_code, len(source_code)))
    assert ('numpy', 'module') in completions

    source_code = "import pandas as pd; pd.DataFrame"
    path, line_nr = p.get_definition(
        CodeInfo('definition', source_code, len(source_code)))
    assert 'frame.py' in path

    source_code = 'from .utils import CodeInfo'
    path, line_nr = p.get_definition(
Пример #19
0
def test_get_definition():
    source_code = "import os; os.walk"
    path, line_nr = p.get_definition(
        CodeInfo('definition', source_code, len(source_code), __file__))
    assert 'os.py' in path
Пример #20
0
        return [p for p in _listdir(path)]
    # exact file match terminates this completion
    return [path + ' ']


if __name__ == '__main__':
    from spyder.utils.introspection.manager import CodeInfo

    p = FallbackPlugin()

    with open(__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',