Ejemplo n.º 1
0
 def test_multiple_imports(self):
     definitions = api.defined_names("""
     from module import a, b
     from another_module import *
     """)
     self.assertEqual([d.name for d in definitions],
                      ['a', 'b'])
Ejemplo n.º 2
0
 def test_dotted_assignment(self):
     definitions = api.defined_names("""
     x = Class()
     x.y.z = None
     """)
     self.assertEqual([d.name for d in definitions],
                      ['x'])
Ejemplo n.º 3
0
 def test_get_definitions_flat(self):
     definitions = api.defined_names("""
     import module
     class Class:
         pass
     def func():
         pass
     data = None
     """)
     self.assertEqual([d.name for d in definitions],
                      ['module', 'Class', 'func', 'data'])
Ejemplo n.º 4
0
 def test_get_definitions_flat(self):
     definitions = api.defined_names("""
     import module
     class Class:
         pass
     def func():
         pass
     data = None
     """)
     self.assertEqual([d.name for d in definitions],
                      ['module', 'Class', 'func', 'data'])
Ejemplo n.º 5
0
 def test_nested_definitions(self):
     definitions = api.defined_names("""
     class Class:
         def f():
             pass
         def g():
             pass
     """)
     self.assertEqual([d.name for d in definitions], ['Class'])
     subdefinitions = definitions[0].defined_names()
     self.assertEqual([d.name for d in subdefinitions], ['f', 'g'])
     self.assertEqual([d.full_name for d in subdefinitions],
                      ['Class.f', 'Class.g'])
Ejemplo n.º 6
0
 def test_nested_definitions(self):
     definitions = api.defined_names("""
     class Class:
         def f():
             pass
         def g():
             pass
     """)
     self.assertEqual([d.name for d in definitions],
                      ['Class'])
     subdefinitions = definitions[0].defined_names()
     self.assertEqual([d.name for d in subdefinitions],
                      ['f', 'g'])
     self.assertEqual([d.full_name for d in subdefinitions],
                      ['Class.f', 'Class.g'])
Ejemplo n.º 7
0
def make_definitions():
    """
    Return a list of definitions for parametrized tests.

    :rtype: [jedi.api_classes.BaseDefinition]
    """
    source = textwrap.dedent("""
    import sys

    class C:
        pass

    x = C()

    def f():
        pass

    def g():
        yield

    h = lambda: None
    """)

    definitions = []
    definitions += api.defined_names(source)

    source += textwrap.dedent("""
    variable = sys or C or x or f or g or g() or h""")
    lines = source.splitlines()
    script = api.Script(source, len(lines), len('variable'), None)
    definitions += script.goto_definitions()

    script2 = api.Script(source, 4, len('class C'), None)
    definitions += script2.usages()

    source_param = "def f(a): return a"
    script_param = api.Script(source_param, 1, len(source_param), None)
    definitions += script_param.goto_assignments()

    return definitions
Ejemplo n.º 8
0
def make_definitions():
    """
    Return a list of definitions for parametrized tests.

    :rtype: [jedi.api_classes.BaseDefinition]
    """
    source = textwrap.dedent("""
    import sys

    class C:
        pass

    x = C()

    def f():
        pass

    def g():
        yield

    h = lambda: None
    """)

    definitions = []
    definitions += api.defined_names(source)

    source += textwrap.dedent("""
    variable = sys or C or x or f or g or g() or h""")
    lines = source.splitlines()
    script = api.Script(source, len(lines), len('variable'), None)
    definitions += script.goto_definitions()

    script2 = api.Script(source, 4, len('class C'), None)
    definitions += script2.usages()

    source_param = "def f(a): return a"
    script_param = api.Script(source_param, 1, len(source_param), None)
    definitions += script_param.goto_assignments()

    return definitions
Ejemplo n.º 9
0
 def test_multiple_assignment(self):
     definitions = api.defined_names("""
     x = y = None
     """)
     self.assertEqual([d.name for d in definitions],
                      ['x', 'y'])
Ejemplo n.º 10
0
def test_follow_imports():
    # github issue #344
    imp = api.defined_names('import datetime')[0]
    assert imp.name == 'datetime'
    datetime_names = [str(d.name) for d in imp.defined_names()]
    assert 'timedelta' in datetime_names
Ejemplo n.º 11
0
 def check_defined_names(self, source, names):
     definitions = api.defined_names(textwrap.dedent(source))
     self.assert_definition_names(definitions, names)
     return definitions
Ejemplo n.º 12
0
 def check_defined_names(self, source, names):
     definitions = api.defined_names(textwrap.dedent(source))
     self.assert_definition_names(definitions, names)
     return definitions
Ejemplo n.º 13
0
def test_follow_imports():
    # github issue #344
    imp = api.defined_names("import datetime")[0]
    assert imp.name == "datetime"
    datetime_names = [str(d.name) for d in imp.defined_names()]
    assert "timedelta" in datetime_names
Ejemplo n.º 14
0
 def test_multiple_imports(self):
     definitions = api.defined_names("""
     from module import a, b
     from another_module import *
     """)
     self.assertEqual([d.name for d in definitions], ['a', 'b'])
Ejemplo n.º 15
0
 def test_multiple_assignment(self):
     definitions = api.defined_names("""
     x = y = None
     """)
     self.assertEqual([d.name for d in definitions], ['x', 'y'])
Ejemplo n.º 16
0
 def test_dotted_assignment(self):
     definitions = api.defined_names("""
     x = Class()
     x.y.z = None
     """)
     self.assertEqual([d.name for d in definitions], ['x'])
Ejemplo n.º 17
0
def test_follow_imports():
    # github issue #344
    imp = api.defined_names('import datetime')[0]
    assert imp.name == 'datetime'
    datetime_names = [str(d.name) for d in imp.defined_names()]
    assert 'timedelta' in datetime_names
Ejemplo n.º 18
0
 def get_tag(self):
     return (JediTag(n, globalJediType2devp.get(n.type)) for n in defined_names(self.model.get_text()))