mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
use docopt for run.py executions, much more readable
This commit is contained in:
@@ -47,9 +47,8 @@ def warning(*args):
|
|||||||
|
|
||||||
def speed(name):
|
def speed(name):
|
||||||
if debug_function and enable_speed:
|
if debug_function and enable_speed:
|
||||||
global start_time
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
debug_function(SPEED, 'speed: ' + '%s %s' % (name, now - start_time))
|
debug_function(SPEED, 'speed: ' + '%s %s' % (u(name), now - start_time))
|
||||||
|
|
||||||
|
|
||||||
def print_to_stdout(level, str_out):
|
def print_to_stdout(level, str_out):
|
||||||
|
|||||||
45
test/run.py
45
test/run.py
@@ -277,38 +277,41 @@ def collect_dir_tests(base_dir, test_files, check_thirdparty=False):
|
|||||||
yield case
|
yield case
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
docoptstr = """
|
||||||
|
Using run.py to make debugging easier with integration tests.
|
||||||
|
|
||||||
|
An alternative testing format, which is much more hacky, but very nice to
|
||||||
|
work with.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
run.py [--pdb] [--debug] [--thirdparty] [<rest>...]
|
||||||
|
run.py --help
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h --help Show this screen.
|
||||||
|
--pdb Enable pdb debugging on fail.
|
||||||
|
-d, --debug Enable text output debugging (please install ``colorama``).
|
||||||
|
--thirdparty Also run thirdparty tests (in ``completion/thirdparty``).
|
||||||
|
"""
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# an alternative testing format, this is much more hacky, but very nice to
|
import docopt
|
||||||
# work with.
|
arguments = docopt.docopt(docoptstr)
|
||||||
|
|
||||||
import time
|
import time
|
||||||
t_start = time.time()
|
t_start = time.time()
|
||||||
# Sorry I didn't use argparse here. It's because argparse is not in the
|
# Sorry I didn't use argparse here. It's because argparse is not in the
|
||||||
# stdlib in 2.5.
|
# stdlib in 2.5.
|
||||||
import sys
|
import sys
|
||||||
args = sys.argv[1:]
|
|
||||||
try:
|
|
||||||
i = args.index('--thirdparty')
|
|
||||||
thirdparty = True
|
|
||||||
args = args[:i] + args[i + 1:]
|
|
||||||
except ValueError:
|
|
||||||
thirdparty = False
|
|
||||||
|
|
||||||
print_debug = False
|
if arguments['--debug']:
|
||||||
try:
|
|
||||||
i = args.index('--debug')
|
|
||||||
args = args[:i] + args[i + 1:]
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
from jedi import api, debug
|
from jedi import api, debug
|
||||||
print_debug = True
|
|
||||||
api.set_debug_function(debug.print_to_stdout)
|
api.set_debug_function(debug.print_to_stdout)
|
||||||
|
|
||||||
# get test list, that should be executed
|
# get test list, that should be executed
|
||||||
test_files = {}
|
test_files = {}
|
||||||
last = None
|
last = None
|
||||||
for arg in args:
|
for arg in arguments['<rest>']:
|
||||||
if arg.isdigit():
|
if arg.isdigit():
|
||||||
if last is None:
|
if last is None:
|
||||||
continue
|
continue
|
||||||
@@ -324,7 +327,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# execute tests
|
# execute tests
|
||||||
cases = list(collect_dir_tests(completion_test_dir, test_files))
|
cases = list(collect_dir_tests(completion_test_dir, test_files))
|
||||||
if test_files or thirdparty:
|
if test_files or arguments['--thirdparty']:
|
||||||
completion_test_dir += '/thirdparty'
|
completion_test_dir += '/thirdparty'
|
||||||
cases += collect_dir_tests(completion_test_dir, test_files, True)
|
cases += collect_dir_tests(completion_test_dir, test_files, True)
|
||||||
|
|
||||||
@@ -354,6 +357,10 @@ if __name__ == '__main__':
|
|||||||
print("\ttest fail @%d" % (c.line_nr - 1))
|
print("\ttest fail @%d" % (c.line_nr - 1))
|
||||||
tests_fail += 1
|
tests_fail += 1
|
||||||
fails += 1
|
fails += 1
|
||||||
|
if arguments['--pdb']:
|
||||||
|
import pdb
|
||||||
|
pdb.post_mortem()
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
if current != c.path:
|
if current != c.path:
|
||||||
|
|||||||
Reference in New Issue
Block a user