diff --git a/test/test_regression.py b/test/test_regression.py index 2ee22fd6..52ba20bc 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -5,21 +5,19 @@ Unit tests to avoid errors of the past. Makes use of Python's ``unittest`` module. """ -import itertools import os import textwrap -from .base import TestBase, unittest, cwd_at +from .base import unittest, cwd_at import jedi from jedi import Script -from jedi._compatibility import utf8, unicode from jedi import api, parsing, common #jedi.set_debug_function(jedi.debug.print_to_stdout) -class TestRegression(TestBase): +class TestRegression(unittest.TestCase): def test_goto_definition_cursor(self): s = ("class A():\n" @@ -39,7 +37,9 @@ class TestRegression(TestBase): diff_line = 4, 10 should2 = 8, 10 - get_def = lambda pos: [d.description for d in self.goto_definitions(s, pos)] + def get_def(pos): + return [d.description for d in Script(s, *pos).goto_definitions()] + in_name = get_def(in_name) under_score = get_def(under_score) should1 = get_def(should1) @@ -55,53 +55,53 @@ class TestRegression(TestBase): self.assertRaises(jedi.NotFoundError, get_def, cls) def test_keyword_doc(self): - r = list(self.goto_definitions("or", (1, 1))) + r = list(Script("or", 1, 1).goto_definitions()) assert len(r) == 1 assert len(r[0].doc) > 100 - r = list(self.goto_definitions("asfdasfd", (1, 1))) + r = list(Script("asfdasfd", 1, 1).goto_definitions()) assert len(r) == 0 - k = self.completions("fro")[0] + k = Script("fro").completions()[0] imp_start = '\nThe ``import' assert k.raw_doc.startswith(imp_start) assert k.doc.startswith(imp_start) def test_operator_doc(self): - r = list(self.goto_definitions("a == b", (1, 3))) + r = list(Script("a == b", 1, 3).goto_definitions()) assert len(r) == 1 assert len(r[0].doc) > 100 def test_function_call_signature(self): - defs = self.goto_definitions(""" + defs = Script(""" def f(x, y=1, z='a'): pass - f""") + f""").goto_definitions() doc = defs[0].doc assert "f(x, y = 1, z = 'a')" in doc def test_class_call_signature(self): - defs = self.goto_definitions(""" + defs = Script(""" class Foo: def __init__(self, x, y=1, z='a'): pass - Foo""") + Foo""").goto_definitions() doc = defs[0].doc assert "Foo(self, x, y = 1, z = 'a')" in doc def test_goto_definition_at_zero(self): - assert self.goto_definitions("a", (1, 1)) == [] - s = self.goto_definitions("str", (1, 1)) + assert Script("a", 1, 1).goto_definitions() == [] + s = Script("str", 1, 1).goto_definitions() assert len(s) == 1 assert list(s)[0].description == 'class str' - assert self.goto_definitions("", (1, 0)) == [] + assert Script("", 1, 0).goto_definitions() == [] def test_complete_at_zero(self): - s = self.completions("str", (1, 3)) + s = Script("str", 1, 3).completions() assert len(s) == 1 assert list(s)[0].name == 'str' - s = self.completions("", (1, 0)) + s = Script("", 1, 0).completions() assert len(s) > 0 @cwd_at('jedi') @@ -113,30 +113,29 @@ class TestRegression(TestBase): src2 = 'from .. import setup; setup.ret(1)' # .parser to load the module api.modules.Module(os.path.abspath('dynamic.py'), src2).parser - script = jedi.Script(src1, 1, len(src1), '../setup.py') - result = script.goto_definitions() + result = Script(src1, source_path='../setup.py').goto_definitions() assert len(result) == 1 assert result[0].description == 'class int' def test_os_nowait(self): """ github issue #45 """ - s = self.completions("import os; os.P_") + s = Script("import os; os.P_").completions() assert 'P_NOWAIT' in [i.name for i in s] def test_keyword(self): """ github jedi-vim issue #44 """ - defs = self.goto_definitions("print") + defs = Script("print").goto_definitions() assert [d.doc for d in defs] - defs = self.goto_definitions("import") + defs = Script("import").goto_definitions() assert len(defs) == 1 and [1 for d in defs if d.doc] # unrelated to #44 - defs = self.goto_assignments("import") + defs = Script("import").goto_assignments() assert len(defs) == 0 - completions = self.completions("import", (1,1)) + completions = Script("import", 1,1).completions() assert len(completions) == 0 with common.ignored(jedi.NotFoundError): # TODO shouldn't throw that. - defs = self.goto_definitions("assert") + defs = Script("assert").goto_definitions() assert len(defs) == 1 def test_goto_assignments_keyword(self): @@ -145,13 +144,13 @@ class TestRegression(TestBase): 'unicode' object has no attribute 'generate_call_path' """ - self.goto_assignments('in') + Script('in').goto_assignments() def test_points_in_completion(self): """At some point, points were inserted into the completions, this caused problems, sometimes. """ - c = self.completions("if IndentationErr") + c = Script("if IndentationErr").completions() assert c[0].name == 'IndentationError' self.assertEqual(c[0].complete, 'or') @@ -164,8 +163,7 @@ class TestRegression(TestBase): pass variable = f or C""") - lines = source.splitlines() - defs = self.goto_definitions(source, (len(lines), 3)) + defs = Script(source, column=3).goto_definitions() defs = sorted(defs, key=lambda d: d.line) self.assertEqual([d.description for d in defs], ['def f', 'class C']) @@ -195,7 +193,7 @@ class TestRegression(TestBase): if after_cursor in line: break column = len(line) - len(after_cursor) - defs = self.goto_definitions(source, (i + 1, column)) + defs = Script(source, i + 1, column).goto_definitions() self.assertEqual([d.name for d in defs], names) def test_backslash_continuation(self): @@ -210,7 +208,7 @@ class TestRegression(TestBase): # completion in whitespace s = 'asdfxyxxxxxxxx sds\\\n hello' - assert self.goto_assignments(s, (2, 4)) == [] + assert Script(s, 2, 4).goto_assignments() == [] def test_backslash_continuation_and_bracket(self): self.check_definition_by_marker(r""" @@ -225,4 +223,4 @@ class TestRegression(TestBase): s = "def abc():\n" \ " yield 1\n" \ "abc()." - assert self.completions(s) + assert Script(s).completions()