mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 10:07:06 +08:00
tests for get_definitions
This commit is contained in:
@@ -162,7 +162,7 @@ def gen():
|
|||||||
yield 1
|
yield 1
|
||||||
yield ""
|
yield ""
|
||||||
|
|
||||||
gen_exe = gen()
|
gen_exe = gen()
|
||||||
|
|
||||||
def nexti(iterator, default=list):
|
def nexti(iterator, default=list):
|
||||||
if hasattr("next"):
|
if hasattr("next"):
|
||||||
|
|||||||
@@ -241,3 +241,5 @@ gen_exe = gen()
|
|||||||
next(gen_exe).upper
|
next(gen_exe).upper
|
||||||
#? ['real']
|
#? ['real']
|
||||||
next(gen_exe).real
|
next(gen_exe).real
|
||||||
|
#? float() str()
|
||||||
|
next(gen_exe)
|
||||||
|
|||||||
82
test/run.py
82
test/run.py
@@ -11,6 +11,59 @@ import functions
|
|||||||
|
|
||||||
#functions.set_debug_function(functions.debug.print_to_stdout)
|
#functions.set_debug_function(functions.debug.print_to_stdout)
|
||||||
|
|
||||||
|
def run_completion_test(correct, source, line_nr, line):
|
||||||
|
"""
|
||||||
|
Runs tests for completions.
|
||||||
|
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
||||||
|
"""
|
||||||
|
# lines start with 1 and column is just the last (makes no
|
||||||
|
# difference for testing)
|
||||||
|
try:
|
||||||
|
completions = functions.complete(source, line_nr, 999,
|
||||||
|
completion_test_dir)
|
||||||
|
except Exception:
|
||||||
|
print('test @%s: %s' % (line_nr-1, line))
|
||||||
|
print(traceback.format_exc())
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
# TODO remove sorted? completions should be sorted?
|
||||||
|
# TODO remove set! duplicates should not be normal
|
||||||
|
comp_str = str(sorted(set([str(c) for c in completions])))
|
||||||
|
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_definition_test(correct, source, line_nr, line):
|
||||||
|
"""
|
||||||
|
Runs tests for definitions.
|
||||||
|
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
||||||
|
"""
|
||||||
|
def defs(line_nr, indent):
|
||||||
|
return set(functions.get_definitions(source, line_nr, indent,
|
||||||
|
completion_test_dir))
|
||||||
|
try:
|
||||||
|
result = defs(line_nr, 999)
|
||||||
|
except Exception:
|
||||||
|
print('test @%s: %s' % (line_nr-1, line))
|
||||||
|
print(traceback.format_exc())
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
should_be = set()
|
||||||
|
for index in re.finditer('(?: +|$)', correct):
|
||||||
|
# -1 for the comment, +3 because of the comment start `#? `
|
||||||
|
should_be |= defs(line_nr-1, index.start() + 3)
|
||||||
|
# because the objects have different ids, `repr` it, then compare it.
|
||||||
|
should_str = sorted(str(r) for r in should_be)
|
||||||
|
is_str = sorted(str(r) for r in result)
|
||||||
|
if is_str != should_str:
|
||||||
|
print('Solution @%s not right, received %s, wanted %s' \
|
||||||
|
% (line_nr - 1, is_str, should_str))
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def completion_test(source):
|
def completion_test(source):
|
||||||
"""
|
"""
|
||||||
@@ -30,24 +83,13 @@ def completion_test(source):
|
|||||||
for line_nr, line in enumerate(StringIO.StringIO(source)):
|
for line_nr, line in enumerate(StringIO.StringIO(source)):
|
||||||
line_nr += 1
|
line_nr += 1
|
||||||
if correct:
|
if correct:
|
||||||
# lines start with 1 and column is just the last (makes no
|
# if a list is wanted, use the completion test, otherwise the
|
||||||
# difference for testing)
|
# get_definition test
|
||||||
try:
|
if correct.startswith('['):
|
||||||
completions = functions.complete(source, line_nr, 999,
|
fails += run_completion_test(correct, source, line_nr, line)
|
||||||
completion_test_dir)
|
|
||||||
except Exception:
|
|
||||||
print 'test @%s: %s' % (line_nr-1, line)
|
|
||||||
print traceback.format_exc()
|
|
||||||
fails += 1
|
|
||||||
else:
|
else:
|
||||||
# TODO remove sorted? completions should be sorted?
|
fails += run_definition_test(correct, source, line_nr, line)
|
||||||
# TODO remove set! duplicates should not be normal
|
|
||||||
comp_str = str(sorted(set([str(c) for c in completions])))
|
|
||||||
if comp_str != correct:
|
|
||||||
print 'Solution @%s not right, received %s, wanted %s'\
|
|
||||||
% (line_nr - 1, comp_str, correct)
|
|
||||||
#print [(c.name, c.name.parent) for c in completions]
|
|
||||||
fails += 1
|
|
||||||
correct = None
|
correct = None
|
||||||
tests += 1
|
tests += 1
|
||||||
else:
|
else:
|
||||||
@@ -75,9 +117,9 @@ for f_name in os.listdir(completion_test_dir):
|
|||||||
f = open(path)
|
f = open(path)
|
||||||
num_tests, fails = completion_test(f.read())
|
num_tests, fails = completion_test(f.read())
|
||||||
s = 'run %s tests with %s fails (%s)' % (num_tests, fails, f_name)
|
s = 'run %s tests with %s fails (%s)' % (num_tests, fails, f_name)
|
||||||
print s
|
print(s)
|
||||||
summary.append(s)
|
summary.append(s)
|
||||||
|
|
||||||
print '\nSummary:'
|
print('\nSummary:')
|
||||||
for s in summary:
|
for s in summary:
|
||||||
print s
|
print(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user