Migrate parso integration to script fixture

This commit is contained in:
Dave Halter
2017-12-29 18:47:13 +01:00
parent 181fe38c17
commit 2493e6ea16
2 changed files with 23 additions and 26 deletions

View File

@@ -3,13 +3,10 @@ from textwrap import dedent
import pytest
from parso import parse
import jedi
from jedi._compatibility import py_version
def test_form_feed_characters():
def test_form_feed_characters(Script):
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):
@@ -18,7 +15,7 @@ def check_p(src):
return module_node
def test_if():
def test_if(Script):
src = dedent('''\
def func():
x = 3
@@ -32,10 +29,10 @@ def test_if():
# Two parsers needed, one for pass and one for the function.
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("""\
class V:
def __init__(self):
@@ -50,10 +47,10 @@ def test_class_and_if():
# COMMENT
a_func()""")
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
help of caches, this is an example that didn't work.
@@ -73,7 +70,7 @@ def test_add_to_end():
" self."
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()
complete(a, 7, 12)
@@ -84,13 +81,15 @@ def test_add_to_end():
complete(a + b)
def test_tokenizer_with_string_literal_backslash():
c = jedi.Script("statement = u'foo\\\n'; statement").goto_definitions()
def test_tokenizer_with_string_literal_backslash(Script):
c = Script("statement = u'foo\\\n'; statement").goto_definitions()
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():
def_, = jedi.Script('x=...;x').goto_definitions()
def test_ellipsis_without_getitem(Script, environment):
if environment.version_info.major == 2:
pytest.skip('In 2.7 Ellipsis can only be used like x[...]')
def_, = Script('x=...;x').goto_definitions()
assert def_.name == 'ellipsis'

View File

@@ -1,20 +1,18 @@
from textwrap import dedent
import jedi
def test_error_correction_with():
def test_error_correction_with(Script):
source = """
with open() as f:
try:
f."""
comps = jedi.Script(source).completions()
comps = Script(source).completions()
assert len(comps) > 30
# `open` completions have a closed attribute.
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."""
source = dedent("""
x = ur'''
@@ -23,19 +21,19 @@ def test_string_literals():
pass
""")
script = jedi.Script(dedent(source))
script = Script(dedent(source))
assert script._get_module().tree_node.end_pos == (6, 0)
assert script.completions()
def test_incomplete_function():
def test_incomplete_function(Script):
source = '''return ImportErr'''
script = jedi.Script(dedent(source), 1, 3)
script = Script(dedent(source), 1, 3)
assert script.completions()
def test_decorator_string_issue():
def test_decorator_string_issue(Script):
"""
Test case from #589
"""
@@ -47,6 +45,6 @@ def test_decorator_string_issue():
bla.''')
s = jedi.Script(source)
s = Script(source)
assert s.completions()
assert s._get_module().tree_node.get_code() == source