本文整理汇总了Python中sismic.interpreter.Interpreter类的典型用法代码示例。如果您正苦于以下问题:Python Interpreter类的具体用法?Python Interpreter怎么用?Python Interpreter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Interpreter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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'))
示例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)
示例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)
示例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'])
示例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)
示例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))
示例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()
示例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)
示例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)
示例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'])
示例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'])
示例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)
示例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'])
示例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'))