class WatchElevatorTests(unittest.TestCase): def setUp(self): with open('docs/examples/elevator.yaml') as f: sc = io.import_from_yaml(f) self.tested = Interpreter(sc) self.watcher = ExecutionWatcher(self.tested) def test_7th_floor_never_reached(self): with open('docs/examples/tester_elevator_7th_floor_never_reached.yaml' ) as f: tester_sc = io.import_from_yaml(f) tester = self.watcher.watch_with(tester_sc) self.watcher.start() # Send elevator to 4th self.tested.queue(Event('floorSelected', floor=4)).execute() self.watcher.stop() self.assertFalse(tester.final) def test_7th_floor_never_reached_fails(self): with open('docs/examples/tester_elevator_7th_floor_never_reached.yaml' ) as f: tester_sc = io.import_from_yaml(f) tester = self.watcher.watch_with(tester_sc) self.watcher.start() # Send elevator to 7th self.tested.queue(Event('floorSelected', floor=7)).execute() self.watcher.stop() self.assertTrue(tester.final) def test_destination_reached(self): with open( 'docs/examples/tester_elevator_destination_reached.yaml') as f: tester_statechart = io.import_from_yaml(f) # Create the interpreter and the watcher watcher = ExecutionWatcher(self.tested) # Add the tester and start watching tester = watcher.watch_with(tester_statechart) watcher.start() # Send the elevator to 4th self.tested.queue(Event('floorSelected', floor=4)).execute(max_steps=2) self.assertEqual(tester.context['destinations'], [4]) self.tested.execute() self.assertEqual(tester.context['destinations'], []) # Stop watching. The tester must be in a final state watcher.stop() self.assertFalse(tester.final)
class WatchElevatorTests(unittest.TestCase): def setUp(self): with open('docs/examples/elevator.yaml') as f: sc = io.import_from_yaml(f) self.tested = Interpreter(sc) self.watcher = ExecutionWatcher(self.tested) def test_7th_floor_never_reached(self): with open('docs/examples/tester_elevator_7th_floor_never_reached.yaml') as f: tester_sc = io.import_from_yaml(f) tester = self.watcher.watch_with(tester_sc) self.watcher.start() # Send elevator to 4th self.tested.queue(Event('floorSelected', floor=4)).execute() self.watcher.stop() self.assertFalse(tester.final) def test_7th_floor_never_reached_fails(self): with open('docs/examples/tester_elevator_7th_floor_never_reached.yaml') as f: tester_sc = io.import_from_yaml(f) tester = self.watcher.watch_with(tester_sc) self.watcher.start() # Send elevator to 7th self.tested.queue(Event('floorSelected', floor=7)).execute() self.watcher.stop() self.assertTrue(tester.final) def test_destination_reached(self): with open('docs/examples/tester_elevator_destination_reached.yaml') as f: tester_statechart = io.import_from_yaml(f) # Create the interpreter and the watcher watcher = ExecutionWatcher(self.tested) # Add the tester and start watching tester = watcher.watch_with(tester_statechart) watcher.start() # Send the elevator to 4th self.tested.queue(Event('floorSelected', floor=4)).execute(max_steps=2) self.assertEqual(tester.context['destinations'], [4]) self.tested.execute() self.assertEqual(tester.context['destinations'], []) # Stop watching. The tester must be in a final state watcher.stop() self.assertFalse(tester.final)
def test_destination_reached(self): with open( 'docs/examples/tester_elevator_destination_reached.yaml') as f: tester_statechart = io.import_from_yaml(f) # Create the interpreter and the watcher watcher = ExecutionWatcher(self.tested) # Add the tester and start watching tester = watcher.watch_with(tester_statechart) watcher.start() # Send the elevator to 4th self.tested.queue(Event('floorSelected', floor=4)).execute(max_steps=2) self.assertEqual(tester.context['destinations'], [4]) self.tested.execute() self.assertEqual(tester.context['destinations'], []) # Stop watching. The tester must be in a final state watcher.stop() self.assertFalse(tester.final)
def test_destination_reached(self): with open('docs/examples/elevator/tester_elevator_destination_reached.yaml') as f: tester_statechart = io.import_from_yaml(f) # Create the interpreter and the watcher watcher = ExecutionWatcher(self.tested) # Add the tester and start watching tester = watcher.watch_with(tester_statechart) watcher.start() # Send the elevator to 4th self.tested.queue(Event('floorSelected', floor=4)).execute(max_steps=2) self.assertEqual(tester.context['destinations'], [4]) self.tested.execute() self.assertEqual(tester.context['destinations'], []) # Stop watching. The tester must be in a final state watcher.stop() self.assertFalse(tester.final)
def setUp(self): with open('docs/examples/elevator/elevator.yaml') as f: sc = io.import_from_yaml(f) self.tested = Interpreter(sc) self.watcher = ExecutionWatcher(self.tested)
def setUp(self): with open('docs/examples/elevator.yaml') as f: sc = io.import_from_yaml(f) self.tested = Interpreter(sc) self.watcher = ExecutionWatcher(self.tested)