mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Avoid execution of Jedi in test setup
This makes testing Jedi potentially faster.
This commit is contained in:
@@ -18,52 +18,52 @@ def test_is_keyword():
|
|||||||
assert len(results) == 1 and results[0].is_keyword is False
|
assert len(results) == 1 and results[0].is_keyword is False
|
||||||
|
|
||||||
|
|
||||||
def make_definitions():
|
def test_basedefinition_type():
|
||||||
"""
|
def make_definitions():
|
||||||
Return a list of definitions for parametrized tests.
|
"""
|
||||||
|
Return a list of definitions for parametrized tests.
|
||||||
|
|
||||||
:rtype: [jedi.api_classes.BaseDefinition]
|
:rtype: [jedi.api_classes.BaseDefinition]
|
||||||
"""
|
"""
|
||||||
source = dedent("""
|
source = dedent("""
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
x = C()
|
x = C()
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def g():
|
def g():
|
||||||
yield
|
yield
|
||||||
|
|
||||||
h = lambda: None
|
h = lambda: None
|
||||||
""")
|
""")
|
||||||
|
|
||||||
definitions = []
|
definitions = []
|
||||||
definitions += names(source)
|
definitions += names(source)
|
||||||
|
|
||||||
source += dedent("""
|
source += dedent("""
|
||||||
variable = sys or C or x or f or g or g() or h""")
|
variable = sys or C or x or f or g or g() or h""")
|
||||||
lines = source.splitlines()
|
lines = source.splitlines()
|
||||||
script = Script(source, len(lines), len('variable'), None)
|
script = Script(source, len(lines), len('variable'), None)
|
||||||
definitions += script.goto_definitions()
|
definitions += script.goto_definitions()
|
||||||
|
|
||||||
script2 = Script(source, 4, len('class C'), None)
|
script2 = Script(source, 4, len('class C'), None)
|
||||||
definitions += script2.usages()
|
definitions += script2.usages()
|
||||||
|
|
||||||
source_param = "def f(a): return a"
|
source_param = "def f(a): return a"
|
||||||
script_param = Script(source_param, 1, len(source_param), None)
|
script_param = Script(source_param, 1, len(source_param), None)
|
||||||
definitions += script_param.goto_assignments()
|
definitions += script_param.goto_assignments()
|
||||||
|
|
||||||
return definitions
|
return definitions
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('definition', make_definitions())
|
for definition in make_definitions():
|
||||||
def test_basedefinition_type(definition):
|
assert definition.type in ('module', 'class', 'instance', 'function',
|
||||||
assert definition.type in ('module', 'class', 'instance', 'function',
|
'generator', 'statement', 'import', 'param')
|
||||||
'generator', 'statement', 'import', 'param')
|
|
||||||
|
|
||||||
|
|
||||||
def test_basedefinition_type_import():
|
def test_basedefinition_type_import():
|
||||||
|
|||||||
Reference in New Issue
Block a user