コード例 #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
コード例 #2
0
def check(hsm, states, Event, exp_resp_states, exp_tran_targets):
    state_set = set([get_state_by_sig(sig, hsm.flattened) for sig in states])
    tree = tree_from_state_set(state_set)
    resps = get_responses(tree, Event(), hsm.trans, None)

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

        assert len(trans) == len(exp_tran_targets)
        target_ids = set([tr.target for tr in trans])
        assert target_ids == set(exp_tran_targets)
    else:
        assert resps == []
コード例 #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 == []