mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Migrate parso integration to script fixture
This commit is contained in:
@@ -3,13 +3,10 @@ from textwrap import dedent
|
|||||||
import pytest
|
import pytest
|
||||||
from parso import parse
|
from parso import parse
|
||||||
|
|
||||||
import jedi
|
|
||||||
from jedi._compatibility import py_version
|
|
||||||
|
|
||||||
|
def test_form_feed_characters(Script):
|
||||||
def test_form_feed_characters():
|
|
||||||
s = "\f\nclass Test(object):\n pass"
|
s = "\f\nclass Test(object):\n pass"
|
||||||
jedi.Script(s, line=2, column=18).call_signatures()
|
Script(s, line=2, column=18).call_signatures()
|
||||||
|
|
||||||
|
|
||||||
def check_p(src):
|
def check_p(src):
|
||||||
@@ -18,7 +15,7 @@ def check_p(src):
|
|||||||
return module_node
|
return module_node
|
||||||
|
|
||||||
|
|
||||||
def test_if():
|
def test_if(Script):
|
||||||
src = dedent('''\
|
src = dedent('''\
|
||||||
def func():
|
def func():
|
||||||
x = 3
|
x = 3
|
||||||
@@ -32,10 +29,10 @@ def test_if():
|
|||||||
|
|
||||||
# Two parsers needed, one for pass and one for the function.
|
# Two parsers needed, one for pass and one for the function.
|
||||||
check_p(src)
|
check_p(src)
|
||||||
assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int']
|
assert [d.name for d in Script(src, 8, 6).goto_definitions()] == ['int']
|
||||||
|
|
||||||
|
|
||||||
def test_class_and_if():
|
def test_class_and_if(Script):
|
||||||
src = dedent("""\
|
src = dedent("""\
|
||||||
class V:
|
class V:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -50,10 +47,10 @@ def test_class_and_if():
|
|||||||
# COMMENT
|
# COMMENT
|
||||||
a_func()""")
|
a_func()""")
|
||||||
check_p(src)
|
check_p(src)
|
||||||
assert [d.name for d in jedi.Script(src).goto_definitions()] == ['int']
|
assert [d.name for d in Script(src).goto_definitions()] == ['int']
|
||||||
|
|
||||||
|
|
||||||
def test_add_to_end():
|
def test_add_to_end(Script):
|
||||||
"""
|
"""
|
||||||
The diff parser doesn't parse everything again. It just updates with the
|
The diff parser doesn't parse everything again. It just updates with the
|
||||||
help of caches, this is an example that didn't work.
|
help of caches, this is an example that didn't work.
|
||||||
@@ -73,7 +70,7 @@ def test_add_to_end():
|
|||||||
" self."
|
" self."
|
||||||
|
|
||||||
def complete(code, line=None, column=None):
|
def complete(code, line=None, column=None):
|
||||||
script = jedi.Script(code, line, column, 'example.py')
|
script = Script(code, line, column, 'example.py')
|
||||||
assert script.completions()
|
assert script.completions()
|
||||||
|
|
||||||
complete(a, 7, 12)
|
complete(a, 7, 12)
|
||||||
@@ -84,13 +81,15 @@ def test_add_to_end():
|
|||||||
complete(a + b)
|
complete(a + b)
|
||||||
|
|
||||||
|
|
||||||
def test_tokenizer_with_string_literal_backslash():
|
def test_tokenizer_with_string_literal_backslash(Script):
|
||||||
c = jedi.Script("statement = u'foo\\\n'; statement").goto_definitions()
|
c = Script("statement = u'foo\\\n'; statement").goto_definitions()
|
||||||
assert c[0]._name._context.get_safe_value() == 'foo'
|
assert c[0]._name._context.get_safe_value() == 'foo'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif('py_version < 30', reason='In 2.7 Ellipsis can only be used like x[...]')
|
def test_ellipsis_without_getitem(Script, environment):
|
||||||
def test_ellipsis_without_getitem():
|
if environment.version_info.major == 2:
|
||||||
def_, = jedi.Script('x=...;x').goto_definitions()
|
pytest.skip('In 2.7 Ellipsis can only be used like x[...]')
|
||||||
|
|
||||||
|
def_, = Script('x=...;x').goto_definitions()
|
||||||
|
|
||||||
assert def_.name == 'ellipsis'
|
assert def_.name == 'ellipsis'
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import jedi
|
|
||||||
|
|
||||||
|
def test_error_correction_with(Script):
|
||||||
def test_error_correction_with():
|
|
||||||
source = """
|
source = """
|
||||||
with open() as f:
|
with open() as f:
|
||||||
try:
|
try:
|
||||||
f."""
|
f."""
|
||||||
comps = jedi.Script(source).completions()
|
comps = Script(source).completions()
|
||||||
assert len(comps) > 30
|
assert len(comps) > 30
|
||||||
# `open` completions have a closed attribute.
|
# `open` completions have a closed attribute.
|
||||||
assert [1 for c in comps if c.name == 'closed']
|
assert [1 for c in comps if c.name == 'closed']
|
||||||
|
|
||||||
|
|
||||||
def test_string_literals():
|
def test_string_literals(Script):
|
||||||
"""Simplified case of jedi-vim#377."""
|
"""Simplified case of jedi-vim#377."""
|
||||||
source = dedent("""
|
source = dedent("""
|
||||||
x = ur'''
|
x = ur'''
|
||||||
@@ -23,19 +21,19 @@ def test_string_literals():
|
|||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
|
|
||||||
script = jedi.Script(dedent(source))
|
script = Script(dedent(source))
|
||||||
assert script._get_module().tree_node.end_pos == (6, 0)
|
assert script._get_module().tree_node.end_pos == (6, 0)
|
||||||
assert script.completions()
|
assert script.completions()
|
||||||
|
|
||||||
|
|
||||||
def test_incomplete_function():
|
def test_incomplete_function(Script):
|
||||||
source = '''return ImportErr'''
|
source = '''return ImportErr'''
|
||||||
|
|
||||||
script = jedi.Script(dedent(source), 1, 3)
|
script = Script(dedent(source), 1, 3)
|
||||||
assert script.completions()
|
assert script.completions()
|
||||||
|
|
||||||
|
|
||||||
def test_decorator_string_issue():
|
def test_decorator_string_issue(Script):
|
||||||
"""
|
"""
|
||||||
Test case from #589
|
Test case from #589
|
||||||
"""
|
"""
|
||||||
@@ -47,6 +45,6 @@ def test_decorator_string_issue():
|
|||||||
|
|
||||||
bla.''')
|
bla.''')
|
||||||
|
|
||||||
s = jedi.Script(source)
|
s = Script(source)
|
||||||
assert s.completions()
|
assert s.completions()
|
||||||
assert s._get_module().tree_node.get_code() == source
|
assert s._get_module().tree_node.get_code() == source
|
||||||
|
|||||||
Reference in New Issue
Block a user