Ejemplo n.º 1
0
 def test__EventNoBraces_NonActions_NonCondition__Valid(self):
     example = 'EvConfig1'
     parser = TransitionParser(example)
     events, condition, actions = parser.get_transition_items()
     self.assertEqual(events, 'EvConfig1')
     self.assertEqual(actions, '')
     self.assertEqual(condition, '')
Ejemplo n.º 2
0
 def test__EventArgEventArg_ActionAction_Condition__Valid(self):
     example = 'EvConfig1(1), EvConfig2(2) [ i > k ] / Action1() { [] }, Action2()'
     parser = TransitionParser(example)
     events, condition, actions = parser.get_transition_items()
     self.assertEqual(events, 'EvConfig1(1), EvConfig2(2)')
     self.assertEqual(condition, 'i > k')
     self.assertEqual(actions, 'Action1() { [] }, Action2()')
Ejemplo n.º 3
0
 def test__Event_ActionPlusStringAction_Condition__Valid(self):
     example = 'EvConfig1() [ i > k ] / Action1() { [ "Hello Denis" ] }, Action2()'
     parser = TransitionParser(example)
     events, condition, actions = parser.get_transition_items()
     self.assertEqual(events, 'EvConfig1()')
     self.assertEqual(condition, 'i > k')
     self.assertEqual(actions, 'Action1() { [ "Hello Denis" ] }, Action2()')
Ejemplo n.º 4
0
 def test__Event_NonActions_Condition__Valid(self):
     example = 'EvConfig1() [ i > k ]'
     parser = TransitionParser(example)
     events, condition, actions = parser.get_transition_items()
     self.assertEqual(events, 'EvConfig1()')
     self.assertEqual(condition, 'i > k')
     self.assertEqual(actions, '')
Ejemplo n.º 5
0
 def test__Event_ActionAction_Condition2__Valid(self):
     example = 'powerOn{} [ name.size() > default_name.size() ] / Action(), Action2()'
     parser = TransitionParser(example)
     events, condition, actions = parser.get_transition_items()
     self.assertEqual(events, 'powerOn{}')
     self.assertEqual(condition, 'name.size() > default_name.size()')
     self.assertEqual(actions, 'Action(), Action2()')
Ejemplo n.º 6
0
    def _parse_transition(self, instructions, parent_state=None):
        """

        :param instructions:
        :param parent_state:
        :return:
        """
        states = set()
        transitions = set()
        transition_meta = _transition.finditer(instructions)
        for transition in transition_meta:
            from_state_name = transition.group('state_from')
            to_state_name = transition.group('state_to')
            comment = transition.group('comment')
            events = []
            actions = []
            condition = None
            if comment is not None:
                parser = TransitionParser(comment)
                raw_events, raw_condition, raw_actions = parser.get_transition_items(
                )
                events = self._parse_events(raw_events)
                actions = self._parse_actions(raw_actions)
                condition = self._parse_condition(raw_condition)
            if from_state_name != '[*]':
                from_state = State.create_state(from_state_name, parent_state)
                for state in states:
                    if from_state == state:
                        state.sub_states.update(from_state.sub_states)
                        state.transitions.update(from_state.transitions)
                        break
                else:
                    states.add(from_state)
            else:
                from_state = parent_state
            if to_state_name != '[*]':
                to_state = State.create_state(to_state_name, parent_state)
                for state in states:
                    if to_state == state:
                        state.sub_states.update(to_state.sub_states)
                        state.transitions.update(to_state.transitions)
                        break
                else:
                    states.add(to_state)
            else:
                to_state = parent_state
            transitions.add(
                Transition(from_state, to_state, events, actions, condition))
        return states, transitions
Ejemplo n.º 7
0
 def test__Event_ActionPlusStringAction_Condition__Invalid3(self):
     example = "EvConfig1() / Action1() { [ Hello Denis' ] }, Action2() [ i > k ]"
     with self.assertRaises(ValidationError) as context:
         parser = TransitionParser(example)
Ejemplo n.º 8
0
 def test__Event_ActionAction_Condition__Invalid(self):
     example = 'EvConfig() [ i > k ]] / Action1() { [] }, Action2()'
     with self.assertRaises(ValidationError) as context:
         parser = TransitionParser(example)
Ejemplo n.º 9
0
 def test__EventArgEventArg_ActionAction_Condition__Invalid3(self):
     example = 'EvConfig1(1), EvConfig2(2) [ i > k ] / Action1() { [ }, Action2()'
     with self.assertRaises(ValidationError) as context:
         parser = TransitionParser(example)