当前位置: 首页>>代码示例>>Python>>正文


Python Interpreter.execute_once方法代码示例

本文整理汇总了Python中sismic.interpreter.Interpreter.execute_once方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.execute_once方法的具体用法?Python Interpreter.execute_once怎么用?Python Interpreter.execute_once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sismic.interpreter.Interpreter的用法示例。


在下文中一共展示了Interpreter.execute_once方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SimulatorHistoryTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:36,代码来源:test_interpreter.py

示例2: BindTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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.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,代码行数:33,代码来源:test_interpreter.py

示例3: ElevatorContractTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [as 别名]
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,代码行数:9,代码来源:test_examples.py

示例4: SimulatorSimpleTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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)
开发者ID:mgoeminne,项目名称:sismic,代码行数:36,代码来源:test_interpreter.py

示例5: ElevatorTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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)
开发者ID:mgoeminne,项目名称:sismic,代码行数:28,代码来源:test_examples.py

示例6: test_floor_selection

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [as 别名]
    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,代码行数:10,代码来源:test_examples.py

示例7: test_nondeterminism

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [as 别名]
    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,代码行数:11,代码来源:test_interpreter.py

示例8: test_simple_entered

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [as 别名]
 def test_simple_entered(self):
     sc = io.import_from_yaml(open('tests/yaml/simple.yaml'))
     interpreter = Interpreter(sc, DummyEvaluator)
     interpreter.send(Event('goto s2'))
     self.assertEqual(interpreter.execute_once().entered_states, ['s2'])
     interpreter.send(Event('goto final'))
     self.assertEqual(interpreter.execute_once().entered_states, ['s3'])
     self.assertEqual(interpreter.execute_once().entered_states, ['final'])
     self.assertEqual(interpreter.configuration, [])
     self.assertTrue(interpreter.final)
开发者ID:tommens,项目名称:sismic,代码行数:12,代码来源:test_interpreter.py

示例9: SimulatorDeepHistoryTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:55,代码来源:test_interpreter.py

示例10: InfiniteExecutionTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:31,代码来源:test_interpreter.py

示例11: MicrowaveTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:27,代码来源:test_examples.py

示例12: ParallelExecutionTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [as 别名]
class ParallelExecutionTests(unittest.TestCase):
    def setUp(self):
        with open('tests/yaml/parallel.yaml') as f:
            sc = io.import_from_yaml(f)
        self.interpreter = Interpreter(sc)
        # Stabilization
        self.interpreter.execute_once()

    def test_concurrent_transitions(self):
        step = self.interpreter.queue(Event('nextA')).execute_once()

        self.assertEqual(self.interpreter.configuration, ['root', 's1', 'p1', 'p2', 'a1', 'a2'])
        self.assertLess(step.exited_states.index('initial1'), step.exited_states.index('initial2'))
        self.assertLess(step.entered_states.index('a1'), step.entered_states.index('a2'))

    def test_concurrent_transitions_nested_target(self):
        self.interpreter.queue(Event('nextA')).queue(Event('reset1'))
        self.interpreter.execute()

        self.assertEqual(self.interpreter.configuration, ['root', 's1', 'p1', 'p2', 'a2', 'initial1'])

    def test_unnested_transitions(self):
        self.interpreter.queue(Event('nextA')).queue(Event('nextA'))
        self.interpreter.execute()

        self.assertEqual(self.interpreter.configuration, ['root', 's1', 'p1', 'p2', 'a2', 'initial1'])

    def test_unnested_transitions_2(self):
        self.interpreter.queue(Event('nextA')).queue(Event('nextB'))
        self.interpreter.execute()

        self.assertEqual(self.interpreter.configuration, ['root', 's1', 'p1', 'p2', 'b1', 'b2'])

    def test_conflicting_transitions(self):
        self.interpreter.queue(Event('nextA')).queue(Event('nextB')).queue(Event('conflict1'))
        self.interpreter.execute_once()
        self.interpreter.execute_once()

        with self.assertRaises(exceptions.ConflictingTransitionsError):
            self.interpreter.execute_once()

    def test_conflicting_transitions_2(self):
        self.interpreter.queue(Event('nextA')).queue(Event('nextB')).queue(Event('conflict2'))
        self.interpreter.execute_once()
        self.interpreter.execute_once()

        with self.assertRaises(exceptions.ConflictingTransitionsError):
            self.interpreter.execute_once()
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:50,代码来源:test_interpreter.py

示例13: InternalTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [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)
开发者ID:AlexandreDecan,项目名称:sismic,代码行数:29,代码来源:test_interpreter.py

示例14: test_simple_configuration

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [as 别名]
 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,代码行数:12,代码来源:test_interpreter.py

示例15: ParallelExecutionTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import execute_once [as 别名]
class ParallelExecutionTests(unittest.TestCase):
    def setUp(self):
        self.sc = io.import_from_yaml(open('tests/yaml/parallel.yaml'))
        self.interpreter = Interpreter(self.sc)

    def test_concurrent_transitions(self):
        step = self.interpreter.send(Event('nextA')).execute_once()

        self.assertEqual(self.interpreter.configuration, ['s1', 'p1', 'p2', 'a1', 'a2'])
        self.assertLess(step.exited_states.index('initial1'), step.exited_states.index('initial2'))
        self.assertLess(step.entered_states.index('a1'), step.entered_states.index('a2'))

    def test_concurrent_transitions_nested_target(self):
        self.interpreter.send(Event('nextA')).send(Event('reset1'))
        self.interpreter.execute()

        self.assertEqual(self.interpreter.configuration, ['s1', 'p1', 'p2', 'a2', 'initial1'])

    def test_unnested_transitions(self):
        self.interpreter.send(Event('nextA')).send(Event('nextA'))
        self.interpreter.execute()

        self.assertEqual(self.interpreter.configuration, ['s1', 'p1', 'p2', 'a2', 'initial1'])

    def test_unnested_transitions_2(self):
        self.interpreter.send(Event('nextA')).send(Event('nextB'))
        self.interpreter.execute()

        self.assertEqual(self.interpreter.configuration, ['s1', 'p1', 'p2', 'b1', 'b2'])

    def test_conflicting_transitions(self):
        self.interpreter.send(Event('nextA')).send(Event('nextB')).send(Event('conflict1'))
        self.interpreter.execute_once()
        self.interpreter.execute_once()

        with self.assertRaises(Warning):
            self.interpreter.execute_once()

    def test_conflicting_transitions_2(self):
        self.interpreter.send(Event('nextA')).send(Event('nextB')).send(Event('conflict2'))
        self.interpreter.execute_once()
        self.interpreter.execute_once()

        with self.assertRaises(Warning):
            self.interpreter.execute_once()
开发者ID:tommens,项目名称:sismic,代码行数:47,代码来源:test_interpreter.py


注:本文中的sismic.interpreter.Interpreter.execute_once方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。