diff options
Diffstat (limited to 'meta/lib/patchtest/patchtest_parser.py')
-rw-r--r-- | meta/lib/patchtest/patchtest_parser.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/meta/lib/patchtest/patchtest_parser.py b/meta/lib/patchtest/patchtest_parser.py new file mode 100644 index 0000000000..2a11cb76c2 --- /dev/null +++ b/meta/lib/patchtest/patchtest_parser.py | |||
@@ -0,0 +1,78 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | # | ||
4 | # patchtestdata: module used to share command line arguments between | ||
5 | # patchtest & test suite and a data store between test cases | ||
6 | # | ||
7 | # Copyright (C) 2016 Intel Corporation | ||
8 | # | ||
9 | # SPDX-License-Identifier: GPL-2.0-only | ||
10 | # | ||
11 | # NOTE: Strictly speaking, unit test should be isolated from outside, | ||
12 | # but patchtest test suites uses command line input data and | ||
13 | # pretest and test test cases may use the datastore defined | ||
14 | # on this module | ||
15 | |||
16 | import os | ||
17 | import argparse | ||
18 | |||
19 | default_testdir = os.path.abspath(os.path.dirname(__file__) + "/tests") | ||
20 | default_repodir = os.path.abspath(os.path.dirname(__file__) + "/../../..") | ||
21 | |||
22 | class PatchtestParser(object): | ||
23 | """Abstract the patchtest argument parser""" | ||
24 | |||
25 | @classmethod | ||
26 | def set_namespace(cls): | ||
27 | parser = cls.get_parser() | ||
28 | parser.parse_args(namespace=cls) | ||
29 | |||
30 | @classmethod | ||
31 | def get_parser(cls): | ||
32 | parser = argparse.ArgumentParser() | ||
33 | |||
34 | target_patch_group = parser.add_mutually_exclusive_group(required=True) | ||
35 | |||
36 | target_patch_group.add_argument('--patch', metavar='PATCH', dest='patch_path', | ||
37 | help='The patch to be tested') | ||
38 | |||
39 | target_patch_group.add_argument('--directory', metavar='DIRECTORY', dest='patch_path', | ||
40 | help='The directory containing patches to be tested') | ||
41 | |||
42 | parser.add_argument('--repodir', metavar='REPO', | ||
43 | default=default_repodir, | ||
44 | help="Name of the repository where patch is merged") | ||
45 | |||
46 | parser.add_argument('--testdir', metavar='TESTDIR', | ||
47 | default=default_testdir, | ||
48 | help="Directory where test cases are located") | ||
49 | |||
50 | parser.add_argument('--top-level-directory', '-t', | ||
51 | dest='topdir', | ||
52 | default=None, | ||
53 | help="Top level directory of project (defaults to start directory)") | ||
54 | |||
55 | parser.add_argument('--pattern', '-p', | ||
56 | dest='pattern', | ||
57 | default='test*.py', | ||
58 | help="Pattern to match test files") | ||
59 | |||
60 | parser.add_argument('--base-branch', '-b', | ||
61 | dest='basebranch', | ||
62 | help="Branch name used by patchtest to branch from. By default, it uses the current one.") | ||
63 | |||
64 | parser.add_argument('--base-commit', '-c', | ||
65 | dest='basecommit', | ||
66 | help="Commit ID used by patchtest to branch from. By default, it uses HEAD.") | ||
67 | |||
68 | parser.add_argument('--debug', '-d', | ||
69 | action='store_true', | ||
70 | help='Enable debug output') | ||
71 | |||
72 | parser.add_argument('--log-results', | ||
73 | action='store_true', | ||
74 | help='Enable logging to a file matching the target patch name with ".testresult" appended') | ||
75 | |||
76 | |||
77 | return parser | ||
78 | |||