homework_checker/core/tasks.py
def check(self: Task) -> Task.ResultDictType:
        """Iterate over the tests and check them."""
        # Generate empty results.
        results: Task.ResultDictType = {}

        def run_all_tests(
            test_node: dict, executable_folder: Path
        ) -> Task.ResultDictType:
            """Run all tests in the task."""
            results: Task.ResultDictType = {}
            if Tags.INJECT_FOLDER_TAG not in test_node:
                # There is no need to rebuild the code. We can just run our tests.
                test_result = self._run_test(test_node, executable_folder)
                results[
                    self.__with_number_prefix(test_node[Tags.NAME_TAG])
                ] = test_result
                return results
            # There are folders to inject, so we will have to rebuild with the newly
            # injected folders. We do it in a new temp folder.
            with tools.TempDirCopy(
                source_folder=self._student_task_folder, prefix="build_injected"
            ) as code_folder:
                folders_to_inject = self.__get_folders_to_inject(
                    node=test_node, destination_root=code_folder
                )
                Task.__inject_folders(folders_to_inject)
                build_result, build_folder = self._build_if_needed(code_folder)
                if build_result and not build_result.succeeded():
                    raise Exception("Build with inserted folders must ALWAYS succeed!")
                test_result = self._run_test(
                    test_node=test_node, executable_folder=build_folder
                )
                results[
                    self.__with_number_prefix(test_node[Tags.NAME_TAG])
                ] = test_result
            return results

        with tools.TempDirCopy(self._student_task_folder) as code_folder:
            # Build the source if this is needed.
            build_result, build_folder = self._build_if_needed(code_folder)
            if build_result:
                results[self.__with_number_prefix(BUILD_SUCCESS_TAG)] = build_result
                if not build_result.succeeded():
                    # The build has failed, so no further testing needed.
                    return results
            # The build is either not needed or succeeded. Continue testing.
            for test_node in self._test_nodes:
                results.update(
                    run_all_tests(test_node=test_node, executable_folder=build_folder)
                )

        style_errors = self._code_style_errors()
        if style_errors:
            results[STYLE_ERROR_TAG] = style_errors
        return results
Iterate over the tests and check them.
Iterate over the tests and check them.
Iterate over the tests and check them .
def check(self: Task) -> Task.ResultDictType:
        results: Task.ResultDictType = {}
        def run_all_tests(
            test_node: dict, executable_folder: Path
        ) -> Task.ResultDictType:
            results: Task.ResultDictType = {}
            if Tags.INJECT_FOLDER_TAG not in test_node:
                test_result = self._run_test(test_node, executable_folder)
                results[
                    self.__with_number_prefix(test_node[Tags.NAME_TAG])
                ] = test_result
                return results
            with tools.TempDirCopy(
                source_folder=self._student_task_folder, prefix="build_injected"
            ) as code_folder:
                folders_to_inject = self.__get_folders_to_inject(
                    node=test_node, destination_root=code_folder
                )
                Task.__inject_folders(folders_to_inject)
                build_result, build_folder = self._build_if_needed(code_folder)
                if build_result and not build_result.succeeded():
                    raise Exception("Build with inserted folders must ALWAYS succeed!")
                test_result = self._run_test(
                    test_node=test_node, executable_folder=build_folder
                )
                results[
                    self.__with_number_prefix(test_node[Tags.NAME_TAG])
                ] = test_result
            return results
        with tools.TempDirCopy(self._student_task_folder) as code_folder:
            build_result, build_folder = self._build_if_needed(code_folder)
            if build_result:
                results[self.__with_number_prefix(BUILD_SUCCESS_TAG)] = build_result
                if not build_result.succeeded():
                    return results
            for test_node in self._test_nodes:
                results.update(
                    run_all_tests(test_node=test_node, executable_folder=build_folder)
                )
        style_errors = self._code_style_errors()
        if style_errors:
            results[STYLE_ERROR_TAG] = style_errors
        return results
def check ( self : Task ) -> Task . ResultDictType : results : Task . ResultDictType = { } def run_all_tests ( test_node : dict , executable_folder : Path ) -> Task . ResultDictType : """Run all tests in the task.""" results : Task . ResultDictType = { } if Tags . INJECT_FOLDER_TAG not in test_node : test_result = self . _run_test ( test_node , executable_folder ) results [ self . __with_number_prefix ( test_node [ Tags . NAME_TAG ] ) ] = test_result return results with tools . TempDirCopy ( source_folder = self . _student_task_folder , prefix = "build_injected" ) as code_folder : folders_to_inject = self . __get_folders_to_inject ( node = test_node , destination_root = code_folder ) Task . __inject_folders ( folders_to_inject ) build_result , build_folder = self . _build_if_needed ( code_folder ) if build_result and not build_result . succeeded ( ) : raise Exception ( "Build with inserted folders must ALWAYS succeed!" ) test_result = self . _run_test ( test_node = test_node , executable_folder = build_folder ) results [ self . __with_number_prefix ( test_node [ Tags . NAME_TAG ] ) ] = test_result return results with tools . TempDirCopy ( self . _student_task_folder ) as code_folder : build_result , build_folder = self . _build_if_needed ( code_folder ) if build_result : results [ self . __with_number_prefix ( BUILD_SUCCESS_TAG ) ] = build_result if not build_result . succeeded ( ) : return results for test_node in self . _test_nodes : results . update ( run_all_tests ( test_node = test_node , executable_folder = build_folder ) ) style_errors = self . _code_style_errors ( ) if style_errors : results [ STYLE_ERROR_TAG ] = style_errors return results
Iterate over the tests and check them.
Iterate over the tests and check them .
"""Iterate over the tests and check them.""" # Generate empty results. """Run all tests in the task.""" # There is no need to rebuild the code. We can just run our tests. # There are folders to inject, so we will have to rebuild with the newly # injected folders. We do it in a new temp folder. # Build the source if this is needed. # The build has failed, so no further testing needed. # The build is either not needed or succeeded. Continue testing.
self
Task