本文整理汇总了Python中sismic.interpreter.Interpreter.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.execute方法的具体用法?Python Interpreter.execute怎么用?Python Interpreter.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sismic.interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SimulatorSimpleTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class SimulatorSimpleTests(unittest.TestCase):
def setUp(self):
with open('tests/yaml/simple.yaml') as f:
sc = io.import_from_yaml(f)
self.interpreter = Interpreter(sc, DummyEvaluator)
# Stabilization
self.interpreter.execute_once()
def test_init(self):
self.assertEqual(self.interpreter.configuration, ['root', 's1'])
self.assertFalse(self.interpreter.final)
def test_simple_configuration(self):
self.interpreter.execute_once() # Should do nothing!
self.assertEqual(self.interpreter.configuration, ['root', 's1'])
self.interpreter.queue(Event('goto s2'))
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['root', 's2'])
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['root', 's3'])
def test_simple_entered(self):
self.interpreter.queue(Event('goto s2'))
self.assertEqual(self.interpreter.execute_once().entered_states, ['s2'])
self.interpreter.queue(Event('goto final'))
self.assertEqual(self.interpreter.execute_once().entered_states, ['s3'])
self.assertEqual(self.interpreter.execute_once().entered_states, ['final'])
self.assertEqual(self.interpreter.configuration, [])
self.assertTrue(self.interpreter.final)
def test_simple_final(self):
self.interpreter.queue(Event('goto s2')).queue(Event('goto final'))
self.interpreter.execute()
self.assertTrue(self.interpreter.final)
示例2: InfiniteExecutionTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class InfiniteExecutionTests(unittest.TestCase):
def setUp(self):
with open('tests/yaml/infinite.yaml') as f:
sc = io.import_from_yaml(f)
self.interpreter = Interpreter(sc)
# Stabilization
self.interpreter.execute_once()
def test_three_steps(self):
self.assertEqual(self.interpreter.configuration, ['root', 's1'])
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['root', 's2'])
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['root', 's1'])
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['root', 's2'])
self.assertEqual(self.interpreter.context['x'], 2) # x is incremented in s1.on_entry
def test_auto_three_steps(self):
self.interpreter.execute(max_steps=3)
self.assertEqual(self.interpreter.configuration, ['root', 's2'])
self.assertEqual(self.interpreter.context['x'], 2) # x is incremented in s1.on_entry
def test_auto_stop(self):
self.interpreter.execute()
self.assertTrue(self.interpreter.final)
self.assertEqual(self.interpreter.context['x'], 100)
示例3: SimulatorHistoryTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class SimulatorHistoryTests(unittest.TestCase):
def setUp(self):
with open('tests/yaml/history.yaml') as f:
sc = io.import_from_yaml(f)
self.interpreter = Interpreter(sc, evaluator_klass=DummyEvaluator)
# Stabilization
self.interpreter.execute_once()
def test_memory(self):
self.interpreter.queue(Event('next')).execute_once()
self.assertEqual(sorted(self.interpreter.configuration), ['loop', 'root', 's2'])
step = self.interpreter.queue(Event('pause')).execute_once()
self.assertEqual(step.exited_states, ['s2', 'loop'])
self.assertEqual(sorted(self.interpreter.configuration), ['pause', 'root'])
def test_resume_memory(self):
self.interpreter.queue(Event('next')).queue(Event('pause')).queue(Event('continue'))
steps = self.interpreter.execute()
step = steps[-1]
self.assertEqual(step.entered_states, ['loop', 'loop.H', 's2'])
self.assertEqual(step.exited_states, ['pause', 'loop.H'])
self.assertEqual(sorted(self.interpreter.configuration), ['loop', 'root', 's2'])
def test_after_memory(self):
self.interpreter.queue(Event('next')).queue(Event('pause')).queue(Event('continue'))
self.interpreter.queue(Event('next')).queue(Event('next'))
self.interpreter.execute()
self.assertEqual(sorted(self.interpreter.configuration), ['loop', 'root', 's1'])
self.interpreter.queue(Event('pause')).queue(Event('stop'))
self.interpreter.execute()
self.assertTrue(self.interpreter.final)
示例4: ElevatorTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class ElevatorTests(unittest.TestCase):
def setUp(self):
with open('docs/examples/elevator.yaml') as f:
self.sc = io.import_from_yaml(f)
self.interpreter = Interpreter(self.sc)
# Stabilization
self.interpreter.execute_once()
def test_init(self):
self.assertEqual(len(self.interpreter.configuration), 5)
def test_floor_selection(self):
self.interpreter.queue(Event('floorSelected', floor=4)).execute_once()
self.assertEqual(self.interpreter.context['destination'], 4)
self.interpreter.execute_once()
self.assertEqual(sorted(self.interpreter.configuration), ['active', 'doorsClosed', 'floorListener', 'floorSelecting', 'movingElevator'])
def test_doorsOpen(self):
self.interpreter.queue(Event('floorSelected', floor=4))
self.interpreter.execute()
self.assertEqual(self.interpreter.context['current'], 4)
self.interpreter.time += 10
self.interpreter.execute()
self.assertTrue('doorsOpen' in self.interpreter.configuration)
self.assertEqual(self.interpreter.context['current'], 0)
示例5: RemoteElevatorTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class RemoteElevatorTests(unittest.TestCase):
def setUp(self):
with open('docs/examples/elevator.yaml') as f:
elevator = io.import_from_yaml(f)
with open('docs/examples/elevator_buttons.yaml') as f:
buttons = io.import_from_yaml(f)
self.elevator = Interpreter(elevator)
self.buttons = Interpreter(buttons)
self.buttons.bind(self.elevator)
def test_button(self):
self.assertEqual(self.elevator.context['current'], 0)
self.buttons.queue(Event('button_2_pushed'))
self.buttons.execute()
event = self.elevator._events.pop()
self.assertEqual(event.name, 'floorSelected')
self.assertEqual(event.data['floor'], 2)
self.buttons.queue(Event('button_2_pushed'))
self.buttons.execute()
self.elevator.execute()
self.assertEqual(self.elevator.context['current'], 2)
def test_button_0_on_groundfloor(self):
self.assertEqual(self.elevator.context['current'], 0)
self.buttons.queue(Event('button_0_pushed'))
self.buttons.execute()
self.elevator.execute()
self.assertEqual(self.elevator.context['current'], 0)
示例6: generic_test
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
def generic_test(self, condition: Condition, success_expected: bool, failure_expected: bool, delay: int = 0):
statechart = Statechart('test')
parallel_state = OrthogonalState('parallel_state')
statechart.add_state(parallel_state, parent=None)
initial_state = CompoundState('initial_state', initial='Cond')
statechart.add_state(initial_state, "parallel_state")
statechart.add_state(BasicState('success'), 'initial_state')
statechart.add_state(BasicState('failure'), 'initial_state')
condition.add_to(statechart=statechart,
id='Cond',
parent_id='initial_state',
status_id=parallel_state,
success_id='success',
failure_id='failure')
interpreter = Interpreter(statechart)
self.assertFalse('success' in interpreter.configuration)
self.assertFalse('failure' in interpreter.configuration)
interpreter.execute()
interpreter.time += delay
interpreter.queue(Event(Condition.STEP_ENDED_EVENT))
interpreter.queue(Event(Condition.STEP_ENDED_EVENT))
interpreter.execute()
self.assertEqual(success_expected, 'success' in interpreter.configuration)
self.assertEqual(failure_expected, 'failure' in interpreter.configuration)
示例7: MicrowaveTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class MicrowaveTests(unittest.TestCase):
def setUp(self):
with open('docs/examples/microwave/microwave.yaml') as f:
sc = io.import_from_yaml(f)
self.microwave = Interpreter(sc)
def test_lamp_on(self):
self.microwave.execute_once()
self.microwave.queue(Event('door_opened'))
step = self.microwave.execute_once()
self.microwave.execute_once()
self.assertEqual(step.sent_events[0].name, 'lamp_switch_on')
def test_heating_on(self):
self.microwave.execute_once()
self.microwave.queue(Event('door_opened'))
self.microwave.queue(Event('item_placed'))
self.microwave.queue(Event('door_closed'))
self.microwave.queue(Event('input_timer_inc'))
self.microwave.execute()
self.microwave.queue(Event('input_cooking_start'))
step = self.microwave.execute_once()
self.assertIn(Event('heating_on'), step.sent_events)
self.assertIn(Event('lamp_switch_on'), step.sent_events)
self.assertIn(Event('turntable_start'), step.sent_events)
示例8: InternalTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class InternalTests(unittest.TestCase):
def setUp(self):
with open('tests/yaml/internal.yaml') as f:
self.sc = io.import_from_yaml(f)
self.interpreter = Interpreter(self.sc)
# Stabilization
self.interpreter.execute_once()
def testInternalSent(self):
step = self.interpreter.execute_once()
self.assertEqual(step.event.name, 'next')
def testInternalBeforeExternal(self):
self.interpreter.queue(Event('not_next'))
step = self.interpreter.execute_once()
self.assertEqual(step.event.name, 'next')
step = self.interpreter.execute_once()
self.assertEqual(step.event, None)
self.assertEqual(step.entered_states, ['s2'])
step = self.interpreter.execute_once()
self.assertEqual(step.event.name, 'not_next')
def testActiveGuard(self):
self.interpreter.execute()
self.assertTrue(self.interpreter.final)
示例9: test_statechart_postcondition
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
def test_statechart_postcondition(self):
sc = io.import_from_yaml(open('tests/yaml/simple.yaml'))
sc.postconditions.append('False')
interpreter = Interpreter(sc)
interpreter.send(Event('goto s2')).send(Event('goto final'))
with self.assertRaises(PostconditionFailed) as cm:
interpreter.execute()
self.assertTrue(isinstance(cm.exception.obj, StateChart))
示例10: generic_temporal_test
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
def generic_temporal_test(self, expression: TemporalExpression, story: list, accept_after: bool):
# Todo: convert the story list into a 'real' story that can be told to an interpreter
statechart = expression.generate_statechart()
interpreter = Interpreter(statechart)
for event in story:
interpreter.queue(event)
interpreter.execute()
self.assertEqual(len(interpreter.configuration) == 0, accept_after)
示例11: test_doorsOpen
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
def test_doorsOpen(self):
sc = io.import_from_yaml(open('docs/examples/elevator.yaml'))
interpreter = Interpreter(sc)
interpreter.send(Event('floorSelected', floor=4))
interpreter.execute()
self.assertEqual(interpreter._evaluator.context['current'], 4)
interpreter.time += 10
interpreter.execute()
self.assertTrue('doorsOpen' in interpreter.configuration)
self.assertEqual(interpreter._evaluator.context['current'], 0)
示例12: test_after_memory
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
def test_after_memory(self):
sc = io.import_from_yaml(open('tests/yaml/history.yaml'))
interpreter = Interpreter(sc, DummyEvaluator)
interpreter.send(Event('next')).send(Event('pause')).send(Event('continue'))
interpreter.send(Event('next')).send(Event('next'))
interpreter.execute()
self.assertEqual(sorted(interpreter.configuration), ['loop', 's1'])
interpreter.send(Event('pause')).send(Event('stop'))
interpreter.execute()
self.assertTrue(interpreter.final)
示例13: WatchElevatorTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
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)
示例14: PythonEvaluatorNestedContextTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class PythonEvaluatorNestedContextTests(unittest.TestCase):
def setUp(self):
statechart = """
statechart:
name: test
preamble: x = y = 1
root state:
name: root
initial: s1
states:
- name: s1
on entry: x, z = 2, 1
transitions:
- target: s2
guard: y == 1
action: a, z, y = 2, 2, 2
- name: s2
"""
sc = import_from_yaml(statechart)
self.intp = Interpreter(sc)
def test_initialization(self):
self.assertEqual(self.intp.context.get('x'), 1)
self.assertEqual(self.intp.context.get('y'), 1)
with self.assertRaises(KeyError):
_ = self.intp.context['z']
with self.assertRaises(KeyError):
_ = self.intp.context['a']
def test_global_context(self):
self.intp.execute()
self.assertEqual(self.intp.context.get('x'), 2)
self.assertEqual(self.intp.context.get('y'), 2)
with self.assertRaises(KeyError):
_ = self.intp.context['z']
with self.assertRaises(KeyError):
_ = self.intp.context['a']
def test_nested_context(self):
self.intp.execute()
s1 = self.intp._evaluator.context_for('s1')
self.assertEqual(s1['x'], 2)
self.assertEqual(s1['y'], 2)
self.assertEqual(s1['z'], 2)
with self.assertRaises(KeyError):
_ = s1['a']
示例15: SimulatorDeepHistoryTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute [as 别名]
class SimulatorDeepHistoryTests(unittest.TestCase):
def setUp(self):
with open('tests/yaml/deep_history.yaml') as f:
sc = io.import_from_yaml(f)
self.interpreter = Interpreter(sc, evaluator_klass=DummyEvaluator)
# Stabilization
self.interpreter.execute_once()
def test_deep_memory(self):
self.interpreter.queue(Event('next1')).queue(Event('next2'))
self.interpreter.execute()
self.assertEqual(sorted(self.interpreter.configuration), ['active', 'concurrent_processes', 'process_1', 'process_2', 'root', 's12', 's22'])
self.interpreter.queue(Event('error1'))
self.interpreter.execute()
self.assertEqual(self.interpreter.configuration, ['root', 'pause'])
self.assertEqual(sorted(self.interpreter._memory['active.H*']), ['concurrent_processes', 'process_1', 'process_2', 's12', 's22'])
self.interpreter.queue(Event('continue'))
self.interpreter.execute()
self.assertEqual(sorted(self.interpreter.configuration), ['active', 'concurrent_processes', 'process_1',
'process_2', 'root', 's12', 's22'])
def test_entered_order(self):
self.interpreter.queue(Event('next1')).queue(Event('next2')).queue(Event('pause'))
step = self.interpreter.execute()[-1]
self.assertEqual(step.entered_states, ['pause'])
self.assertEqual(sorted(self.interpreter.configuration), ['pause', 'root'])
step = self.interpreter.queue(Event('continue')).execute_once()
self.assertTrue(step.entered_states.index('active') < step.entered_states.index('active.H*'))
self.assertTrue(step.entered_states.index('active.H*') < step.entered_states.index('concurrent_processes'))
self.assertTrue(step.entered_states.index('concurrent_processes') < step.entered_states.index('process_1'))
self.assertTrue(step.entered_states.index('concurrent_processes') < step.entered_states.index('process_2'))
self.assertTrue(step.entered_states.index('process_1') < step.entered_states.index('s12'))
self.assertTrue(step.entered_states.index('process_2') < step.entered_states.index('s22'))
self.interpreter.queue(Event('next1')).queue(Event('next2')).execute()
self.assertTrue(self.interpreter.final)
def test_exited_order(self):
self.interpreter.queue(Event('next1')).queue(Event('next2')).queue(Event('pause'))
step = self.interpreter.execute()[-1]
self.assertEqual(step.exited_states, ['s12', 's22', 'process_1', 'process_2', 'concurrent_processes', 'active'])
self.assertEqual(sorted(self.interpreter.configuration), ['pause', 'root'])
step = self.interpreter.queue(Event('continue')).execute_once()
self.assertEqual(step.exited_states, ['pause', 'active.H*'])
self.interpreter.queue(Event('next1')).queue(Event('next2')).execute()
self.assertTrue(self.interpreter.final)