def test_empty(self): try: do_work(parser, []) self.fail() pass except SystemExit as e: self.assertEqual(e.code, 1)
def test_compare_correct_output(self): # all test must pass since we are copying reference outputs try: do_work(parser,[ '--root', root, os.path.join(root, 'tests', '03_transport_small_12d', 'flow_implicit.yaml'), '--', '-t', '0.1', '--copy', '--clean' ]) except SystemExit as se: self.assertEqual(se.code, EXIT_OK)
def test_compare_wrong_output_error(self): # all test must fail since test_outputs are empty try: do_work(parser,[ '--root', root, os.path.join(root, 'tests', '03_transport_small_12d', 'flow_implicit.yaml'), '--', '-t', '0.1', '--clean', '--random' ]) except SystemExit as se: self.assertEqual(se.code, EXIT_COMPARE_ERROR)
def test_missing_yaml(self): # test fail if we pass non_existent yaml file try: do_work(parser,[ '--root', root, os.path.join(root, 'tests', '03_transport_small_12d', 'flow_implicit_non_existent.yaml'), os.path.join(root, 'tests', '03_transport_small_12d', 'flow_implicit.yaml'), '--', '-t', '0.01', '--copy', '--clean' ]) except SystemExit as se: self.assertNotEqual(se.code, EXIT_OK)
def parse(command, debug=False): """ :type command: list or str """ arg_options = argparser.Parser.parse_runtest( script.create_parser(), command.split() if type(command) is str else command) return do_work(arg_options, debug)
def test_argument_pass(self): # we test that arguments are passed to flow123d by specifying sleep duration for flow123d_mock scripts # if passing works, duration for this test must be greater than sleep time passed start_time = time.time() sleep_time = 2 try: do_work(parser,[ '--root', root, os.path.join(root, 'tests', '03_transport_small_12d', 'flow_implicit.yaml'), '--', '-t', str(sleep_time), '-e' ]) except SystemExit as se: self.assertNotEqual(se.code, EXIT_OK) end_time = time.time() diff = end_time - start_time self.assertGreater(diff, sleep_time)
def test_config_load(self): config=""" common_config: proc: {common_proc} memory_limit: 1000 test_cases: - files: test-02.yaml proc: {test02_proc} """.strip() # ------------------------------------------------------------------------ common_proc = [1, 2, 3] test02_proc = [1, 2, 3, 4] with open('extras/foo/bar/config.yaml', 'w') as fp: fp.write(config.format(**locals())) # result = do_work(parser, ['extras/foo']) # self.assertEqual(len(common_proc)+len(test02_proc), len(result.threads)) # # result = do_work(parser, ['-p', '7', 'extras']) # self.assertEqual(len(common_proc)+len(test02_proc), len(result.threads)) result = do_work(parser, ['extras/foo/bar/test-01.yaml']) self.assertEqual(len(result.threads), len(common_proc)) result = do_work(parser, ['extras/foo/bar/test-02.yaml']) self.assertEqual(len(result.threads), len(test02_proc)) # ------------------------------------------------------------------------ common_proc = [1] test02_proc = [] with open('extras/foo/bar/config.yaml', 'w') as fp: fp.write(config.format(**locals())) result = do_work(parser, ['extras/foo']) self.assertEqual(len(common_proc)+len(test02_proc), len(result.threads)) result = do_work(parser, ['-p', '2', 'extras/foo/bar']) self.assertEqual(len(common_proc)+len(test02_proc), len(result.threads)) result = do_work(parser, ['extras/foo/bar/test-01.yaml']) self.assertEqual(len(result.threads), len(common_proc)) result = do_work(parser, ['extras/foo/bar/test-02.yaml']) self.assertEqual(len(result.threads), len(test02_proc))
sys.exit(1) from scripts.core.execution import BinExecutor from scripts.runtest_module import do_work # determine batched mode after parsing from scripts.core.base import Printer parser.on_parse += Printer.setup_printer # import os # Paths.init(os.getcwd()) # run work with Timer.app_timer: BinExecutor.register_sigint() returncode = do_work(parser) # collect artifact if not set otherwise # parser.parse() if parser.simple_options.artifacts: if parser.simple_options.artifacts is True: artifact_yml = Paths.artifact_yaml() else: artifact_yml = parser.simple_options.artifacts try: ap = ArtifactProcessor(artifact_yml) ap.run() except Exception as e: # we catch all error coming from artifact system # so it does not affect regular tests
or export them to database. """) argparser.Parser.add(group, '--status-file', action=argparser.Parser.STORE_TRUE, help="""R| If set, will also generate status file in test_results directory. Status file will have name "runtest.status.json" and will contain additional information which cannot be obtained from profiler file """) return parser if __name__ == '__main__': parser = create_parser() arg_options = argparser.Parser.parse_runtest(parser) printf.init_logger(verbosity=arg_options.verbosity, logfile=arg_options.log) # run work with Timer.app_timer: BinExecutor.register_sigint() returncode, debug = do_work(arg_options) # run work if arg_options.death: if returncode == 0: printf.error('Command did exit with 0 but should not (--death flag was set)!') sys.exit(1) else: printf.success('Command did not with 0 (--death flag was set)') sys.exit(0) else: sys.exit(returncode())
parser.add('-m', '--limit-memory', type=float, name='memory_limit', placeholder='<memory>', docs=[ 'Optional memory limit per node in MB', 'For precision use float value' ]) parser.add('', '--root', hidden=True, type=str, name='root', placeholder='<ROOT>', docs=[ 'Path to base dir of flow123d' ]) parser.add('', '--json', hidden=True, type=str, name='json', placeholder='<JSON>', docs=[ 'Output result to json file' ]) # ---------------------------------------------- if __name__ == '__main__': from utils.globals import check_modules required = ('psutil', 'yaml', 'shutil', 'importlib', 'platform') if not check_modules(*required): sys.exit(1) from scripts.core.execution import BinExecutor from scripts.runtest_module import do_work # # # for debug only set dir to where script should be Paths.base_dir(__file__) # run work BinExecutor.register_sigint() do_work(parser) if parser.simple_options.json: GlobalResult.to_json(parser.simple_options.json)
def test_help(self): try: do_work(parser, ['--help']) self.fail() except SystemExit as e: self.assertEqual(e.code, 0)
global_changes = { k: arg_options.get(k) for k in overrides if arg_options.get(k) } if global_changes: Printer.all.out('Detected global resource override:') Printer.all.out(format_dict(global_changes, indent=1)) Printer.all.sep() # import os # Paths.init(os.getcwd()) # run work with Timer.app_timer: BinExecutor.register_sigint() returncode = do_work(arg_options) # run work returncode = returncode.returncode if type( returncode) is not int else returncode if arg_options.death: if returncode == 0: Printer.all.err( 'Command did exit with 0 but should not (--death flag was set)!' ) sys.exit(1) else: Printer.all.suc('Command did not with 0 (--death flag was set)') sys.exit(0) else: