本文整理汇总了Python中sismic.interpreter.Interpreter类的典型用法代码示例。如果您正苦于以下问题:Python Interpreter类的具体用法?Python Interpreter怎么用?Python Interpreter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Interpreter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ElevatorContractTests
class ElevatorContractTests(ElevatorTests):
def setUp(self):
with open('docs/examples/elevator_contract.yaml') as f:
self.sc = io.import_from_yaml(f)
self.interpreter = Interpreter(self.sc)
# Stabilization
self.interpreter.execute_once()
开发者ID:mgoeminne,项目名称:sismic,代码行数:7,代码来源:test_examples.py
示例2: BindTests
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.assertIn(other_interpreter.queue, self.interpreter._bound)
self.interpreter.raise_event(InternalEvent('test'))
self.assertTrue(self.interpreter._internal_events.pop(), Event('test'))
self.assertTrue(other_interpreter._external_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.assertIn(other_interpreter.queue, self.interpreter._bound)
self.interpreter.raise_event(InternalEvent('test'))
self.assertTrue(self.interpreter._internal_events.pop(), Event('test'))
self.assertTrue(other_interpreter._external_events.pop(), Event('test'))
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:31,代码来源:test_interpreter.py
示例3: InfiniteExecutionTests
class InfiniteExecutionTests(unittest.TestCase):
def setUp(self):
self.sc = io.import_from_yaml(open('tests/yaml/infinite.yaml'))
self.interpreter = Interpreter(self.sc)
def test_three_steps(self):
self.assertEqual(self.interpreter.configuration, ['s1'])
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['s2'])
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['s1'])
self.interpreter.execute_once()
self.assertEqual(self.interpreter.configuration, ['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, ['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)
开发者ID:tommens,项目名称:sismic,代码行数:26,代码来源:test_interpreter.py
示例4: InternalTests
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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:27,代码来源:test_interpreter.py
示例5: test_floor_selection
def test_floor_selection(self):
sc = io.import_from_yaml(open('docs/examples/elevator.yaml'))
interpreter = Interpreter(sc)
interpreter.send(Event('floorSelected', floor=4)).execute_once()
self.assertEqual(interpreter._evaluator.context['destination'], 4)
interpreter.execute_once()
self.assertEqual(sorted(interpreter.configuration), ['active', 'doorsClosed', 'floorListener', 'floorSelecting', 'movingElevator'])
开发者ID:tommens,项目名称:sismic,代码行数:8,代码来源:test_examples.py
示例6: test_run_in_background
def test_run_in_background(self):
sc = io.import_from_yaml(open('tests/yaml/simple.yaml'))
intp = Interpreter(sc)
task = run_in_background(intp, 0.001)
intp.send(Event('goto s2'))
intp.send(Event('goto final'))
task.join()
self.assertTrue(intp.final)
开发者ID:tommens,项目名称:sismic,代码行数:8,代码来源:test_interpreter.py
示例7: test_statechart_postcondition
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))
开发者ID:tommens,项目名称:sismic,代码行数:8,代码来源:test_contract.py
示例8: test_nondeterminism
def test_nondeterminism(self):
with open('tests/yaml/nondeterministic.yaml') as f:
sc = io.import_from_yaml(f)
interpreter = Interpreter(sc, evaluator_klass=DummyEvaluator)
# Stabilization
interpreter.execute_once()
with self.assertRaises(exceptions.NonDeterminismError):
interpreter.execute_once()
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:9,代码来源:test_interpreter.py
示例9: test_run_in_background
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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:9,代码来源:test_interpreter.py
示例10: setUp
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)
开发者ID:mgoeminne,项目名称:sismic,代码行数:9,代码来源:test_examples.py
示例11: test_memory
def test_memory(self):
sc = io.import_from_yaml(open('tests/yaml/history.yaml'))
interpreter = Interpreter(sc, DummyEvaluator)
interpreter.send(Event('next')).execute_once()
self.assertEqual(sorted(interpreter.configuration), ['loop', 's2'])
step = interpreter.send(Event('pause')).execute_once()
self.assertEqual(step.exited_states, ['s2', 'loop'])
self.assertEqual(sorted(interpreter.configuration), ['pause'])
开发者ID:tommens,项目名称:sismic,代码行数:10,代码来源:test_interpreter.py
示例12: test_resume_memory
def test_resume_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'))
steps = 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(interpreter.configuration), ['loop', 's2'])
开发者ID:tommens,项目名称:sismic,代码行数:11,代码来源:test_interpreter.py
示例13: generic_temporal_test
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)
开发者ID:mgoeminne,项目名称:sismic,代码行数:11,代码来源:test_temporal_testing.py
示例14: test_simple_configuration
def test_simple_configuration(self):
sc = io.import_from_yaml(open('tests/yaml/simple.yaml'))
interpreter = Interpreter(sc, DummyEvaluator)
interpreter.execute_once() # Should do nothing!
self.assertEqual(interpreter.configuration, ['s1'])
interpreter.send(Event('goto s2'))
interpreter.execute_once()
self.assertEqual(interpreter.configuration, ['s2'])
interpreter.execute_once()
self.assertEqual(interpreter.configuration, ['s3'])
开发者ID:tommens,项目名称:sismic,代码行数:10,代码来源:test_interpreter.py
示例15: BindTests
class BindTests(unittest.TestCase):
def setUp(self):
sc = io.import_from_yaml(open('tests/yaml/simple.yaml'))
self.interpreter = Interpreter(sc)
def test_bind(self):
other_sc = io.import_from_yaml(open('tests/yaml/simple.yaml'))
other_interpreter = Interpreter(other_sc)
self.interpreter.bind(other_interpreter)
self.assertEqual(self.interpreter._bound, [other_interpreter.send])
self.interpreter.send(Event('test'), internal=True)
self.assertTrue(self.interpreter._events.pop(), Event('test'))
self.assertTrue(other_interpreter._events.pop(), Event('test'))
def test_bind_callable(self):
other_sc = io.import_from_yaml(open('tests/yaml/simple.yaml'))
other_interpreter = Interpreter(other_sc)
self.interpreter.bind(other_interpreter.send)
self.assertEqual(self.interpreter._bound, [other_interpreter.send])
self.interpreter.send(Event('test'), internal=True)
self.assertTrue(self.interpreter._events.pop(), Event('test'))
self.assertTrue(other_interpreter._events.pop(), Event('test'))
开发者ID:tommens,项目名称:sismic,代码行数:26,代码来源:test_interpreter.py
示例16: PythonEvaluatorNestedContextTests
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']
开发者ID:aliparsai,项目名称:sismic,代码行数:48,代码来源:test_evaluator.py
示例17: setUp
def setUp(self):
with open('tests/yaml/nested_parallel.yaml') as f:
sc = io.import_from_yaml(f)
self.interpreter = Interpreter(sc)
# Stabilization
self.interpreter.execute_once()
self.common_states = ['root', 's1', 'p1', 'p2', 'r1', 'r2', 'r3', 'r4']
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:7,代码来源:test_interpreter.py
示例18: setUp
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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:28,代码来源:test_evaluator.py
示例19: generic_test
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)
开发者ID:mgoeminne,项目名称:sismic,代码行数:32,代码来源:test_temporal_testing.py
示例20: LogTraceTests
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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:18,代码来源:test_interpreter.py
注:本文中的sismic.interpreter.Interpreter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论