|
| 1 | +import logging |
| 2 | +import argparse |
| 3 | +import os |
| 4 | +import shutil |
| 5 | +from pydoc import locate |
| 6 | + |
| 7 | +action_options = { |
| 8 | + "run": "execute the test cases that previously did not pass.", |
| 9 | + "rerun": "ignore the status from previous runs, and rerun the tests.", |
| 10 | + "continue": "continue running, ignoring tests that have either passed or failed", |
| 11 | + "list": "list the test cases.", |
| 12 | + "commands": "display the command line of each test step.", |
| 13 | + "reset": "Removes Failed status from any test case.", |
| 14 | + "clean": "remove files generated by the test cases.", |
| 15 | + "veryclean": "does a clean plus removes non testcase created files (TestLog, results, ...)", |
| 16 | + "check": "skip the action steps and just run the check steps.", |
| 17 | + "rebaseline": "rebaseline the testcases from a previous run.", |
| 18 | + "rebaselinefailed": "rebaseline only failed testcases from a previous run.", |
| 19 | + "report": "generate a text or html report, see config for the reporting options.", |
| 20 | +} |
| 21 | + |
| 22 | +check_options = { |
| 23 | + "all": "run all checks", |
| 24 | + "none": "no additional checking", |
| 25 | + "stopcheck": "check the stop time and stop cycle", |
| 26 | + "curvecheck": "check the ultra curves", |
| 27 | + "restartcheck": "check the restart file", |
| 28 | +} |
| 29 | + |
| 30 | +verbose_options = { |
| 31 | + "debug": "Show detailed log information", |
| 32 | + "info": "Show typical log information", |
| 33 | + "warnings": "Show warnings only", |
| 34 | + "errors": "Show errors only", |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +def build_command_line_parser(): |
| 39 | + parser = argparse.ArgumentParser(description="Runs GEOS integrated tests") |
| 40 | + |
| 41 | + parser.add_argument("geos_bin_dir", type=str, help="GEOS binary directory.") |
| 42 | + |
| 43 | + parser.add_argument("-w", "--workingDir", type=str, help="Initial working directory") |
| 44 | + |
| 45 | + action_names = ','.join(action_options.keys()) |
| 46 | + parser.add_argument("-a", "--action", type=str, default="run", help=f"Test actions options ({action_names})") |
| 47 | + |
| 48 | + check_names = ','.join(check_options.keys()) |
| 49 | + parser.add_argument("-c", "--check", type=str, default="all", help=f"Test check options ({check_names})") |
| 50 | + |
| 51 | + verbosity_names = ','.join(verbose_options.keys()) |
| 52 | + parser.add_argument("-v", "--verbose", type=str, default="info", help=f"Log verbosity options ({verbosity_names})") |
| 53 | + |
| 54 | + parser.add_argument("-d", "--detail", action="store_true", default=False, help="Show detailed action/check options") |
| 55 | + |
| 56 | + parser.add_argument("-i", "--info", action="store_true", default=False, help="Info on various topics") |
| 57 | + |
| 58 | + parser.add_argument("-r", |
| 59 | + "--restartCheckOverrides", |
| 60 | + nargs='+', |
| 61 | + action='append', |
| 62 | + help='Restart check parameter override (name value)', |
| 63 | + default=[]) |
| 64 | + |
| 65 | + parser.add_argument("--salloc", |
| 66 | + default=True, |
| 67 | + help="Used by the chaosM machine to first allocate nodes with salloc, before running the tests") |
| 68 | + |
| 69 | + parser.add_argument( |
| 70 | + "--sallocoptions", |
| 71 | + type=str, |
| 72 | + default="", |
| 73 | + help="Used to override all command-line options for salloc. No other options with be used or added.") |
| 74 | + |
| 75 | + parser.add_argument("--ats", nargs='+', default=[], action="append", help="pass arguments to ats") |
| 76 | + |
| 77 | + parser.add_argument("--machine", default=None, help="name of the machine") |
| 78 | + |
| 79 | + parser.add_argument("--machine-dir", default=None, help="Search path for machine definitions") |
| 80 | + |
| 81 | + parser.add_argument("-l", "--logs", type=str, default=None) |
| 82 | + |
| 83 | + parser.add_argument( |
| 84 | + "--failIfTestsFail", |
| 85 | + action="store_true", |
| 86 | + default=False, |
| 87 | + help="geos_ats normally exits with 0. This will cause it to exit with an error code if there was a failed test." |
| 88 | + ) |
| 89 | + |
| 90 | + parser.add_argument("-n", "-N", "--numNodes", type=int, default="2") |
| 91 | + |
| 92 | + parser.add_argument("ats_targets", type=str, nargs='*', help="ats files or directories.") |
| 93 | + |
| 94 | + return parser |
| 95 | + |
| 96 | + |
| 97 | +def parse_command_line_arguments(args): |
| 98 | + parser = build_command_line_parser() |
| 99 | + options, unkown_args = parser.parse_known_args() |
| 100 | + exit_flag = False |
| 101 | + |
| 102 | + # Check action, check, verbosity items |
| 103 | + check = options.check |
| 104 | + if check not in check_options: |
| 105 | + print( |
| 106 | + f"Selected check option ({check}) not recognized. Try running with --help/--details for more information") |
| 107 | + exit_flag = True |
| 108 | + |
| 109 | + action = options.action |
| 110 | + if action not in action_options: |
| 111 | + print( |
| 112 | + f"Selected action option ({action}) not recognized. Try running with --help/--details for more information" |
| 113 | + ) |
| 114 | + exit_flag = True |
| 115 | + |
| 116 | + verbose = options.verbose |
| 117 | + if verbose not in verbose_options: |
| 118 | + print(f"Selected verbose option ({verbose}) not recognized") |
| 119 | + exit_flag = True |
| 120 | + |
| 121 | + # Print detailed information |
| 122 | + if options.detail: |
| 123 | + for option_type, details in zip(['action', 'check'], [action_options, check_options]): |
| 124 | + print(f'\nAvailable {option_type} options:') |
| 125 | + for k, v in details.items(): |
| 126 | + print(f' {k}: {v}') |
| 127 | + exit_flag = True |
| 128 | + |
| 129 | + if exit_flag: |
| 130 | + quit() |
| 131 | + |
| 132 | + return options |
| 133 | + |
| 134 | + |
| 135 | +def patch_parser(parser): |
| 136 | + |
| 137 | + def add_option_patch(*xargs, **kwargs): |
| 138 | + """ |
| 139 | + Convert type string to actual type instance |
| 140 | + """ |
| 141 | + tmp = kwargs.get('type', str) |
| 142 | + type_map = {'string': str} |
| 143 | + if isinstance(tmp, str): |
| 144 | + if tmp in type_map: |
| 145 | + tmp = type_map[tmp] |
| 146 | + else: |
| 147 | + tmp = locate(tmp) |
| 148 | + kwargs['type'] = tmp |
| 149 | + parser.add_argument(*xargs, **kwargs) |
| 150 | + |
| 151 | + parser.add_option = add_option_patch |
0 commit comments