mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
actually start checking if the integration tests are instances on both sides of the comparison. This wasnt necessary for just autocompletion, but it's way more important now.
This commit is contained in:
@@ -621,7 +621,10 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
d = d.parent
|
d = d.parent
|
||||||
|
|
||||||
if isinstance(d, compiled.CompiledObject):
|
if isinstance(d, compiled.CompiledObject):
|
||||||
d = d.type() + ' ' + d.name
|
typ = d.type()
|
||||||
|
if typ == 'instance':
|
||||||
|
typ = 'class' # The description should be similar to Py objects.
|
||||||
|
d = typ + ' ' + d.name
|
||||||
elif isinstance(d, iterable.Array):
|
elif isinstance(d, iterable.Array):
|
||||||
d = 'class ' + d.type
|
d = 'class ' + d.type
|
||||||
elif isinstance(d, (pr.Class, er.Class, er.Instance)):
|
elif isinstance(d, (pr.Class, er.Class, er.Instance)):
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ class CompiledObject(Base):
|
|||||||
return _parse_function_doc(self.doc)
|
return _parse_function_doc(self.doc)
|
||||||
|
|
||||||
def type(self):
|
def type(self):
|
||||||
|
if fake.is_class_instance(self.obj):
|
||||||
|
return 'instance'
|
||||||
|
|
||||||
cls = self._cls().obj
|
cls = self._cls().obj
|
||||||
if inspect.isclass(cls):
|
if inspect.isclass(cls):
|
||||||
return 'class'
|
return 'class'
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ arr
|
|||||||
def inputs(param):
|
def inputs(param):
|
||||||
return param
|
return param
|
||||||
|
|
||||||
#? list()
|
#? list
|
||||||
inputs(list)
|
inputs(list)
|
||||||
|
|
||||||
def variable_middle():
|
def variable_middle():
|
||||||
|
|||||||
37
test/run.py
37
test/run.py
@@ -170,6 +170,10 @@ 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):
|
||||||
|
def comparison(definition):
|
||||||
|
suffix = '()' if definition.type == 'instance' else ''
|
||||||
|
return definition.desc_with_module + suffix
|
||||||
|
|
||||||
def definition(correct, correct_start, path):
|
def definition(correct, correct_start, path):
|
||||||
def defs(line_nr, indent):
|
def defs(line_nr, indent):
|
||||||
s = jedi.Script(self.source, line_nr, indent, path)
|
s = jedi.Script(self.source, line_nr, indent, path)
|
||||||
@@ -177,30 +181,29 @@ class IntegrationTestCase(object):
|
|||||||
|
|
||||||
should_be = set()
|
should_be = set()
|
||||||
number = 0
|
number = 0
|
||||||
for index in re.finditer('(?: +|$)', correct):
|
for index in re.finditer('(?:[^ ]+)', correct):
|
||||||
if correct == ' ':
|
end = index.end()
|
||||||
continue
|
# +3 because of the comment start `#? `
|
||||||
# -1 for the comment, +3 because of the comment start `#? `
|
end += 3
|
||||||
start = index.start()
|
|
||||||
number += 1
|
number += 1
|
||||||
try:
|
try:
|
||||||
should_be |= defs(self.line_nr - 1, start + correct_start)
|
should_be |= defs(self.line_nr - 1, end + correct_start)
|
||||||
except Exception:
|
except Exception:
|
||||||
print('could not resolve %s indent %s'
|
print('could not resolve %s indent %s'
|
||||||
% (self.line_nr - 1, start))
|
% (self.line_nr - 1, end))
|
||||||
raise
|
raise
|
||||||
# because the objects have different ids, `repr`, then compare.
|
# because the objects have different ids, `repr`, then compare.
|
||||||
should_str = set(r.desc_with_module for r in should_be)
|
should = set(comparison(r) for r in should_be)
|
||||||
if len(should_str) < number:
|
if len(should) < number:
|
||||||
raise Exception('Solution @%s not right, '
|
raise Exception('Solution @%s not right, too few test results: %s'
|
||||||
'too few test results: %s' % (self.line_nr - 1, should_str))
|
% (self.line_nr - 1, should))
|
||||||
return should_str
|
return should
|
||||||
|
|
||||||
script = self.script()
|
script = self.script()
|
||||||
should_str = 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(r.desc_with_module for r in result)
|
is_str = set(comparison(r) for r in result)
|
||||||
return compare_cb(self, is_str, should_str)
|
return compare_cb(self, is_str, should)
|
||||||
|
|
||||||
def run_goto_assignments(self, compare_cb):
|
def run_goto_assignments(self, compare_cb):
|
||||||
result = self.script().goto_assignments()
|
result = self.script().goto_assignments()
|
||||||
@@ -390,8 +393,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
file_change(current, count, fails)
|
file_change(current, count, fails)
|
||||||
|
|
||||||
print('\nSummary: (%s fails of %s tests) in %.3fs' % (tests_fail,
|
print('\nSummary: (%s fails of %s tests) in %.3fs'
|
||||||
len(cases), time.time() - t_start))
|
% (tests_fail, len(cases), time.time() - t_start))
|
||||||
for s in summary:
|
for s in summary:
|
||||||
print(s)
|
print(s)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user