From a1201252e28149272ed674f830ca30bd209980a0 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 18 Jan 2016 15:43:57 -0700 Subject: [PATCH] artiq/test/{not,harness}.py: usual CLI handling --- artiq/test/harness.py | 36 ++++++++++++++++++++---------------- artiq/test/not.py | 7 ++++++- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/artiq/test/harness.py b/artiq/test/harness.py index 955394c3b..cf3a0fd10 100644 --- a/artiq/test/harness.py +++ b/artiq/test/harness.py @@ -11,21 +11,25 @@ emulate the same behavior when invoked under lit. import sys, os, argparse, importlib -parser = argparse.ArgumentParser(description=__doc__) -parser.add_argument('-m', metavar='mod', type=str, - help='run library module as a script') -parser.add_argument('args', type=str, nargs='+', - help='arguments passed to program in sys.argv[1:]') -args = parser.parse_args(sys.argv[1:]) +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('-m', metavar='mod', type=str, + help='run library module as a script') + parser.add_argument('args', type=str, nargs='+', + help='arguments passed to program in sys.argv[1:]') + args = parser.parse_args(sys.argv[1:]) -artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) -sys.path.insert(1, artiq_path) + artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + sys.path.insert(1, artiq_path) -if args.m: - sys.argv[1:] = args.args - importlib.import_module(args.m).main() -else: - sys.argv[1:] = args.args[1:] - with open(args.args[0]) as f: - code = compile(f.read(), args.args[0], 'exec') - exec(code) + if args.m: + sys.argv[1:] = args.args + importlib.import_module(args.m).main() + else: + sys.argv[1:] = args.args[1:] + with open(args.args[0]) as f: + code = compile(f.read(), args.args[0], 'exec') + exec(code) + +if __name__ == "__main__": + main() diff --git a/artiq/test/not.py b/artiq/test/not.py index 8c0421623..855a36416 100644 --- a/artiq/test/not.py +++ b/artiq/test/not.py @@ -1,2 +1,7 @@ import sys, subprocess -exit(not subprocess.call(sys.argv[1:])) + +def main(): + exit(not subprocess.call(sys.argv[1:])) + +if __name__ == "__main__": + main()