def test_pauses(self): trace = [ MacroStep(0, []), MacroStep(10, []), MacroStep(10, []), MacroStep(15, []), ] self.assertListEqual(story_from_trace(trace), [Pause(10), Pause(5)])
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)
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)
def test_events(self): trace = [ MacroStep(0, [MicroStep(Event('a'))]), MacroStep(0, [MicroStep(Event('b'))]), MacroStep(0, [MicroStep(Event('c'))]), MacroStep(0, [MicroStep(Event('d'))]), ] self.assertListEqual( story_from_trace(trace), [Event('a'), Event('b'), Event('c'), Event('d')])
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)
def test_ignore_internal_events(self): trace = [ MacroStep(2, [MicroStep(Event('a'))]), MacroStep(5, [MicroStep(Event('b'))]), MacroStep(9, [MicroStep(InternalEvent('c'))]), MacroStep(14, [MicroStep(Event('d'))]), ] self.assertListEqual(story_from_trace(trace), [ Pause(2), Event('a'), Pause(3), Event('b'), Pause(4), Pause(5), Event('d') ])
def test_events_and_pauses(self): trace = [ MacroStep(2, [MicroStep(event=Event('a'))]), MacroStep(5, [MicroStep(event=Event('b'))]), MacroStep(9, [MicroStep(event=Event('c'))]), MacroStep(14, [MicroStep(event=Event('d'))]), ] self.assertListEqual(story_from_trace(trace), [ Pause(2), Event('a'), Pause(3), Event('b'), Pause(4), Event('c'), Pause(5), Event('d') ])
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')))
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'))))
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)
def test_single_step(self): trace = [ MacroStep(0, steps=[ MicroStep(entered_states=['a', 'b', 'c'], transition=Transition('x')), MicroStep(entered_states=['a', 'b'], transition=Transition('x')), MicroStep(entered_states=['a']), MicroStep(entered_states=[]) ]) ] self.assertEqual( coverage_from_trace(trace), (Counter(a=3, b=2, c=1), Counter({Transition('x'): 2})))
def test_single_step(self): trace = [MacroStep(0, steps=[ MicroStep(entered_states=['a', 'b', 'c'], exited_states=['b'], transition=Transition('x')), MicroStep(entered_states=['a', 'b'], exited_states=['c'], transition=Transition('x')), MicroStep(entered_states=['a']), MicroStep(entered_states=[]) ])] expected = { 'entered states': Counter(a=3, b=2, c=1), 'exited states': Counter(b=1, c=1), 'processed transitions': Counter({Transition('x'): 2}) } assert coverage_from_trace(trace) == expected
def test_multiple_steps(self): trace = [ MacroStep(0, steps=[ MicroStep(entered_states=['a', 'b', 'c'], transition=Transition('x')), MicroStep(entered_states=['a', 'b'], transition=Transition('x')), MicroStep(entered_states=['a']), MicroStep(entered_states=[]) ]) ] trace.extend(trace) self.assertEqual( coverage_from_trace(trace), (Counter(a=6, b=4, c=2), Counter({Transition('x'): 4})))
def test_multiple_steps(self): trace = [MacroStep(0, steps=[ MicroStep(entered_states=['a', 'b', 'c'], exited_states=['b'], transition=Transition('x')), MicroStep(entered_states=['a', 'b'], exited_states=['c'], transition=Transition('x')), MicroStep(entered_states=['a']), MicroStep(entered_states=[]) ])] trace.extend(trace) expected = { 'entered states': Counter(a=6, b=4, c=2), 'exited states': Counter(b=2, c=2), 'processed transitions': Counter({Transition('x'): 4}) } assert coverage_from_trace(trace) == expected
def test_initial_pause(self): trace = [MacroStep(10, [])] self.assertListEqual(story_from_trace(trace), [Pause(10)])