mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
testing for related names (renaming). with first tests
This commit is contained in:
15
dynamic.py
15
dynamic.py
@@ -321,8 +321,14 @@ def get_related_names(definitions, search_name, modules):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# TODO check modules in the same directoy
|
|
||||||
names = []
|
names = []
|
||||||
|
for d in definitions:
|
||||||
|
if isinstance(d, parsing.Statement):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
names.append(RelatedName(d.name.names[0], d))
|
||||||
|
|
||||||
|
# TODO check modules in the same directoy
|
||||||
for m in modules:
|
for m in modules:
|
||||||
try:
|
try:
|
||||||
stmts = m.used_names[search_name]
|
stmts = m.used_names[search_name]
|
||||||
@@ -343,6 +349,9 @@ class RelatedName():
|
|||||||
self.scope = scope
|
self.scope = scope
|
||||||
self.module = self.scope.get_parent_until()
|
self.module = self.scope.get_parent_until()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self):
|
||||||
|
return "%s@%s,%s" % (self.text, self.start_pos[0], self.start_pos[1])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s@%s,%s>" % (self.__class__.__name__, self.text,
|
return "<%s: %s>" % (self.__class__.__name__, self.description)
|
||||||
self.start_pos[0], self.start_pos[1])
|
|
||||||
|
|||||||
12
test/completion/renaming.py
Normal file
12
test/completion/renaming.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
"""
|
||||||
|
Renaming tests. This means search for related names.
|
||||||
|
I always leave a little bit of space to add room for additions, because the
|
||||||
|
results always contain position informations.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def abc(): pass
|
||||||
|
|
||||||
|
#< 0 abc@7,4 abc@10,0 abc@12,0
|
||||||
|
abc.d.a.abc.d
|
||||||
|
|
||||||
|
abc
|
||||||
@@ -83,6 +83,13 @@ class TestRegression(unittest.TestCase):
|
|||||||
s = self.complete("", (1,0))
|
s = self.complete("", (1,0))
|
||||||
assert len(s) > 0
|
assert len(s) > 0
|
||||||
|
|
||||||
|
def test_new(self):
|
||||||
|
""" This is just to try out things, removing or deleting it is ok. """
|
||||||
|
s = ("def abc(): pass\n"
|
||||||
|
"abc.d.a.abc.d"
|
||||||
|
)
|
||||||
|
functions.get_related_names(s, 2, 2, '/')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
37
test/run.py
37
test/run.py
@@ -118,6 +118,32 @@ def run_goto_test(correct, source, line_nr, index, line, path):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def run_related_name_test(correct, source, line_nr, index, line, path):
|
||||||
|
"""
|
||||||
|
Runs tests for gotos.
|
||||||
|
Tests look like this:
|
||||||
|
>>> abc = 1
|
||||||
|
>>> #< abc@1,0 abc@3,0
|
||||||
|
>>> abc
|
||||||
|
|
||||||
|
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
result = functions.get_related_names(source, line_nr, index, path)
|
||||||
|
except Exception:
|
||||||
|
print(traceback.format_exc())
|
||||||
|
print('test @%s: %s' % (line_nr - 1, line))
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
comp_str = set(r.description for r in result)
|
||||||
|
correct = set(correct.strip().split(' '))
|
||||||
|
if comp_str != correct:
|
||||||
|
print('Solution @%s not right, received %s, wanted %s'\
|
||||||
|
% (line_nr - 1, comp_str, correct))
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def run_test(source, f_name, lines_to_execute):
|
def run_test(source, f_name, lines_to_execute):
|
||||||
"""
|
"""
|
||||||
This is the completion test for some cases. The tests are not unit test
|
This is the completion test for some cases. The tests are not unit test
|
||||||
@@ -150,12 +176,13 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
# if a list is wanted, use the completion test, otherwise the
|
# if a list is wanted, use the completion test, otherwise the
|
||||||
# get_definition test
|
# get_definition test
|
||||||
path = completion_test_dir + os.path.sep + f_name
|
path = completion_test_dir + os.path.sep + f_name
|
||||||
|
args = (correct, source, line_nr, index, line, path)
|
||||||
if test_type == '!':
|
if test_type == '!':
|
||||||
fails += run_goto_test(correct, source, line_nr, index, line,
|
fails += run_goto_test(*args)
|
||||||
path)
|
elif test_type == '<':
|
||||||
|
fails += run_related_name_test(*args)
|
||||||
elif correct.startswith('['):
|
elif correct.startswith('['):
|
||||||
fails += run_completion_test(correct, source, line_nr, index,
|
fails += run_completion_test(*args)
|
||||||
line, path)
|
|
||||||
else:
|
else:
|
||||||
fails += run_definition_test(correct, source, line_nr, index,
|
fails += run_definition_test(correct, source, line_nr, index,
|
||||||
line, start, path)
|
line, start, path)
|
||||||
@@ -163,7 +190,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
tests += 1
|
tests += 1
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
r = re.search(r'(?:^|(?<=\s))#([?!])\s*([^\n]+)', line)
|
r = re.search(r'(?:^|(?<=\s))#([?!<])\s*([^\n]+)', line)
|
||||||
# test_type is ? for completion and ! for goto
|
# test_type is ? for completion and ! for goto
|
||||||
test_type = r.group(1)
|
test_type = r.group(1)
|
||||||
correct = r.group(2)
|
correct = r.group(2)
|
||||||
|
|||||||
Reference in New Issue
Block a user