Example #1
0
    def test_execution_stopped(self):
        story = teststory_from_trace([])
        self.assertIn(Event('execution stopped'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertIn(Event('execution stopped'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertIn(Event('execution stopped'), story)
Example #2
0
    def test_step_ended(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('step ended'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertIn(Event('step ended'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertIn(Event('step ended'), story)
Example #3
0
    def test_step_ended(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('step ended'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertIn(Event('step ended'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertIn(Event('step ended'), story)
Example #4
0
    def test_execution_stopped(self):
        story = teststory_from_trace([])
        self.assertIn(Event('execution stopped'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertIn(Event('execution stopped'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertIn(Event('execution stopped'), story)
Example #5
0
    def test_event_consumed(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('event consumed'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('event consumed'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('event consumed'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep(event=Event('a'))])])
        self.assertIn(Event('event consumed', event=Event('a')), story)
Example #6
0
    def test_transition_processed(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('transition processed'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('transition processed'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('transition processed'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep(event=Event('c'), transition=Transition('a', 'b', event='c'))])])
        self.assertIn(Event('transition processed', source='a', target='b', event=Event('c')), story)
Example #7
0
    def test_event_consumed(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('event consumed'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('event consumed'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('event consumed'), story)

        story = teststory_from_trace(
            [MacroStep(0, [MicroStep(event=Event('a'))])])
        self.assertIn(Event('event consumed', event=Event('a')), story)
Example #8
0
    def test_simple(self):
        with open('tests/yaml/simple.yaml') as f:
            sc = io.import_from_yaml(f)
        interpreter = Interpreter(sc)

        trace = Story([Pause(2), Event('goto s2'), Pause(3)]).tell(interpreter)
        story = teststory_from_trace(trace)

        expected = Story([
            Event('execution started'),
            Pause(2),
            Event('step started'),
            Event('state entered', state='root'),
            Event('state entered', state='s1'),
            Event('step ended'),
            Event('step started'),
            Event('event consumed', event=Event('goto s2')),
            Event('state exited', state='s1'),
            Event('transition processed', source='s1', target='s2', event=Event('goto s2')),
            Event('state entered', state='s2'),
            Event('step ended'),
            Event('step started'),
            Event('state exited', state='s2'),
            Event('transition processed', source='s2', target='s3', event=None),
            Event('state entered', state='s3'),
            Event('step ended'),
            Event('execution stopped')
        ])
        for a, b in zip(story, expected):
            self.assertEqual(a, b)
            if isinstance(a, Event):
                self.assertEqual(a.data.items(), b.data.items())
            else:
                self.assertEqual(a.duration, b.duration)
Example #9
0
    def test_elevator_moves_after_10s(self):
        stories = [
            Story([Event('floorSelected', floor=4)]),
            Story([Event('floorSelected', floor=0)]),
            Story([Event('floorSelected', floor=4),
                   Pause(10)]),
            Story([Event('floorSelected', floor=0),
                   Pause(10)]),
            Story([Event('floorSelected', floor=4),
                   Pause(9)]),
            Story([Event('floorSelected', floor=0),
                   Pause(9)]),
        ]

        for story in stories:
            with self.subTest(story=story):
                # Reopen because we need to reset it
                with open('docs/examples/elevator.yaml') as f:
                    sc = io.import_from_yaml(f)
                tested = Interpreter(sc)

                test_story = teststory_from_trace(story.tell(tested))

                with open('docs/examples/tester_elevator_moves_after_10s.yaml'
                          ) as f:
                    tester = Interpreter(io.import_from_yaml(f))
                test_story.tell(tester)
                self.assertFalse(tester.final)
Example #10
0
    def test_event_sent(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('event sent'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('event sent'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('event sent'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep(sent_events=[Event('a')])])])
        self.assertIn(Event('event sent', event=Event('a')), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep(sent_events=[Event('a'), Event('b')])])])
        self.assertIn(Event('event sent', event=Event('a')), story)
        self.assertIn(Event('event sent', event=Event('b')), story)
        self.assertLess(story.index(Event('event sent', event=Event('a'))),
                       story.index(Event('event sent', event=Event('b'))))
Example #11
0
    def test_state_exited(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('state exited'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('state exited'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('state exited'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep(exited_states=['a'])])])
        self.assertIn(Event('state exited', state='a'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep(exited_states=['a', 'b'])])])
        self.assertIn(Event('state exited', state='a'), story)
        self.assertIn(Event('state exited', state='b'), story)
        self.assertLess(story.index(Event('state exited', state='a')),
                        story.index(Event('state exited', state='b')))
Example #12
0
    def test_7th_floor_never_reached_fails(self):
        tested = Interpreter(io.import_from_yaml(open('docs/examples/elevator.yaml')))
        story = Story([Event('floorSelected', floor=4), Pause(2), Event('floorSelected', floor=7)])
        trace = story.tell(tested).trace

        test_story = teststory_from_trace(trace)

        tester = Interpreter(io.import_from_yaml(open('docs/examples/tester_elevator_7th_floor_never_reached.yaml')))
        self.assertFalse(test_story.tell(tester).final)
Example #13
0
    def test_7th_floor_never_reached_fails(self):
        story = Story([Event('floorSelected', floor=4), Pause(2), Event('floorSelected', floor=7)])
        trace = story.tell(self.tested)  # self.tested is an interpreter for our elevator

        test_story = teststory_from_trace(trace)

        with open('docs/examples/elevator/tester_elevator_7th_floor_never_reached.yaml') as f:
            tester = Interpreter(io.import_from_yaml(f))
        test_story.tell(tester)
        self.assertTrue(tester.final)
Example #14
0
    def test_state_exited(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('state exited'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('state exited'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('state exited'), story)

        story = teststory_from_trace(
            [MacroStep(0, [MicroStep(exited_states=['a'])])])
        self.assertIn(Event('state exited', state='a'), story)

        story = teststory_from_trace(
            [MacroStep(0, [MicroStep(exited_states=['a', 'b'])])])
        self.assertIn(Event('state exited', state='a'), story)
        self.assertIn(Event('state exited', state='b'), story)
        self.assertLess(story.index(Event('state exited', state='a')),
                        story.index(Event('state exited', state='b')))
Example #15
0
    def test_event_sent(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('event sent'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('event sent'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('event sent'), story)

        story = teststory_from_trace(
            [MacroStep(0, [MicroStep(sent_events=[Event('a')])])])
        self.assertIn(Event('event sent', event=Event('a')), story)

        story = teststory_from_trace(
            [MacroStep(
                0, [MicroStep(sent_events=[Event('a'), Event('b')])])])
        self.assertIn(Event('event sent', event=Event('a')), story)
        self.assertIn(Event('event sent', event=Event('b')), story)
        self.assertLess(story.index(Event('event sent', event=Event('a'))),
                        story.index(Event('event sent', event=Event('b'))))
Example #16
0
    def test_7th_floor_never_reached(self):
        story = Story([Event('floorSelected', floor=8)])
        trace = story.tell(
            self.tested)  # self.tested is an interpreter for our elevator

        test_story = teststory_from_trace(trace)

        with open('docs/examples/tester_elevator_7th_floor_never_reached.yaml'
                  ) as f:
            tester = Interpreter(io.import_from_yaml(f))
        test_story.tell(tester)
        self.assertFalse(tester.final)
Example #17
0
    def test_transition_processed(self):
        story = teststory_from_trace([])
        self.assertNotIn(Event('transition processed'), story)

        story = teststory_from_trace([MacroStep(0, [])])
        self.assertNotIn(Event('transition processed'), story)

        story = teststory_from_trace([MacroStep(0, [MicroStep()])])
        self.assertNotIn(Event('transition processed'), story)

        story = teststory_from_trace([
            MacroStep(0, [
                MicroStep(event=Event('c'),
                          transition=Transition('a', 'b', event='c'))
            ])
        ])
        self.assertIn(
            Event('transition processed',
                  source='a',
                  target='b',
                  event=Event('c')), story)
Example #18
0
    def test_elevator_moves_after_10s(self):
        tested_sc = io.import_from_yaml(open('docs/examples/elevator.yaml'))
        tester_sc = io.import_from_yaml(open('docs/examples/tester_elevator_moves_after_10s.yaml'))

        stories = [
            Story([Event('floorSelected', floor=4)]),
            Story([Event('floorSelected', floor=0)]),
            Story([Event('floorSelected', floor=4), Pause(10)]),
            Story([Event('floorSelected', floor=0), Pause(10)]),
            Story([Event('floorSelected', floor=4), Pause(9)]),
            Story([Event('floorSelected', floor=0), Pause(9)]),
        ]

        for story in stories:
            tested = Interpreter(tested_sc)
            test_story = teststory_from_trace(story.tell(tested).trace)

            tester = Interpreter(tester_sc)
            self.assertTrue(test_story.tell(tester).final)
Example #19
0
 def test_simple(self):
     interpreter = Interpreter(io.import_from_yaml(open('tests/yaml/simple.yaml')))
     Story([Pause(2), Event('goto s2'), Pause(3)]).tell(interpreter)
     story = teststory_from_trace(interpreter.trace)
     expected = Story([Event('started'),
                       Event('entered', state='s1'),
                       Pause(2),
                       Event('consumed', event=Event('goto s2')),
                       Event('exited', state='s1'),
                       Event('processed', source='s1', target='s2', event=Event('goto s2')),
                       Event('entered', state='s2'),
                       Event('exited', state='s2'),
                       Event('processed', source='s2', target='s3', event=None),
                       Event('entered', state='s3'),
                       Event('stopped')])
     for a, b in zip(story, expected):
         self.assertEqual(a, b)
         if isinstance(a, Event):
             self.assertEqual(a.data.items(), b.data.items())
         else:
             self.assertEqual(a.duration, b.duration)
Example #20
0
    def generic_test(self,
                     tested_statechart: Statechart,
                     events: list,
                     property: Condition,
                     expected_success: bool,
                     expected_failure: bool):
        from sismic.interpreter import log_trace
        tester_statechart = Statechart('tester_statechart')

        tester_statechart.add_state(OrthogonalState('parallel_state'), None)
        tester_statechart.add_state(CompoundState('testing_area', initial='property'), parent='parallel_state')
        tester_statechart.add_state(BasicState('success_state'), parent='testing_area')
        tester_statechart.add_state(BasicState('failure_state'), parent='testing_area')

        property.add_to(tester_statechart,
                        id='property',
                        parent_id='testing_area',
                        status_id='parallel_state',
                        success_id='success_state',
                        failure_id='failure_state')

        tester_interpreter = Interpreter(tester_statechart)

        self.assertFalse('success_state' in tester_interpreter.configuration)
        self.assertFalse('failure_state' in tester_interpreter.configuration)

        tested_interpreter = Interpreter(tested_statechart)
        trace = log_trace(tested_interpreter)

        for event in events:
            tested_interpreter.queue(event)

        tested_interpreter.execute()

        story = teststory_from_trace(trace)
        story.tell(tester_interpreter)

        self.assertEqual(expected_success, 'success_state' in tester_interpreter.configuration)
        self.assertEqual(expected_failure, 'failure_state' in tester_interpreter.configuration)
Example #21
0
    def test_simple(self):
        with open('tests/yaml/simple.yaml') as f:
            sc = io.import_from_yaml(f)
        interpreter = Interpreter(sc)

        trace = Story([Pause(2), Event('goto s2'), Pause(3)]).tell(interpreter)
        story = teststory_from_trace(trace)

        expected = Story([
            Event('execution started'),
            Pause(2),
            Event('step started'),
            Event('state entered', state='root'),
            Event('state entered', state='s1'),
            Event('step ended'),
            Event('step started'),
            Event('event consumed', event=Event('goto s2')),
            Event('state exited', state='s1'),
            Event('transition processed',
                  source='s1',
                  target='s2',
                  event=Event('goto s2')),
            Event('state entered', state='s2'),
            Event('step ended'),
            Event('step started'),
            Event('state exited', state='s2'),
            Event('transition processed', source='s2', target='s3',
                  event=None),
            Event('state entered', state='s3'),
            Event('step ended'),
            Event('execution stopped')
        ])
        for a, b in zip(story, expected):
            self.assertEqual(a, b)
            if isinstance(a, Event):
                self.assertEqual(a.data.items(), b.data.items())
            else:
                self.assertEqual(a.duration, b.duration)
Example #22
0
    def test_elevator_moves_after_10s(self):
        stories = [
            Story([Event('floorSelected', floor=4)]),
            Story([Event('floorSelected', floor=0)]),
            Story([Event('floorSelected', floor=4), Pause(10)]),
            Story([Event('floorSelected', floor=0), Pause(10)]),
            Story([Event('floorSelected', floor=4), Pause(9)]),
            Story([Event('floorSelected', floor=0), Pause(9)]),
        ]

        for story in stories:
            with self.subTest(story=story):
                # Reopen because we need to reset it
                with open('docs/examples/elevator/elevator.yaml') as f:
                    sc = io.import_from_yaml(f)
                tested = Interpreter(sc)

                test_story = teststory_from_trace(story.tell(tested))

                with open('docs/examples/elevator/tester_elevator_moves_after_10s.yaml') as f:
                    tester = Interpreter(io.import_from_yaml(f))
                test_story.tell(tester)
                self.assertFalse(tester.final)