Exemplo n.º 1
0
    def all_tests(self, key: str,
                  config: Configuration) -> List[TestDefinition]:
        if not config:
            return []

        includes = config.pop_optional(list, 'include') or []
        excludes = config.pop_optional(list, 'exclude') or []
        parameters = config.pop_optional(Configuration,
                                         'parameters') or Configuration()
        all_tests = self.find_python_tests()

        PythonTestsProvider.validate_match_strings(all_tests,
                                                   includes + excludes)

        # Instantiate tests selected
        for test in all_tests:
            test.selected = PythonTestsProvider.test_selected(
                test.name, includes, excludes)

            test_parameters_list = parameters.pop_raw(test.name)
            # If no parameters used, just create one empty set
            if test.selected and not test_parameters_list:
                test_parameters_list = [{}]

            if not isinstance(test_parameters_list, list):
                test_parameters_list = [test_parameters_list]

            for test_parameters in test_parameters_list:
                test.parameter_sets.append(test_parameters)

        parameters.ensure_consumed()
        config.ensure_consumed()
        return all_tests
Exemplo n.º 2
0
    def _create_test_controller(self, board: Board,
                                settings: Configuration) -> TestController:
        tests = TestsConfig.create_tests(self.selected_tests(), board)

        testrunner = TestRunner(
            board=board,
            tests=tests,
            email_on_fail=settings.pop_optional(bool,
                                                'email_on_fail',
                                                default=False),
            continue_on_fail=settings.pop_optional(bool,
                                                   'continue_on_fail',
                                                   default=True))

        controller = TestController(testrunner,
                                    log_func=log.info,
                                    verbose_log_func=log.notice,
                                    debug_log_func=log.debug)

        iterations = settings.pop_optional(int, 'iterations')
        if iterations:
            controller.run_condition = sc_run_n_iterations(
                ntimes=int(iterations))

        return controller
    def __populate_tests(self, tests_config: Configuration):
        self.tests = []

        sequence = tests_config.pop_optional(list,
                                             'sequence',
                                             context='test config')
        if sequence:
            self.tests = self.tests_from_sequence(sequence,
                                                  self.test_providers)
Exemplo n.º 4
0
    def _create_context(config: Configuration) -> PlumaContext:
        variables = TargetFactory.parse_variables(
            config.pop_optional(Configuration, 'variables'))
        system = TargetFactory.parse_system_context(
            config.pop_optional(Configuration, 'system'))
        consoles = TargetFactory.create_consoles(
            config.pop_optional(Configuration, 'console'), system)

        serial = consoles.get('serial')
        ssh = consoles.get('ssh')
        if not serial and not ssh:
            log.warning("No console defined in the device configuration file")

        power = TargetFactory.create_power_control(
            config.pop_optional(Configuration, 'power'), ssh or serial)

        config.ensure_consumed()

        board = Board('Test board',
                      console=consoles,
                      power=power,
                      system=system)
        return PlumaContext(board, variables=variables)
    def __init__(self, config: Configuration,
                 test_providers: List[TestsProvider]):
        if not config or not isinstance(config, Configuration):
            raise ValueError(
                f'Null or invalid \'config\', which must be of type \'{Configuration}\''
            )

        if not test_providers:
            raise ValueError('Null test providers passed')

        if not isinstance(test_providers, list):
            test_providers = [test_providers]

        self.settings_config = config.pop_optional(Configuration,
                                                   SETTINGS_SECTION,
                                                   Configuration())
        self.results_config = self.settings_config.pop_optional(
            Configuration, RESULTS_SECTION, Configuration())
        self.test_providers: List[TestsProvider] = test_providers
        self.tests: List[TestDefinition] = []

        self.__populate_tests(config)

        config.ensure_consumed()