1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#!/usr/bin/env python3
#
# test case management tool - store test result, report test result summary,
# & manual test execution
#
# As part of the initiative to provide LITE version Test Case Management System
# with command-line to replace Testopia.
# test-case-mgmt script was designed as part of the helper script for below purpose:
# 1. To store test result inside git repository
# 2. To report text-based test result summary
# 3. To execute manual test cases
#
# To look for help information.
# $ test-case-mgmt
#
# To store test result, execute the below
# $ test-case-mgmt store <source_dir> <git_branch>
#
# To report test result summary, execute the below
# $ test-case-mgmt report <git_branch>
#
# To execute manual test cases, execute the below
# $ test-case-mgmt manualexecution <manualjsonfile>
#
# By default testresults.json for manualexecution store in <build_dir>/tmp/log/manual/
#
#
# Copyright (c) 2018, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
import os
import sys
import argparse
import logging
script_path = os.path.dirname(os.path.realpath(__file__))
lib_path = script_path + '/lib'
sys.path = sys.path + [lib_path]
import argparse_oe
import scriptutils
import testcasemgmt.store
import testcasemgmt.report
import testcasemgmt.manualexecution
logger = scriptutils.logger_create('test-case-mgmt')
def _validate_user_input_arguments(args):
if hasattr(args, "source_dir"):
if not os.path.isdir(args.source_dir):
logger.error('source_dir argument need to be a directory : %s' % args.source_dir)
return False
if hasattr(args, "git_sub_dir"):
if '/' in args.git_sub_dir:
logger.error('git_sub_dir argument cannot contain / : %s' % args.git_sub_dir)
return False
if '\\' in r"%r" % args.git_sub_dir:
logger.error('git_sub_dir argument cannot contain \\ : %r' % args.git_sub_dir)
return False
return True
def _set_default_arg_value(args):
if hasattr(args, "git_dir"):
if args.git_dir == '':
base_path = script_path + '/..'
args.git_dir = os.path.join(os.path.abspath(base_path), 'testresults')
logger.debug('Set git_dir argument: %s' % args.git_dir)
def main():
parser = argparse_oe.ArgumentParser(description="OpenEmbedded test case management tool.",
epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
parser.add_argument('-d', '--debug', help='enable debug output', action='store_true')
parser.add_argument('-q', '--quiet', help='print only errors', action='store_true')
subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>')
subparsers.required = True
subparsers.add_subparser_group('manualexecution', 'execute manual test cases', 300)
testcasemgmt.manualexecution.register_commands(subparsers)
subparsers.add_subparser_group('store', 'store test result', 200)
testcasemgmt.store.register_commands(subparsers)
subparsers.add_subparser_group('report', 'report test result summary', 100)
testcasemgmt.report.register_commands(subparsers)
args = parser.parse_args()
if args.debug:
logger.setLevel(logging.DEBUG)
elif args.quiet:
logger.setLevel(logging.ERROR)
if not _validate_user_input_arguments(args):
return -1
_set_default_arg_value(args)
try:
ret = args.func(args, logger)
except argparse_oe.ArgumentUsageError as ae:
parser.error_subcommand(ae.message, ae.subcommand)
return ret
if __name__ == "__main__":
sys.exit(main())
|