Example #1
0
    def show_test_selection(self):
        """
        Show the currently selected tests in the current project.
        Add or remove tests using the
        add_tests and remove_tests commands respectively.
        """
        ids_list = list(self.test_set)
        tests = []
        for file_object in self.project.get_tests():
            file_name = os.path.basename(file_object.path)
            print(term.yellow(file_name))
            for test_group in file_object.testsuite:
                for testId, test in enumerate(utils.iterate_tests(test_group)):
                    if testId == 0:
                        groupName = str(test.__class__.__name__)
                    testName = test.id().split('.')[-1]
                    tests.append((file_name, groupName, testName, test))

        # Filter out any invalid indices
        ids_list = list(filter(lambda x: x < len(tests), ids_list))
        for idx, (fileName, groupName, testName, test) in enumerate(
            [tests[idx] for idx in ids_list]
        ):
            print(
                '{:<5}'.format(str(ids_list[idx]) + ':') +
                '[' + term.yellow(fileName) + ']' +
                '[' + term.green(groupName) + ']' +
                '[' + term.blue(testName) + ']'
            )
Example #2
0
    def show_test_selection(self):
        """
        Show the currently selected tests in the current project.
        Add or remove tests using the
        add_tests and remove_tests commands respectively.
        """
        ids_list = list(self.test_set)
        tests = []
        for file_object in self.project.get_tests():
            file_name = os.path.basename(file_object.path)
            print(term.yellow(file_name))
            for test_group in file_object.testsuite:
                for testId, test in enumerate(utils.iterate_tests(test_group)):
                    if testId == 0:
                        groupName = str(test.__class__.__name__)
                    testName = test.id().split('.')[-1]
                    tests.append((file_name, groupName, testName, test))

        # Filter out any invalid indices
        ids_list = list(filter(lambda x: x < len(tests), ids_list))
        for idx, (fileName, groupName, testName, test) in enumerate(
            [tests[idx] for idx in ids_list]
        ):
            print(
                '{:<5}'.format(str(ids_list[idx]) + ':') +
                '[' + term.yellow(fileName) + ']' +
                '[' + term.green(groupName) + ']' +
                '[' + term.blue(testName) + ']'
            )
Example #3
0
    def run_tests(self, ids=None, tool_name=None):
        """
        Run the Project unit tests. The *ids* input is an iterable containing
        integer IDs referencing test cases from the test suite. If *ids* is
        None all tests in the test suite will be executed, otherwise the
        *ids* will be used to select which tests in the test suite are run.

        The Simulation tool that is used is determined by the
        *tool_name* input if supplied, otherwise the *Project* configuration
        : 'simulator' tool name will be used instead.
        """
        simulation_tool = self._get_tool(tool_name, tool_type="simulation")
        # First compile the project
        simulation_tool.compile_project(includes=self.options.get_simulator_library_dependencies(simulation_tool.name))

        suite = unittest.TestSuite()
        tests = []

        for file_object in self.get_tests():
            file_name = os.path.basename(file_object.path)
            for test_group in file_object.testsuite:
                for testId, test in enumerate(utils.iterate_tests(test_group)):
                    # Patch in the simulation runtime data
                    test.load_environment(self, tool_name=tool_name)
                    # Add the test to the library
                    tests.append((file_name, test))

        if len(tests) == 0:
            log.warning("No tests available.")
            return

        # Run all tests by default if no IDs are specified
        if ids is None:
            ids = list(range(len(tests)))
        elif len(ids) == 0:
            ids = list(range(len(tests)))

        for id in ids:
            if id < len(tests):
                fileName, test = tests[id]
                log.info(str(test.id()))
                suite.addTest(test)
                log.info("Added " + str(test) + " to testsuite")

        log.info("Running testsuite...")
        # TODO: Allow HTML or Console selection
        if True:
            with open(os.path.join(self.get_simulation_directory(), "report.html"), "w") as report:
                HTMLTestRunner.HTMLTestRunner(verbosity=2, stream=report).run(suite)
        else:
            unittest.TextTestRunner(verbosity=2).run(suite)
        log.info("...done")
Example #4
0
    def do_show_tests(self, command):
        """
        Show the tests available in the current project.
        """
        tests = self.project.get_tests()

        if len(tests) == 0:
            log.info('There are no tests available.')
            return

        testUniqueId = 0
        for file_object in tests:
            file_name = os.path.basename(file_object.path)
            print(term.yellow(file_name))
            for test_group in file_object.testsuite:
                for testId, test in enumerate(utils.iterate_tests(test_group)):
                    if testId == 0:
                        print(
                            SEP + term.green(str(test.__class__.__name__))
                        )
                    doc = test.shortDescription()
                    if doc is None:
                        doc = term.darkred('No description')
                    if testUniqueId in self.test_set:
                        msg = SEP * 2 + '[' + term.blue('ID ' + str(
                            testUniqueId) + ' ' + test.id().split('.')[-1]
                        ) + ']'
                    else:
                        msg = SEP * 2 + term.lightgray('ID ' + str(
                            testUniqueId) + ' ' + test.id().split('.')[-1]
                        )
                    print(msg)
                    print(term.darkgray(textwrap.fill(
                        doc,
                        width=80,
                        initial_indent=SEP * 2,
                        subsequent_indent=SEP * 2,
                    )))
                    testUniqueId += 1
Example #5
0
    def do_show_tests(self, command):
        """
        Show the tests available in the current project.
        """
        tests = self.project.get_tests()

        if len(tests) == 0:
            log.info('There are no tests available.')
            return

        testUniqueId = 0
        for file_object in tests:
            file_name = os.path.basename(file_object.path)
            print(term.yellow(file_name))
            for test_group in file_object.testsuite:
                for testId, test in enumerate(utils.iterate_tests(test_group)):
                    if testId == 0:
                        print(
                            SEP + term.green(str(test.__class__.__name__))
                        )
                    doc = test.shortDescription()
                    if doc is None:
                        doc = term.darkred('No description')
                    if testUniqueId in self.test_set:
                        msg = SEP * 2 + '[' + term.blue('ID ' + str(
                            testUniqueId) + ' ' + test.id().split('.')[-1]
                        ) + ']'
                    else:
                        msg = SEP * 2 + term.lightgray('ID ' + str(
                            testUniqueId) + ' ' + test.id().split('.')[-1]
                        )
                    print(msg)
                    print(term.darkgray(textwrap.fill(
                        doc,
                        width=80,
                        initial_indent=SEP * 2,
                        subsequent_indent=SEP * 2,
                    )))
                    testUniqueId += 1
Example #6
0
    def run_tests(self, ids=None, tool_name=None):
        """
        Run the Project unit tests. The *ids* input is an iterable containing
        integer IDs referencing test cases from the test suite. If *ids* is
        None all tests in the test suite will be executed, otherwise the
        *ids* will be used to select which tests in the test suite are run.

        The Simulation tool that is used is determined by the
        *tool_name* input if supplied, otherwise the *Project* configuration
        : 'simulator' tool name will be used instead.
        """
        simulation_tool = self._get_tool(tool_name, tool_type='simulation')
        # First compile the project
        simulation_tool.compile_project(
            includes=self.options.get_simulator_library_dependencies(
                simulation_tool.name
            )
        )

        suite = unittest.TestSuite()
        tests = []

        for file_object in self.get_tests():
            file_name = os.path.basename(file_object.path)
            for test_group in file_object.testsuite:
                for testId, test in enumerate(utils.iterate_tests(test_group)):
                    # Patch in the simulation runtime data
                    test.load_environment(self, tool_name=tool_name)
                    # Add the test to the library
                    tests.append((file_name, test))

        if len(tests) == 0:
            log.warning('No tests available.')
            return

        # Run all tests by default if no IDs are specified
        if ids is None:
            ids = list(range(len(tests)))
        elif len(ids) == 0:
            ids = list(range(len(tests)))

        for id in ids:
            if id < len(tests):
                fileName, test = tests[id]
                log.info(
                    str(test.id())
                )
                suite.addTest(test)
                log.info('Added ' + str(test) + ' to testsuite')

        log.info('Running testsuite...')
        # TODO: Allow HTML or Console selection
        if True:
            with open(
                os.path.join(
                    self.get_simulation_directory(), 'report.html'
                ), 'w'
            ) as report:
                HTMLTestRunner.HTMLTestRunner(
                    verbosity=2,
                    stream=report
                ).run(suite)
        else:
            unittest.TextTestRunner(verbosity=2).run(suite)
        log.info('...done')
Example #7
0
    def run_tests(self, ids=None, tool_name=None):
        """
        Run the Project unit tests. The *ids* input is an iterable containing
        integer IDs referencing test cases from the test suite. If *ids* is
        None all tests in the test suite will be executed, otherwise the
        *ids* will be used to select which tests in the test suite are run.

        The Simulation tool that is used is determined by the
        *tool_name* input if supplied, otherwise the *Project* configuration
        : 'simulator' tool name will be used instead.
        """
        simulation_tool = self._get_tool(tool_name, tool_type='simulation')
        # First compile the project
        try:
            simulation_tool.compile_project(
                includes=self.options.get_simulator_library_dependencies(
                    simulation_tool.name
                )
            )
        except:
            log.error(traceback.format_exc())
            log.error("Compilation aborted due to previous error")
            return

        suite = unittest.TestSuite()
        tests = []

        for file_object in self.get_tests():
            file_name = os.path.basename(file_object.path)
            for test_group in file_object.testsuite:
                for testId, test in enumerate(utils.iterate_tests(test_group)):
                    # Patch in the simulation runtime data
                    test.postImport(
                        self.options.get_simulator_library_dependencies(
                            simulation_tool.name
                        ),
                        self.get_simulation_directory(),
                        simulation_tool,
                    )
                    # Add the test to the library
                    tests.append((file_name, test))

        if len(tests) == 0:
            log.warning('No tests available.')
            return

        # Run all tests by default if no IDs are specified
        if ids is None:
            ids = list(range(len(tests)))
        elif len(ids) == 0:
            ids = list(range(len(tests)))

        for id in ids:
            if id < len(tests):
                fileName, test = tests[id]
                log.info(
                    str(test.id())
                )
                suite.addTest(test)
                log.info('Added ' + str(test) + ' to testsuite')

        log.info('Running testsuite...')
        try:
            # TODO: Allow HTML or Console selection
            if True:
                with open(
                    os.path.join(
                        self.get_simulation_directory(), 'report.html'
                    ), 'w'
                ) as report:
                    HTMLTestRunner.HTMLTestRunner(
                        verbosity=2,
                        stream=report
                    ).run(suite)
            else:
                unittest.TextTestRunner(verbosity=2).run(suite)
        except Exception:
            log.error('An error was encountered when running the TestSuite')
            log.error(traceback.format_exc())
        log.info('...done')