def main(): parser = argparse.ArgumentParser( description="Runs all tests for the tutorials") parser.add_argument('--verbose', action='store_true', help="Output everything including debug info") parser.add_argument('--quiet', action='store_true', help="Suppress output except for junit xml") parser.add_argument('--timeout', type=int, default=DEFAULT_TIMEOUT) parser.add_argument('--config', type=str, choices=common.ALL_CONFIGS) parser.add_argument('--app', type=str, choices=common.ALL_TUTORIALS) args = parser.parse_args() common.setup_logger(__name__) common.set_log_level(args.verbose, args.quiet) # Generate all the tests (restricted by app and config) tests = [] for tutorial in common.ALL_TUTORIALS: for config in common.TUTORIALS[tutorial]: if (args.app is None or args.app == tutorial) and \ (args.config is None or args.config == config): tests = tests + [(config, tutorial)] run_tests(tests, args.timeout) return 0
def main(): parser = argparse.ArgumentParser( description="Initialize a build directory for completing a tutorial. Invoke from " "an empty sub directory, or the tutorials directory, in which case a " "new build directory will be created for you.") parser.add_argument('--verbose', action='store_true', help="Output everything including debug info", default=False) parser.add_argument('--quiet', action='store_true', help="Suppress output except for tutorial completion information", default=True) parser.add_argument('--plat', type=str, choices=common.ALL_CONFIGS, required=True) parser.add_argument('--tut', type=str, choices=common.ALL_TUTORIALS, required=True) parser.add_argument('--solution', action='store_true', help="Generate pre-made solutions", default=False) args = parser.parse_args() common.setup_logger(__name__) common.set_log_level(args.verbose, True) # Additional config/tutorial combination validation if args.plat not in common.TUTORIALS[args.tut]: logging.error("Tutorial %s not supported by platform %s. Valid platforms are %s: ", args.tut, args.plat, common.TUTORIALS[args.tut]) return -1 # Check that the current working directory is empty. If not create a suitably # named build directory and switch to it if len(os.listdir(os.getcwd())) != 0: # Check that we are in the tutorial root directory before we decide to start # Making new directories if not os.access(os.getcwd() + "/init", os.X_OK): logging.error("Current dir %s is invalid" % os.getcwd()) parser.print_help(sys.stderr) return -1 build_dir = tempfile.mkdtemp(dir=os.getcwd(), prefix=('build_%s_%s' % (args.plat, args.tut))) os.chdir(build_dir) else: build_dir = None # Check that our parent directory is an expected tutorial root directory if not os.access(os.getcwd() + "/../init", os.X_OK): logging.error("Parent directory is not tutorials root directory") return -1 # Initialize cmake. Output will be supressed as it defaults to the background result = common.init_build_directory(args.plat, args.tut, args.solution, os.getcwd()) if result.exit_code != 0: logging.error("Failed to initialize build directory.") return -1 # Run cmake again but show the tutorial information (to do this we run it in the foreground) sh.cmake(['-DTUTORIALS_PRINT_INSTRUCTIONS=TRUE', '..'], _fg=True) # Run again in the background but turn of printing sh.cmake(['-DTUTORIALS_PRINT_INSTRUCTIONS=FALSE', '..']) # Inform the user about any subdirectory we might have made if build_dir is not None: print("Tutorials created in subdirectory \"%s\". Switch to this directory and follow the instructions above to complete." % os.path.basename(build_dir)) return 0
def main(log_level="info", meta_model_name="power-daps/python3", actions_to_run=["default"]): common.set_log_level(log_level) meta_model = MetaModel(meta_model_name) common.set_meta_model(meta_model_name) valid_actions = meta_model.actions() common.print_verbose('Actions to run ' + str(actions_to_run)) common.print_verbose('Valid actions ' + str([va.name for va in valid_actions])) for action_to_run in actions_to_run: if action_to_run not in [va.name for va in valid_actions]: common.print_error("Action '" + action_to_run + "' not found.") continue for valid_action in valid_actions: if valid_action.name == action_to_run: common.stop_if_failed(*valid_action.run())
def main(): parser = argparse.ArgumentParser( description= "Initialize a build directory for completing a tutorial. Invoke from " "an empty sub directory, or the tutorials directory, in which case a " "new build directory will be created for you.") parser.add_argument('--verbose', action='store_true', help="Output everything including debug info", default=False) parser.add_argument( '--quiet', action='store_true', help="Suppress output except for tutorial completion information", default=True) parser.add_argument('--plat', type=str, choices=common.ALL_CONFIGS) parser.add_argument('--tut', type=str, choices=common.ALL_TUTORIALS, required=True) parser.add_argument('--solution', action='store_true', help="Generate pre-made solutions", default=False) parser.add_argument('--task', help="Generate pre-made solutions") parser.add_argument('tutedir', nargs='?', default=os.getcwd()) args = parser.parse_args() common.setup_logger(__name__) common.set_log_level(args.verbose, True) # Additional config/tutorial combination validation if not args.plat: # just pick the first platform that works for this tutorial args.plat = list(common.TUTORIALS[args.tut])[0] if args.plat not in common.TUTORIALS[args.tut]: logging.error( "Tutorial %s not supported by platform %s. Valid platforms are %s: ", args.tut, args.plat, common.TUTORIALS[args.tut]) return -1 # Check that the current working directory is empty. If not create a suitably # named build directory and switch to it dir_contents = os.listdir(args.tutedir) initialised = False if ".tute_config" in dir_contents: initialised = True if len(dir_contents) != 0 and ".tute_config" not in dir_contents: # Check that we are in the tutorial root directory before we decide to start # Making new directories if not os.access(os.getcwd() + "/init", os.X_OK): logging.error("Current dir %s is invalid" % os.getcwd()) parser.print_help(sys.stderr) return -1 tute_dir = os.path.join(os.getcwd(), args.tut) if os.path.exists(tute_dir): tute_dir = tempfile.mkdtemp(dir=os.getcwd(), prefix=('%s' % (args.tut))) else: os.mkdir(tute_dir) os.chdir(tute_dir) else: tute_dir = args.tutedir # Check that our parent directory is an expected tutorial root directory if not os.access(os.getcwd() + "/../init", os.X_OK): logging.error("Parent directory is not tutorials root directory") return -1 # Initialize cmake. Output will be supressed as it defaults to the background build_dir = "%s_build" % tute_dir if not initialised: os.mkdir(build_dir) result = common.init_directories(args.plat, args.tut, args.solution, args.task, initialised, tute_dir, build_dir, sys.stdout) if result.exit_code != 0: logging.error("Failed to initialize build directory.") return -1 # Inform the user about any subdirectory we might have made print("Tutorials created in subdirectory \"%s\"." % os.path.basename(tute_dir)) print("Build directory initialised in \"%s\"." % os.path.basename(build_dir)) return 0
def test_print_info(self): common.set_log_level("info") common.print_raw = MagicMock() s = 'hello world' common.print_info(s) common.print_raw.assert_called_with('INFO: hello world')