Beispiel #1
0
    def test_run(self, state_name, Event, foo_before, foo_expected,
                 exp_responding_state, exp_transition_target):
        mock_hsm = MockHSM()
        mock_hsm.data.foo = foo_before
        state = get_state_by_sig((state_name,), self.hsm.flattened)
        tree = tree_from_state_set(set([state]))

        resps = get_responses(tree, Event(), self.hsm.trans, mock_hsm)

        if exp_responding_state is None:
            assert resps == []
        else:
            assert len(resps) == 1  # no orthogonal regions in this HSM
            resp_subtrees, trans = zip(*resps)
            assert resp_subtrees[0][0].name == exp_responding_state
            tran = trans[0]

            if exp_transition_target is not None:
                assert State.sig_to_name(tran.target) == exp_transition_target
            else:
                assert tran.target is None

            tran.action(None, mock_hsm)  # this call might change 'foo' value
                                         # event is not relevant

        if foo_expected != 'ignored':
            assert mock_hsm.data.foo == foo_expected
Beispiel #2
0
 def test_find_invalid_choice_transitions(self):
     func = find_invalid_choice_transitions
     res = sorted((State.sig_to_name(sig), evt)
                  for sig, evt in func(self.hsm.flattened, self.hsm.trans))
     assert sorted(res) == sorted([
         ('choice_placeholder_1', A),
         ('choice_placeholder_1', B),
         ('choice_placeholder_1', C),
         ('right_A', A),
         ('right_A', C),
         ('choice_test_1', Initial),
         #('right_A', Initial),  # these two are valid Choices, but not
         #('right_B', Initial),  # valid initial transitions
     ])
Beispiel #3
0
    def test_choice(self, states, event, exp_resp_states, exp_tran_targets):
        state_set = set([get_state_by_sig((name,), self.hsm.flattened)
                         for name in states])
        tree = tree_from_state_set(state_set)
        resps = get_responses(tree, event, self.hsm.trans, None)
        print resps

        if exp_resp_states or exp_tran_targets:
            resp_subtrees, trans = zip(*resps)
            assert len(resp_subtrees) == len(exp_resp_states)
            resp_names = set([st.name for st, _ in resp_subtrees])
            assert resp_names == set(exp_resp_states)

            assert len(trans) == len(exp_tran_targets)
            target_ids = set([State.sig_to_name(tr.target) for tr in trans])
            assert target_ids == set(exp_tran_targets)
        else:
            assert resps == []
Beispiel #4
0
 def test_sig_to_name(self, sig, name):
     assert State.sig_to_name(sig) == name