edq.cli.testing.cli-test

Run specified CLI test files.

 1# pylint: disable=invalid-name
 2
 3"""
 4Run specified CLI test files.
 5"""
 6
 7import argparse
 8import sys
 9import unittest
10
11import edq.core.argparser
12import edq.testing.cli
13import edq.testing.unittest
14
15class CLITest(edq.testing.unittest.BaseTest):
16    """ Test CLI invocations. """
17
18def run_cli(args: argparse.Namespace) -> int:
19    """ Run the CLI. """
20
21    edq.testing.cli.add_test_paths(CLITest, args.data_dir, args.paths)
22
23    runner = unittest.TextTestRunner(verbosity = 2)
24    tests = unittest.defaultTestLoader.loadTestsFromTestCase(CLITest)
25    results = runner.run(tests)
26
27    return len(results.errors) + len(results.failures)
28
29def main() -> int:
30    """ Get a parser, parse the args, and call run. """
31    return run_cli(_get_parser().parse_args())
32
33def _get_parser() -> argparse.ArgumentParser:
34    """ Get the parser. """
35
36    parser = edq.core.argparser.get_default_parser(__doc__.strip())
37
38    parser.add_argument('paths', metavar = 'PATH',
39        type = str, nargs = '+',
40        help = 'Path to CLI test case files.')
41
42    parser.add_argument('--data-dir', dest = 'data_dir',
43        action = 'store', type = str, default = '.',
44        help = 'The additional data directory (expansion of __DATA_DIR__) used for tests (default: %(default)s).')
45
46    return parser
47
48if (__name__ == '__main__'):
49    sys.exit(main())
class CLITest(edq.testing.unittest.BaseTest):
16class CLITest(edq.testing.unittest.BaseTest):
17    """ Test CLI invocations. """

Test CLI invocations.

def run_cli(args: argparse.Namespace) -> int:
19def run_cli(args: argparse.Namespace) -> int:
20    """ Run the CLI. """
21
22    edq.testing.cli.add_test_paths(CLITest, args.data_dir, args.paths)
23
24    runner = unittest.TextTestRunner(verbosity = 2)
25    tests = unittest.defaultTestLoader.loadTestsFromTestCase(CLITest)
26    results = runner.run(tests)
27
28    return len(results.errors) + len(results.failures)

Run the CLI.

def main() -> int:
30def main() -> int:
31    """ Get a parser, parse the args, and call run. """
32    return run_cli(_get_parser().parse_args())

Get a parser, parse the args, and call run.