diff --git a/dynamic.py b/dynamic.py index 163731e3..6a260ba9 100644 --- a/dynamic.py +++ b/dynamic.py @@ -321,8 +321,14 @@ def get_related_names(definitions, search_name, modules): return result - # TODO check modules in the same directoy 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: try: stmts = m.used_names[search_name] @@ -343,6 +349,9 @@ class RelatedName(): self.scope = scope 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): - return "<%s: %s@%s,%s>" % (self.__class__.__name__, self.text, - self.start_pos[0], self.start_pos[1]) + return "<%s: %s>" % (self.__class__.__name__, self.description) diff --git a/test/completion/renaming.py b/test/completion/renaming.py new file mode 100644 index 00000000..19013d13 --- /dev/null +++ b/test/completion/renaming.py @@ -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 diff --git a/test/regression.py b/test/regression.py index 45fef560..029f5921 100755 --- a/test/regression.py +++ b/test/regression.py @@ -83,6 +83,13 @@ class TestRegression(unittest.TestCase): s = self.complete("", (1,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__': unittest.main() diff --git a/test/run.py b/test/run.py index 504bc6e2..9bc46a91 100755 --- a/test/run.py +++ b/test/run.py @@ -118,6 +118,32 @@ def run_goto_test(correct, source, line_nr, index, line, path): 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): """ 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 # get_definition test path = completion_test_dir + os.path.sep + f_name + args = (correct, source, line_nr, index, line, path) if test_type == '!': - fails += run_goto_test(correct, source, line_nr, index, line, - path) + fails += run_goto_test(*args) + elif test_type == '<': + fails += run_related_name_test(*args) elif correct.startswith('['): - fails += run_completion_test(correct, source, line_nr, index, - line, path) + fails += run_completion_test(*args) else: fails += run_definition_test(correct, source, line_nr, index, line, start, path) @@ -163,7 +190,7 @@ def run_test(source, f_name, lines_to_execute): tests += 1 else: 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 = r.group(1) correct = r.group(2)