From a72601a9d84ae0e6583bd488e7fbf3e28fc7d571 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sun, 11 Aug 2013 19:53:14 +0430 Subject: [PATCH] use docopt for run.py executions, much more readable --- jedi/debug.py | 3 +-- test/run.py | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/jedi/debug.py b/jedi/debug.py index e4d2f670..cea7b30a 100644 --- a/jedi/debug.py +++ b/jedi/debug.py @@ -47,9 +47,8 @@ def warning(*args): def speed(name): if debug_function and enable_speed: - global start_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): diff --git a/test/run.py b/test/run.py index 5ec4b557..d6296ea8 100755 --- a/test/run.py +++ b/test/run.py @@ -277,38 +277,41 @@ def collect_dir_tests(base_dir, test_files, check_thirdparty=False): 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] [...] + 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__': - # an alternative testing format, this is much more hacky, but very nice to - # work with. + import docopt + arguments = docopt.docopt(docoptstr) import time t_start = time.time() # Sorry I didn't use argparse here. It's because argparse is not in the # stdlib in 2.5. 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 - try: - i = args.index('--debug') - args = args[:i] + args[i + 1:] - except ValueError: - pass - else: + if arguments['--debug']: from jedi import api, debug - print_debug = True api.set_debug_function(debug.print_to_stdout) # get test list, that should be executed test_files = {} last = None - for arg in args: + for arg in arguments['']: if arg.isdigit(): if last is None: continue @@ -324,7 +327,7 @@ if __name__ == '__main__': # execute tests 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' 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)) tests_fail += 1 fails += 1 + if arguments['--pdb']: + import pdb + pdb.post_mortem() + count += 1 if current != c.path: