removed a lot of the goto usages, used goto_assignments instead. Did the same also for a lot of definition uses

This commit is contained in:
David Halter
2013-05-03 21:26:11 +04:30
parent edd0a08351
commit 7c8fee1257
10 changed files with 41 additions and 40 deletions

View File

@@ -32,9 +32,9 @@ class TestBase(unittest.TestCase):
script = self.get_script(src, pos, path)
return script.completions()
def goto(self, src, pos=None):
def goto_assignments(self, src, pos=None):
script = self.get_script(src, pos)
return script.goto()
return script.goto_assignments()
def function_definition(self, src, pos=None):
script = self.get_script(src, pos)

View File

@@ -1,4 +1,4 @@
# goto command tests are a different in syntax
# goto_assignments command tests are different in syntax
definition = 3
#! 0 ['a = definition']

View File

@@ -1,5 +1,5 @@
"""
Renaming tests. This means search for related names.
Renaming tests. This means search for usages.
I always leave a little bit of space to add room for additions, because the
results always contain position informations.
"""

View File

@@ -10,8 +10,7 @@ el.description
scopes, path, dot, like = \
functions.prepare_goto(source, row, column,
source_path, True)
api._prepare_goto(source, row, column, source_path, True)
# has problems with that (sometimes) very deep nesting.
#? set()

View File

@@ -10,9 +10,9 @@ tests.
There are different kind of tests:
- completions / definitions ``#?``
- goto: ``#!``
- related names: ``#<``
- completions / goto_definitions ``#?``
- goto_assignments: ``#!``
- usages: ``#<``
How to run tests?
+++++++++++++++++
@@ -63,8 +63,8 @@ For example::
Because it follows ``a.rea`` and a is an ``int``, which has a ``real``
property.
Definition
++++++++++
Goto Definitions
+++++++++++++++
Definition tests use the same symbols like completion tests. This is
possible because the completion tests are defined with a list::
@@ -72,8 +72,8 @@ possible because the completion tests are defined with a list::
#? int()
ab = 3; ab
Goto
++++
Goto Assignments
++++++++++++++++
Tests look like this::
@@ -87,7 +87,7 @@ the test (otherwise it's just end of line)::
#! 2 ['abc=1']
abc
Related Names
Usages
+++++++++++++
Tests look like this::
@@ -141,8 +141,8 @@ class IntegrationTestCase(object):
def run(self, compare_cb):
testers = {
TEST_COMPLETIONS: self.run_completion,
TEST_DEFINITIONS: self.run_definition,
TEST_ASSIGNMENTS: self.run_goto,
TEST_DEFINITIONS: self.run_goto_definitions,
TEST_ASSIGNMENTS: self.run_goto_assignments,
TEST_USAGES: self.run_usages,
}
return testers[self.test_type](compare_cb)
@@ -154,11 +154,11 @@ class IntegrationTestCase(object):
comp_str = set([c.name for c in completions])
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
def run_definition(self, compare_cb):
def run_goto_definitions(self, compare_cb):
def definition(correct, correct_start, path):
def defs(line_nr, indent):
s = jedi.Script(self.source, line_nr, indent, path)
return set(s.definition())
return set(s.goto_definitions())
should_be = set()
number = 0
@@ -183,12 +183,12 @@ class IntegrationTestCase(object):
script = self.script()
should_str = definition(self.correct, self.start, script.source_path)
result = script.definition()
result = script.goto_definitions()
is_str = set(r.desc_with_module for r in result)
return compare_cb(self, is_str, should_str)
def run_goto(self, compare_cb):
result = self.script().goto()
def run_goto_assignments(self, compare_cb):
result = self.script().goto_assignments()
comp_str = str(sorted(str(r.description) for r in result))
return compare_cb(self, comp_str, self.correct)
@@ -242,7 +242,7 @@ def collect_file_tests(lines, lines_to_execute):
else:
try:
r = re.search(r'(?:^|(?<=\s))#([?!<])\s*([^\n]+)', line)
# test_type is ? for completion and ! for goto
# test_type is ? for completion and ! for goto_assignments
test_type = r.group(1)
correct = r.group(2)
start = r.start()

View File

@@ -42,7 +42,7 @@ def make_definitions():
source_param = "def f(a): return a"
script_param = api.Script(source_param, 1, len(source_param), None)
definitions += script_param.goto()
definitions += script_param.goto_assignments()
return definitions

View File

@@ -336,7 +336,8 @@ class TestRegression(TestBase):
assert [d.doc for d in defs]
def test_goto_following_on_imports(self):
g = self.goto("import multiprocessing.dummy; multiprocessing.dummy")
s = "import multiprocessing.dummy; multiprocessing.dummy"
g = self.goto_assignments(s)
assert len(g) == 1
assert g[0].start_pos != (0, 0)