Exemplo n.º 1
0
    def test_validate_multi_trigger_def_with_unknown_wildcard(self):
        trigger_defs = copy.deepcopy(self.MULTI_TRIGGER_DEFS)
        trigger_defs[0][SMConsts.SOURCE_STATES] = '+'

        ValidateData.validate_multi_trigger_defs(
            list_of_trigger_defs=trigger_defs,
            defined_states=self.MULTI_TRIGGER_STATES)
Exemplo n.º 2
0
    def test_validate_multi_trigger_def_without_callback_defined(self):
        trigger_defs = copy.deepcopy(self.MULTI_TRIGGER_DEFS)
        trigger_defs[0][SMConsts.CHANGE_STATE_ROUTINE] = None

        ValidateData.validate_multi_trigger_defs(
            list_of_trigger_defs=trigger_defs,
            defined_states=self.MULTI_TRIGGER_STATES)
Exemplo n.º 3
0
    def test_validate_multi_trigger_def_with_empty_state_list(self):
        trigger_defs = copy.deepcopy(self.MULTI_TRIGGER_DEFS)
        trigger_defs[0][SMConsts.SOURCE_STATES] = []

        ValidateData.validate_multi_trigger_defs(
            list_of_trigger_defs=trigger_defs,
            defined_states=self.MULTI_TRIGGER_STATES)
Exemplo n.º 4
0
    def test_validate_multi_trigger_def_without_dest_state_defined(self):
        trigger_defs = copy.deepcopy(self.MULTI_TRIGGER_DEFS)
        del trigger_defs[0][SMConsts.DESTINATION_STATE]

        ValidateData.validate_multi_trigger_defs(
            list_of_trigger_defs=trigger_defs,
            defined_states=self.MULTI_TRIGGER_STATES)
Exemplo n.º 5
0
    def test_validate_multi_trigger_def_with_invalid_state(self):
        trigger_defs = copy.deepcopy(self.MULTI_TRIGGER_DEFS)
        state_set_1 = [x for index, x in enumerate(self.MULTI_TRIGGER_STATES)
                       if index % 2 == 0]
        state_set_1.append(self.INVALID_TEST_STATE)

        trigger_defs[0][SMConsts.SOURCE_STATES] = state_set_1

        ValidateData.validate_multi_trigger_defs(
            list_of_trigger_defs=trigger_defs,
            defined_states=self.MULTI_TRIGGER_STATES)
Exemplo n.º 6
0
 def test_validate_multi_trigger_def_with_wildcard(self):
     assert_is_none(
         ValidateData.validate_multi_trigger_defs(
             list_of_trigger_defs=self.MULTI_TRIGGER_DEFS,
             defined_states=self.MULTI_TRIGGER_STATES
         )
     )
Exemplo n.º 7
0
    def test_validate_initial_state_with_invalid_state(self):
        model_file, model_cfg, model_def = setup_state_machine_definitions(
            self.MACHINE_DEFINITION_FILE)

        # Set initial state to an invalid state
        model_def.data[SMConsts.INITIAL_STATE] = self.INVALID_TEST_STATE

        # Validate the initial state, should return False
        assert_false(ValidateData(model_def).validate_initial_state())
Exemplo n.º 8
0
    def test_validate_all_transitions_with_no_states(self):
        model_file, model_cfg, model_def = setup_state_machine_definitions(
            self.MACHINE_DEFINITION_FILE)

        # Remove all states (and transitions)
        model_def.data[SMConsts.DEFINITION] = {}

        # Validate the transitions (there are none!), should return False
        assert_false(ValidateData(model_def).validate_all_transitions())
Exemplo n.º 9
0
    def test_validate_initial_state_with_none_value(self):
        model_file, model_cfg, model_def = setup_state_machine_definitions(
            self.MACHINE_DEFINITION_FILE)

        # Set the initial state to None (should be equivalent
        # to invalid state)
        model_def.data[SMConsts.INITIAL_STATE] = None

        # Validate the initial state, should return False
        assert_false(ValidateData(model_def).validate_initial_state())
Exemplo n.º 10
0
    def test_validate_initial_state_that_does_not_have_transitions(self):
        model_file, model_cfg, model_def = setup_state_machine_definitions(
            self.MACHINE_DEFINITION_FILE)
        model_def.data[SMConsts.INITIAL_STATE] = self.VALID_TEST_STATE

        # Remove all transitions from initial_state definition
        state_def = model_def.data[SMConsts.DEFINITION][
            self.VALID_TEST_STATE_INDEX]
        state_def[self.VALID_TEST_STATE][SMConsts.TRANSITIONS] = []

        # Validate the initial state, should return False
        assert_false(ValidateData(model_def).validate_initial_state())
Exemplo n.º 11
0
    def test_validate_multi_trigger_def_with_source_state_list(self):
        trigger_defs = copy.deepcopy(self.MULTI_TRIGGER_DEFS)
        state_set_1 = [x for index, x in enumerate(self.MULTI_TRIGGER_STATES)
                       if index % 2 == 0]
        state_set_2 = [x for index, x in enumerate(self.MULTI_TRIGGER_STATES)
                       if index % 2 == 1]

        trigger_defs[0][SMConsts.SOURCE_STATES] = state_set_1
        trigger_defs[1][SMConsts.SOURCE_STATES] = state_set_2

        assert_is_none(
            ValidateData.validate_multi_trigger_defs(
                list_of_trigger_defs=trigger_defs,
                defined_states=self.MULTI_TRIGGER_STATES
            )
        )
Exemplo n.º 12
0
    def test_validate_all_transitions_with_an_invalid_transition(self):
        bogus_transition = {
            SMConsts.CHANGE_STATE_ROUTINE: 'object_model.unlock_server',
            SMConsts.DESTINATION_STATE: self.INVALID_TEST_STATE,
            SMConsts.TRIGGER_NAME: 'BOGUS'
        }

        # Not pretty, but to meet PEP-8 line length, save to a tuple,
        # and then assign vars based on the tuple
        model_tuple = setup_state_machine_definitions(
            self.MACHINE_DEFINITION_FILE)
        (model_file, model_cfg, model_def) = model_tuple

        # Add a transition (to any state) that points to an
        # unknown/undefined state
        state_def = model_def.data[SMConsts.DEFINITION][
            self.VALID_TEST_STATE_INDEX]
        state_def[self.VALID_TEST_STATE][SMConsts.TRANSITIONS].append(
            bogus_transition)

        # Validate the transitions, should return False
        assert_false(ValidateData(model_def).validate_all_transitions())
Exemplo n.º 13
0
    def validate_multi_triggers(
            self, multi_trigger_defs: typing.List[dict]) -> typing.List[dict]:
        """
        Validates all multi-source trigger definitions.
        Args:
            multi_trigger_defs (list of dicts): definitions of each
            multi-source trigger

        Returns:
            None

        Raises:
            ValidateData will raise various exceptions based on the error

        """
        logging.debug(f"MULTI_TRIGGER_DATA:\n"
                      f"{pprint.pformat(multi_trigger_defs)}")

        ValidateData(self.data).validate_multi_trigger_defs(
            list_of_trigger_defs=multi_trigger_defs,
            defined_states=self.get_list_of_states())

        return multi_trigger_defs
Exemplo n.º 14
0
        logging.error("Need to specify test_suite_name AND test_case_name.")
        exit(1)

    # List the input files for reference
    display_input_files(log=logging,
                        model_file=machine_cfg_file,
                        test_file=test_file_name,
                        ts_name=test_suite_name,
                        tc_name=test_case_name,
                        log_file=logfile)

    # Parse the state machine definitions
    model_data = MachineDefinition(YamlInputFile(machine_cfg_file).data)

    # Validate that the state machine configuration is valid (static assessment)
    validation = ValidateData(model_data)
    if not (validation.validate_all_transitions()
            and validation.validate_initial_state()):
        logging.error("State Machine definitions are not correct.")
        exit()

    # Instantiate the Object model
    server_model = VmModel()

    # Instantiate and build the state machine
    machine = StateMachine(data_model=model_data, object_model=server_model)
    machine.BORDER_LEN = step_log_border_num_stars
    machine.NUM_ELEMS_PER_GRAPH_LINE = graph_steps_per_line
    machine.configure_state_machine()

    # Show a table with all of the state machine state definitions in the
Exemplo n.º 15
0
 def test_validate_initial_state(self):
     model_file, model_cfg, model_def = setup_state_machine_definitions(
         self.MACHINE_DEFINITION_FILE)
     assert_true(ValidateData(model_def).validate_initial_state())