diff options
author | Thomi Richards <thomi.richards@canonical.com> | 2013-11-18 15:27:08 +1300 |
---|---|---|
committer | Thomi Richards <thomi.richards@canonical.com> | 2013-11-18 15:27:08 +1300 |
commit | 17743eb0a1dfa1f2bb0b3eafa2431419dd19ded4 (patch) | |
tree | 06a32fa2198b4f68c23dcc5c422a9f054d492d80 /python/subunit/_output.py | |
parent | 980ddea6ac3ca2f2d5cef72a739a95ae6d753bc2 (diff) | |
download | subunit-git-17743eb0a1dfa1f2bb0b3eafa2431419dd19ded4.tar.gz |
First pass, missing some tests.
Diffstat (limited to 'python/subunit/_output.py')
-rw-r--r-- | python/subunit/_output.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/python/subunit/_output.py b/python/subunit/_output.py index 66093bb..e513639 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -13,6 +13,63 @@ # license you chose for the specific language governing permissions and # limitations under that license. +from argparse import ArgumentParser +from sys import stdout + +from subunit.v2 import StreamResultToBytes def output_main(): + args = parse_arguments() + output = get_output_stream_writer() + generate_bytestream(args, output) + return 0 + + +def parse_arguments(args=None): + """Parse arguments from the command line. + + If specified, args must be a list of strings, similar to sys.argv[1:]. + + """ + parser = ArgumentParser( + prog='subunit-output', + description="A tool to generate a subunit result byte-stream", + ) + sub_parsers = parser.add_subparsers(dest="action") + + parser_start = sub_parsers.add_parser("start", help="Start a test.") + parser_start.add_argument("test_id", help="The test id you want to start.") + + parser_pass = sub_parsers.add_parser("pass", help="Pass a test.") + parser_pass.add_argument("test_id", help="The test id you want to pass.") + + parser_fail = sub_parsers.add_parser("fail", help="Fail a test.") + parser_fail.add_argument("test_id", help="The test id you want to fail.") + + parser_skip = sub_parsers.add_parser("skip", help="Skip a test.") + parser_skip.add_argument("test_id", help="The test id you want to skip.") + + return parser.parse_args(args) + + +def translate_command_name(command_name): + """Turn the friendly command names we show users on the command line into + something subunit understands. + + """ + return { + 'start': 'inprogress', + 'pass': 'success', + }.get(command_name, command_name) + + +def get_output_stream_writer(): + return StreamResultToBytes(stdout) + + +def generate_bytestream(args, output_writer): + output_writer.status( + test_id=args.test_id, + test_status=translate_command_name(args.action) + ) |