mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
indexing a particular position with a test is now also possible with get_definition and complete
This commit is contained in:
37
test/run.py
37
test/run.py
@@ -14,7 +14,7 @@ import debug
|
|||||||
debug.ignored_modules = ['parsing', 'builtin']
|
debug.ignored_modules = ['parsing', 'builtin']
|
||||||
|
|
||||||
|
|
||||||
def run_completion_test(correct, source, line_nr, line, path):
|
def run_completion_test(correct, source, line_nr, index, line, path):
|
||||||
"""
|
"""
|
||||||
Runs tests for completions.
|
Runs tests for completions.
|
||||||
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
||||||
@@ -22,7 +22,7 @@ def run_completion_test(correct, source, line_nr, line, path):
|
|||||||
# lines start with 1 and column is just the last (makes no
|
# lines start with 1 and column is just the last (makes no
|
||||||
# difference for testing)
|
# difference for testing)
|
||||||
try:
|
try:
|
||||||
completions = functions.complete(source, line_nr, len(line), path)
|
completions = functions.complete(source, line_nr, index, path)
|
||||||
#import cProfile as profile
|
#import cProfile as profile
|
||||||
#profile.run('functions.complete("""%s""", %i, %i, "%s")'
|
#profile.run('functions.complete("""%s""", %i, %i, "%s")'
|
||||||
# % (source, line_nr, len(line), path))
|
# % (source, line_nr, len(line), path))
|
||||||
@@ -40,7 +40,8 @@ def run_completion_test(correct, source, line_nr, line, path):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def run_definition_test(correct, source, line_nr, line, correct_start, path):
|
def run_definition_test(correct, source, line_nr, index, line, correct_start,
|
||||||
|
path):
|
||||||
"""
|
"""
|
||||||
Runs tests for definitions.
|
Runs tests for definitions.
|
||||||
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
||||||
@@ -48,7 +49,7 @@ def run_definition_test(correct, source, line_nr, line, correct_start, path):
|
|||||||
def defs(line_nr, indent):
|
def defs(line_nr, indent):
|
||||||
return set(functions.get_definition(source, line_nr, indent, path))
|
return set(functions.get_definition(source, line_nr, indent, path))
|
||||||
try:
|
try:
|
||||||
result = defs(line_nr, len(line))
|
result = defs(line_nr, index)
|
||||||
except Exception:
|
except Exception:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
print('test @%s: %s' % (line_nr - 1, line))
|
print('test @%s: %s' % (line_nr - 1, line))
|
||||||
@@ -59,7 +60,7 @@ def run_definition_test(correct, source, line_nr, line, correct_start, path):
|
|||||||
if correct == ' ':
|
if correct == ' ':
|
||||||
continue
|
continue
|
||||||
# -1 for the comment, +3 because of the comment start `#? `
|
# -1 for the comment, +3 because of the comment start `#? `
|
||||||
start = index.start() + 3
|
start = index.start()
|
||||||
if print_debug:
|
if print_debug:
|
||||||
functions.set_debug_function(None)
|
functions.set_debug_function(None)
|
||||||
try:
|
try:
|
||||||
@@ -80,7 +81,7 @@ def run_definition_test(correct, source, line_nr, line, correct_start, path):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def run_goto_test(correct, source, line_nr, line, path):
|
def run_goto_test(correct, source, line_nr, index, line, path):
|
||||||
"""
|
"""
|
||||||
Runs tests for gotos.
|
Runs tests for gotos.
|
||||||
Tests look like this:
|
Tests look like this:
|
||||||
@@ -97,12 +98,6 @@ def run_goto_test(correct, source, line_nr, line, path):
|
|||||||
|
|
||||||
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
Return if the test was a fail or not, with 1 for fail and 0 for success.
|
||||||
"""
|
"""
|
||||||
r = re.match('^(\d+)\s*(.*)$', correct)
|
|
||||||
if r:
|
|
||||||
index = int(r.group(1))
|
|
||||||
correct = r.group(2)
|
|
||||||
else:
|
|
||||||
index = len(line)
|
|
||||||
try:
|
try:
|
||||||
result = functions.goto(source, line_nr, index, path)
|
result = functions.goto(source, line_nr, index, path)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -140,17 +135,25 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
line = unicode(line)
|
line = unicode(line)
|
||||||
line_nr += 1
|
line_nr += 1
|
||||||
if correct:
|
if correct:
|
||||||
|
r = re.match('^(\d+)\s*(.*)$', correct)
|
||||||
|
if r:
|
||||||
|
index = int(r.group(1))
|
||||||
|
correct = r.group(2)
|
||||||
|
start += r.regs[2][0] # second group, start index
|
||||||
|
else:
|
||||||
|
index = len(line)
|
||||||
# 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
|
||||||
if test_type == '!':
|
if test_type == '!':
|
||||||
fails += run_goto_test(correct, source, line_nr, line, path)
|
fails += run_goto_test(correct, source, line_nr, index, line,
|
||||||
elif correct.startswith('['):
|
|
||||||
fails += run_completion_test(correct, source, line_nr, line,
|
|
||||||
path)
|
path)
|
||||||
|
elif correct.startswith('['):
|
||||||
|
fails += run_completion_test(correct, source, line_nr, index,
|
||||||
|
line, path)
|
||||||
else:
|
else:
|
||||||
fails += run_definition_test(correct, source, line_nr, line,
|
fails += run_definition_test(correct, source, line_nr, index,
|
||||||
start, path)
|
line, start, path)
|
||||||
correct = None
|
correct = None
|
||||||
tests += 1
|
tests += 1
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user