def run(self, targets: List[ProjectTarget], profile_names: List[str] = []) -> None: """ Runs targets from this project. :param targets: The targets to run. :param profile_names: The profiles for which to run the targets. """ for target in targets: if target.name not in self.executables: G_LOGGER.critical( f"Could not find target: {target.name} in project executables. Note: Available executables are: {list(self.executables.keys())}" ) def run_target(target: ProjectTarget, prof_name: str): G_LOGGER.log( f"\nRunning target: {target}, for profile: {prof_name}", colors=[Color.BOLD, Color.GREEN]) status = self._run_linked_node(target[prof_name]) if status.returncode: G_LOGGER.critical( f"Failed to run. Reconfiguring the project or running a clean build may resolve this." ) for prof_name in profile_names: G_LOGGER.log(f"\n{utils.wrap_str(f' Profile: {prof_name} ')}", colors=[Color.BOLD, Color.GREEN]) for target in targets: run_target(target, prof_name)
def run_target(target: ProjectTarget, prof_name: str): G_LOGGER.log( f"\nRunning target: {target}, for profile: {prof_name}", colors=[Color.BOLD, Color.GREEN]) status = self._run_linked_node(target[prof_name]) if status.returncode: G_LOGGER.critical( f"Failed to run. Reconfiguring the project or running a clean build may resolve this." )
def _run_linked_node(self, node: LinkedNode, *args, **kwargs) -> subprocess.CompletedProcess: loader_path = os.environ.get(paths.loader_path_env_var(), "") G_LOGGER.verbose(f"Running linked node: {node}") for lib_dir in node.lib_dirs: loader_path += f"{os.path.pathsep}{lib_dir}" G_LOGGER.debug(f"Using loader paths: {loader_path}") G_LOGGER.log( f"{paths.loader_path_env_var()}={loader_path} {node.path}\n", colors=[Color.BOLD, Color.GREEN]) env = copy.copy(os.environ) env[paths.loader_path_env_var()] = loader_path return subprocess.run([node.path], *args, env=env, **kwargs)
def run_test(test, prof_name): G_LOGGER.log(f"\nRunning test: {test}, for profile: {prof_name}", colors=[Color.BOLD, Color.GREEN]) status = self._run_linked_node(test[prof_name]) if status.returncode: G_LOGGER.log( f"\nFAILED {test}, for profile: {prof_name}:\n{test[prof_name].path}", colors=[Color.BOLD, Color.RED], ) test_results[prof_name].failed += 1 failed_targets[prof_name].add(test[prof_name].name) else: G_LOGGER.log(f"\nPASSED {test}", colors=[Color.BOLD, Color.GREEN]) test_results[prof_name].passed += 1
def run_tests(self, targets: List[ProjectTarget] = None, profile_names: List[str] = None): """ Run tests from this project. Runs all tests from the project for all profiles by default. :param targets: The test targets to run. Raises an exception if the target is not a test target. :param profile_names: The profiles for which to run the tests. Defaults to all profiles. """ for target in targets: if target.name not in self.tests: G_LOGGER.critical( f"Could not find test: {target.name} in project.\n\tAvailable tests:\n\t\t{list(self.tests.keys())}" ) tests = utils.default_value(targets, self.test_targets()) profile_names = utils.default_value(profile_names, self.all_profile_names()) if not tests: G_LOGGER.warning( f"No tests found. Have you registered tests using project.test()?" ) return class TestResult: def __init__(self): self.failed = 0 self.passed = 0 def run_test(test, prof_name): G_LOGGER.log(f"\nRunning test: {test}, for profile: {prof_name}", colors=[Color.BOLD, Color.GREEN]) status = self._run_linked_node(test[prof_name]) if status.returncode: G_LOGGER.log( f"\nFAILED {test}, for profile: {prof_name}:\n{test[prof_name].path}", colors=[Color.BOLD, Color.RED], ) test_results[prof_name].failed += 1 failed_targets[prof_name].add(test[prof_name].name) else: G_LOGGER.log(f"\nPASSED {test}", colors=[Color.BOLD, Color.GREEN]) test_results[prof_name].passed += 1 test_results = defaultdict(TestResult) failed_targets = defaultdict(set) for prof_name in profile_names: G_LOGGER.log(f"\n{utils.wrap_str(f' Profile: {prof_name} ')}", colors=[Color.BOLD, Color.GREEN]) for test in tests: run_test(test, prof_name) # Display summary G_LOGGER.log(f"\n{utils.wrap_str(f' Test Results Summary ')}\n", colors=[Color.BOLD, Color.GREEN]) for prof_name, result in test_results.items(): if result.passed or result.failed: G_LOGGER.log(f"Profile: {prof_name}", colors=[Color.BOLD, Color.GREEN]) if result.passed: G_LOGGER.log(f"\tPASSED {plural('test', result.passed)}", colors=[Color.BOLD, Color.GREEN]) if result.failed: G_LOGGER.log( f"\tFAILED {plural('test', result.failed)}: {failed_targets[prof_name]}", colors=[Color.BOLD, Color.RED], )