The integration test runner is now using a different way of getting the supposed results.

This is needed, because goto_definition will not work in comments anymore.
This commit is contained in:
Dave Halter
2016-06-11 16:33:56 +02:00
parent 99a03da8de
commit 4c711339dd

View File

@@ -119,6 +119,8 @@ from functools import reduce
import jedi import jedi
from jedi._compatibility import unicode, is_py3 from jedi._compatibility import unicode, is_py3
from jedi.parser import Parser, load_grammar
from jedi.api.classes import Definition
TEST_COMPLETIONS = 0 TEST_COMPLETIONS = 0
@@ -172,36 +174,31 @@ class IntegrationTestCase(object):
return compare_cb(self, comp_str, set(literal_eval(self.correct))) return compare_cb(self, comp_str, set(literal_eval(self.correct)))
def run_goto_definitions(self, compare_cb): def run_goto_definitions(self, compare_cb):
script = self.script()
evaluator = script._evaluator
def comparison(definition): def comparison(definition):
suffix = '()' if definition.type == 'instance' else '' suffix = '()' if definition.type == 'instance' else ''
return definition.desc_with_module + suffix return definition.desc_with_module + suffix
def definition(correct, correct_start, path): def definition(correct, correct_start, path):
def defs(line_nr, indent):
s = jedi.Script(self.source, line_nr, indent, path)
return set(s.goto_definitions())
should_be = set() should_be = set()
number = 0 for match in re.finditer('(?:[^ ]+)', correct):
for index in re.finditer('(?:[^ ]+)', correct): parser = Parser(load_grammar(), match.string, start_symbol='eval_input')
end = index.end() parser.position_modifier.line = self.line_nr
# +3 because of the comment start `#? ` element = parser.get_parsed_node()
end += 3 element.parent = script._parser.user_scope()
number += 1 results = evaluator.eval_element(element)
try: if not results:
should_be |= defs(self.line_nr - 1, end + correct_start) raise Exception('Could not resolve %s on line %s'
except Exception: % (match.string, self.line_nr - 1))
print('could not resolve %s indent %s'
% (self.line_nr - 1, end)) should_be |= set(Definition(evaluator, r) for r in results)
raise
# because the objects have different ids, `repr`, then compare. # Because the objects have different ids, `repr`, then compare.
should = set(comparison(r) for r in should_be) should = set(comparison(r) for r in should_be)
if len(should) < number:
raise Exception('Solution @%s not right, too few test results: %s'
% (self.line_nr - 1, should))
return should return should
script = self.script()
should = definition(self.correct, self.start, script.path) should = definition(self.correct, self.start, script.path)
result = script.goto_definitions() result = script.goto_definitions()
is_str = set(comparison(r) for r in result) is_str = set(comparison(r) for r in result)
@@ -381,8 +378,8 @@ if __name__ == '__main__':
last = arg last = arg
# completion tests: # completion tests:
dir = os.path.dirname(os.path.realpath(__file__)) dir_ = os.path.dirname(os.path.realpath(__file__))
completion_test_dir = os.path.join(dir, '../test/completion') completion_test_dir = os.path.join(dir_, '../test/completion')
completion_test_dir = os.path.abspath(completion_test_dir) completion_test_dir = os.path.abspath(completion_test_dir)
summary = [] summary = []
tests_fail = 0 tests_fail = 0