Debian Codegraph @

test/lib/ansible_test/_internal/cli/commands/sanity.py

raw
1 """Command line parsing for the `sanity` command."""
2
3 from __future__ import annotations
4
5 import argparse
6
7 from ...config import (
8 data_context,
9 SanityConfig,
10 )
11
12 from ...commands.sanity import (
13 command_sanity,
14 sanity_get_tests,
15 )
16
17 from ...target import (
18 walk_sanity_targets,
19 )
20
21 from ..environments import (
22 CompositeActionCompletionFinder,
23 ControllerMode,
24 TargetMode,
25 add_environments,
26 )
27
28
29 def do_sanity(
30 subparsers,
31 parent: argparse.ArgumentParser,
32 completer: CompositeActionCompletionFinder,
33 ):
34 """Command line parsing for the `sanity` command."""
35 parser: argparse.ArgumentParser = subparsers.add_parser(
36 'sanity',
37 parents=[parent],
38 help='sanity tests',
39 )
40
41 parser.set_defaults(
42 func=command_sanity,
43 targets_func=walk_sanity_targets,
44 config=SanityConfig,
45 )
46
47 sanity = parser.add_argument_group(title='sanity test arguments')
48
49 sanity.add_argument(
50 '--test',
51 metavar='TEST',
52 action='append',
53 choices=[test.name for test in sanity_get_tests()],
54 help='tests to run',
55 )
56
57 sanity.add_argument(
58 '--skip-test',
59 metavar='TEST',
60 action='append',
61 choices=[test.name for test in sanity_get_tests()],
62 help='tests to skip',
63 )
64
65 sanity.add_argument(
66 '--allow-disabled',
67 action='store_true',
68 help='allow tests to run which are disabled by default',
69 )
70
71 sanity.add_argument(
72 '--list-tests',
73 action='store_true',
74 help='list available tests',
75 )
76
77 sanity.add_argument(
78 '--enable-optional-errors',
79 action='store_true',
80 help='enable optional errors',
81 )
82
83 sanity.add_argument(
84 '--lint',
85 action='store_true',
86 help='write lint output to stdout, everything else stderr',
87 )
88
89 sanity.add_argument(
90 '--junit',
91 action='store_true',
92 help='write test failures to junit xml files',
93 )
94
95 sanity.add_argument(
96 '--failure-ok',
97 action='store_true',
98 help='exit successfully on failed tests after saving results',
99 )
100
101 sanity.add_argument(
102 '--prime-venvs',
103 action='store_true',
104 help='prepare virtual environments without running tests',
105 )
106
107 if data_context().content.is_ansible:
108 sanity.add_argument(
109 '--fix',
110 action='store_true',
111 help='fix issues when possible instead of reporting them',
112 )
113
114 add_environments(parser, completer, ControllerMode.DELEGATED, TargetMode.SANITY) # sanity