本文整理汇总了Python中sismic.interpreter.Interpreter.queue方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.queue方法的具体用法?Python Interpreter.queue怎么用?Python Interpreter.queue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sismic.interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.queue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ElevatorTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例2: BindTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [as 别名]
class BindTests(unittest.TestCase):
def setUp(self):
with open('tests/yaml/simple.yaml') as f:
sc = io.import_from_yaml(f)
self.interpreter = Interpreter(sc)
# Stabilization
self.interpreter.execute_once()
def test_bind(self):
with open('tests/yaml/simple.yaml') as f:
other_sc = io.import_from_yaml(f)
other_interpreter = Interpreter(other_sc)
self.interpreter.bind(other_interpreter)
self.assertEqual(self.interpreter._bound, [other_interpreter.queue])
self.interpreter.queue(InternalEvent('test'))
self.assertTrue(self.interpreter._events.pop(), Event('test'))
self.assertTrue(other_interpreter._events.pop(), Event('test'))
def test_bind_callable(self):
with open('tests/yaml/simple.yaml') as f:
other_sc = io.import_from_yaml(f)
other_interpreter = Interpreter(other_sc)
self.interpreter.bind(other_interpreter.queue)
self.assertEqual(self.interpreter._bound, [other_interpreter.queue])
self.interpreter.queue(InternalEvent('test'))
self.assertTrue(self.interpreter._events.pop(), Event('test'))
self.assertTrue(other_interpreter._events.pop(), Event('test'))
示例3: generic_test
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例4: MicrowaveTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例5: InternalTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例6: test_run_in_background
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [as 别名]
def test_run_in_background(self):
with open('tests/yaml/simple.yaml') as f:
sc = io.import_from_yaml(f)
interpreter = Interpreter(sc)
task = run_in_background(interpreter, 0.001)
interpreter.queue(Event('goto s2'))
interpreter.queue(Event('goto final'))
task.join()
self.assertTrue(interpreter.final)
示例7: generic_temporal_test
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例8: SimulatorSimpleTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例9: LogTraceTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [as 别名]
class LogTraceTests(unittest.TestCase):
def setUp(self):
with open('docs/examples/elevator/elevator.yaml') as f:
sc = io.import_from_yaml(f)
self.tested = Interpreter(sc)
self.steps = log_trace(self.tested)
def test_empty_trace(self):
self.assertEqual(self.steps, [])
def test_nonempty_trace(self):
self.tested.queue(Event('floorSelected', floor=4)).execute()
self.assertTrue(len(self.steps) > 0)
def test_log_content(self):
self.tested.queue(Event('floorSelected', floor=4))
steps = self.tested.execute()
self.assertSequenceEqual(self.steps, steps)
示例10: tell
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [as 别名]
def tell(self, interpreter: Interpreter, *args, **kwargs) -> List[MacroStep]:
"""
Tells the whole story to the interpreter.
:param interpreter: an interpreter instance
:param args: additional positional arguments that are passed to *interpreter.execute*.
:param kwargs: additional keywords arguments that are passed to *interpreter.execute*.
:return: the resulting trace of execution (a list of *MacroStep*)
"""
trace = [] # type: List[MacroStep]
for item in self:
if isinstance(item, Event):
interpreter.queue(item)
elif isinstance(item, Pause):
interpreter.time += item.duration
step = interpreter.execute(*args, **kwargs)
if step:
trace.extend(step)
return trace
示例11: RemoteElevatorTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例12: WriterExecutionTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [as 别名]
class WriterExecutionTests(unittest.TestCase):
def setUp(self):
with open('docs/examples/writer_options.yaml') as f:
self.sc = io.import_from_yaml(f)
self.interpreter = Interpreter(self.sc)
def test_output(self):
scenario = [
Event('keyPress', key='bonjour '),
Event('toggle'),
Event('keyPress', key='a '),
Event('toggle'),
Event('toggle_bold'),
Event('keyPress', key='tous !'),
Event('leave')
]
for event in scenario:
self.interpreter.queue(event)
self.interpreter.execute()
self.assertTrue(self.interpreter.final)
self.assertEqual(self.interpreter.context['output'], ['bonjour ', '[b]', '[i]', 'a ', '[/b]', '[/i]', '[b]', 'tous !', '[/b]'])
示例13: PythonEvaluatorSequenceConditionTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [as 别名]
class PythonEvaluatorSequenceConditionTests(unittest.TestCase):
def setUp(self):
self.sc = import_from_yaml("""
statechart:
name: test contract
root state:
name: root
on entry: x = 1
initial: s0
states:
- name: s0
initial: s1
transitions:
- event: end
target: root
states:
- name: s1
transitions:
- target: s2
action: x = 2
event: e
- name: s2
""")
self.root = self.sc.state_for('root') # Will never be exited
self.s0 = self.sc.state_for('s0') # Will be exited on "end"
self.s1 = self.sc.state_for('s1') # Entered, and then exited on e.
self.s2 = self.sc.state_for('s2') # Entered when e
self.intp = Interpreter(self.sc)
def test_single_condition(self):
self.root.sequences.append('"True"')
self.intp.execute()
def test_access_context(self):
self.root.sequences.append('"x == 1"')
self.intp.execute()
def test_access_nested_context(self):
self.s0.sequences.append('"x == 1" -> "x == 2"')
self.intp.queue(Event('e')).queue(Event('end'))
self.intp.execute()
def test_fails_fast(self):
self.s0.sequences.append('Failure')
with self.assertRaises(SequentialConditionError):
self.intp.execute()
def test_fails_on_exit(self):
self.s0.sequences.append('"x == 1" -> "x == 2" -> "x == 3"')
self.intp.queue(Event('e'))
self.intp.execute()
self.intp.queue(Event('end'))
with self.assertRaises(SequentialConditionError):
self.intp.execute()
示例14: WatchElevatorTests
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [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)
示例15: MicrowaveApplication
# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import queue [as 别名]
#.........这里部分代码省略.........
door_frame = tk.LabelFrame(sensors_frame, text='Door')
door_frame.pack(side=tk.TOP, fill=tk.BOTH, pady=(8, 0))
self.w_door = tk.Label(door_frame)
self.w_door_opened = tk.Button(door_frame, text='open door',
command=partial(self.send_event, event_name='door_opened'))
self.w_door_closed = tk.Button(door_frame, text='close door',
command=partial(self.send_event, event_name='door_closed'))
self.w_door_opened.pack(side=tk.TOP, fill=tk.X)
self.w_door_closed.pack(side=tk.TOP, fill=tk.X)
# ACTUATORS frame
right_frame = tk.LabelFrame(self, text='ACTUATORS')
right_frame.pack(side=tk.LEFT, fill=tk.BOTH, padx=(8, 8))
# Display component
display_frame = tk.LabelFrame(right_frame, text='Display')
display_frame.pack(side=tk.TOP, fill=tk.BOTH)
self.w_display = tk.Label(display_frame)
self.w_display.pack(side=tk.TOP)
# Lamp component
lamp_frame = tk.LabelFrame(right_frame, text='Lamp')
lamp_frame.pack(side=tk.TOP, fill=tk.BOTH)
self.w_lamp = tk.Label(lamp_frame)
self.w_lamp.pack(side=tk.TOP)
# Heating component
heating_frame = tk.LabelFrame(right_frame, text='Heating')
heating_frame.pack(side=tk.TOP, fill=tk.BOTH)
self.w_heating_power = tk.Label(heating_frame)
self.w_heating_status = tk.Label(heating_frame)
self.w_heating_power.pack(side=tk.TOP)
self.w_heating_status.pack(side=tk.TOP)
# Beeper component
beep_frame = tk.LabelFrame(right_frame, text='Beeper')
beep_frame.pack(side=tk.TOP, fill=tk.BOTH)
self.w_beep = tk.Label(beep_frame)
self.w_beep.pack(side=tk.TOP)
# Turntable component
turntable_frame = tk.LabelFrame(right_frame, text='Turntable')
turntable_frame.pack(side=tk.TOP, fill=tk.BOTH)
self.w_turntable = tk.Label(turntable_frame)
self.w_turntable.pack(side=tk.TOP)
# Oven controller statechart component
controller_frame = tk.LabelFrame(self, text='Oven Controller')
controller_frame.pack(side=tk.LEFT, fill=tk.BOTH, padx=(8, 8))
# Microwave Controller Statechart status
# statechart_frame = tk.LabelFrame(right_frame2, text='Controller')
# statechart_frame.pack(side=tk.TOP, fill=tk.BOTH)
states_frame = tk.LabelFrame(controller_frame, text='States')
states_frame.pack(side=tk.TOP, fill=tk.BOTH)
self.w_states = tk.Label(states_frame)
self.w_states.pack(side=tk.TOP, fill=tk.X, pady=(8, 0))
variables_frame = tk.LabelFrame(controller_frame, text='Variables')
variables_frame.pack(side=tk.TOP, fill=tk.BOTH, pady=(8, 0))
self.w_timer = tk.Label(variables_frame)
self.w_timer.pack(side=tk.BOTTOM, fill=tk.X)
self.w_power = tk.Label(variables_frame)
self.w_power.pack(side=tk.BOTTOM, fill=tk.X)
def event_handler(self, event):
name = event.name
if name == 'lamp_switch_on':
self.w_lamp['text'] = 'on'
elif name == 'lamp_switch_off':
self.w_lamp['text'] = 'off'
elif name == 'display_set':
self.w_display['text'] = event.text
elif name == 'display_clear':
self.w_display['text'] = ''
elif name == 'heating_set_power':
self.w_heating_power['text'] = event.power
elif name == 'heating_on':
self.w_heating_status['text'] = 'on'
elif name == 'heating_off':
self.w_heating_status['text'] = 'off'
elif name == 'beep':
self.w_beep['text'] = event.number
elif name == 'turntable_start':
self.w_turntable['text'] = 'on'
elif name == 'turntable_stop':
self.w_turntable['text'] = 'off'
else:
raise ValueError('Unknown event %s' % event)
def send_event(self, event_name):
self.interpreter.queue(Event(event_name))
self.execute()
def _quit(self):
self.master.destroy()