1
0
forked from VimPlug/jedi

Cleanup test_regression tests

This commit is contained in:
Dave Halter
2017-12-29 20:13:04 +01:00
parent ff4f7d5471
commit 918153d55a

View File

@@ -9,16 +9,12 @@ import textwrap
import pytest import pytest
from jedi import Script
from jedi import api from jedi import api
from jedi.evaluate import imports from jedi.evaluate import imports
from .helpers import TestCase, cwd_at from .helpers import cwd_at
#jedi.set_debug_function()
class TestRegression(TestCase): def test_goto_definition_cursor(Script):
def test_goto_definition_cursor(self):
s = ("class A():\n" s = ("class A():\n"
" def _something(self):\n" " def _something(self):\n"
@@ -54,9 +50,10 @@ class TestRegression(TestCase):
assert get_def(cls) == [] assert get_def(cls) == []
@pytest.mark.skipif('True', reason='Skip for now, test case is not really supported.') @pytest.mark.skipif('True', reason='Skip for now, test case is not really supported.')
@cwd_at('jedi') @cwd_at('jedi')
def test_add_dynamic_mods(self): def test_add_dynamic_mods(Script):
fname = '__main__.py' fname = '__main__.py'
api.settings.additional_dynamic_modules = [fname] api.settings.additional_dynamic_modules = [fname]
# Fictional module that defines a function. # Fictional module that defines a function.
@@ -69,20 +66,23 @@ class TestRegression(TestCase):
assert len(result) == 1 assert len(result) == 1
assert result[0].description == 'class int' assert result[0].description == 'class int'
def test_os_nowait(self):
def test_os_nowait(Script):
""" github issue #45 """ """ github issue #45 """
s = Script("import os; os.P_").completions() s = Script("import os; os.P_").completions()
assert 'P_NOWAIT' in [i.name for i in s] assert 'P_NOWAIT' in [i.name for i in s]
def test_points_in_completion(self):
def test_points_in_completion(Script):
"""At some point, points were inserted into the completions, this """At some point, points were inserted into the completions, this
caused problems, sometimes. caused problems, sometimes.
""" """
c = Script("if IndentationErr").completions() c = Script("if IndentationErr").completions()
assert c[0].name == 'IndentationError' assert c[0].name == 'IndentationError'
self.assertEqual(c[0].complete, 'or') assert c[0].complete == 'or'
def test_no_statement_parent(self):
def test_no_statement_parent(Script):
source = textwrap.dedent(""" source = textwrap.dedent("""
def f(): def f():
pass pass
@@ -93,10 +93,10 @@ class TestRegression(TestCase):
variable = f if random.choice([0, 1]) else C""") variable = f if random.choice([0, 1]) else C""")
defs = Script(source, column=3).goto_definitions() defs = Script(source, column=3).goto_definitions()
defs = sorted(defs, key=lambda d: d.line) defs = sorted(defs, key=lambda d: d.line)
self.assertEqual([d.description for d in defs], assert [d.description for d in defs] == ['def f', 'class C']
['def f', 'class C'])
def check_definition_by_marker(self, source, after_cursor, names):
def check_definition_by_marker(Script, source, after_cursor, names):
r""" r"""
Find definitions specified by `after_cursor` and check what found Find definitions specified by `after_cursor` and check what found
@@ -116,11 +116,12 @@ class TestRegression(TestCase):
defs = Script(source, i + 1, column).goto_definitions() defs = Script(source, i + 1, column).goto_definitions()
assert [d.name for d in defs] == names assert [d.name for d in defs] == names
def test_backslash_continuation(self):
def test_backslash_continuation(Script):
""" """
Test that ModuleWithCursor.get_path_until_cursor handles continuation Test that ModuleWithCursor.get_path_until_cursor handles continuation
""" """
self.check_definition_by_marker(r""" check_definition_by_marker(Script, r"""
x = 0 x = 0
a = \ a = \
[1, 2, 3, 4, 5, 6, 7, 8, 9, x] # <-- here [1, 2, 3, 4, 5, 6, 7, 8, 9, x] # <-- here
@@ -130,14 +131,16 @@ class TestRegression(TestCase):
s = 'asdfxyxxxxxxxx sds\\\n hello' s = 'asdfxyxxxxxxxx sds\\\n hello'
assert Script(s, 2, 4).goto_assignments() == [] assert Script(s, 2, 4).goto_assignments() == []
def test_backslash_continuation_and_bracket(self):
self.check_definition_by_marker(r""" def test_backslash_continuation_and_bracket(Script):
check_definition_by_marker(Script, r"""
x = 0 x = 0
a = \ a = \
[1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here [1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here
""", '(x)] # <-- here', ['int']) """, '(x)] # <-- here', ['int'])
def test_generator(self):
def test_generator(Script):
# Did have some problems with the usage of generator completions this # Did have some problems with the usage of generator completions this
# way. # way.
s = "def abc():\n" \ s = "def abc():\n" \
@@ -145,7 +148,8 @@ class TestRegression(TestCase):
"abc()." "abc()."
assert Script(s).completions() assert Script(s).completions()
def test_fake_subnodes(self):
def test_fake_subnodes(Script):
""" """
Test the number of subnodes of a fake object. Test the number of subnodes of a fake object.
@@ -170,7 +174,7 @@ class TestRegression(TestCase):
assert n == limit assert n == limit
def test_loading_unicode_files_with_bad_global_charset(monkeypatch, tmpdir): def test_loading_unicode_files_with_bad_global_charset(Script, monkeypatch, tmpdir):
dirname = str(tmpdir.mkdir('jedi-test')) dirname = str(tmpdir.mkdir('jedi-test'))
filename1 = os.path.join(dirname, 'test1.py') filename1 = os.path.join(dirname, 'test1.py')
filename2 = os.path.join(dirname, 'test2.py') filename2 = os.path.join(dirname, 'test2.py')