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


Python Interpreter.send方法代码示例

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


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

示例1: BindTests

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

示例2: test_floor_selection

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import send [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

示例3: test_statechart_postcondition

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

示例4: test_run_in_background

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

示例5: test_simple_entered

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import send [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

示例6: test_simple_configuration

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import send [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

示例7: test_memory

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

示例8: test_resume_memory

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

示例9: test_doorsOpen

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

示例10: test_exited_order

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import send [as 别名]
    def test_exited_order(self):
        sc = io.import_from_yaml(open('tests/yaml/deep_history.yaml'))
        interpreter = Interpreter(sc, DummyEvaluator)

        interpreter.send(Event('next1')).send(Event('next2')).send(Event('pause'))
        step = interpreter.execute()[-1]

        self.assertEqual(step.exited_states, ['s12', 's22', 'process_1', 'process_2', 'concurrent_processes', 'active'])
        self.assertEqual(sorted(interpreter.configuration), ['pause'])

        step = interpreter.send(Event('continue')).execute_once()
        self.assertEqual(step.exited_states, ['pause', 'active.H*'])

        interpreter.send(Event('next1')).send(Event('next2')).execute()
        self.assertTrue(interpreter.final)
开发者ID:tommens,项目名称:sismic,代码行数:17,代码来源:test_interpreter.py

示例11: RemoteElevatorTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import send [as 别名]
class RemoteElevatorTests(unittest.TestCase):
    def setUp(self):
        self.elevator = Interpreter(io.import_from_yaml(open('docs/examples/elevator.yaml')))
        self.buttons = Interpreter(io.import_from_yaml(open('docs/examples/elevator_buttons.yaml')))
        self.buttons.bind(self.elevator)

    def test_button(self):
        self.assertEqual(self.elevator.context['current'], 0)

        self.buttons.send(Event('button_2_pushed'))
        self.buttons.execute()

        event = self.elevator._events.pop()
        self.assertEqual(event, Event('floorSelected'))
        self.assertEqual(event.data['floor'], 2)

        self.buttons.send(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.send(Event('button_0_pushed'))
        self.buttons.execute()
        self.elevator.execute()

        self.assertEqual(self.elevator.context['current'], 0)
开发者ID:tommens,项目名称:sismic,代码行数:32,代码来源:test_examples.py

示例12: WriterExecutionTests

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import send [as 别名]
class WriterExecutionTests(unittest.TestCase):
    def setUp(self):
        self.sc = io.import_from_yaml(open('docs/examples/writer_options.yaml'))
        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.send(event)

        self.interpreter.execute()

        self.assertTrue(self.interpreter.final)
        self.assertEqual(self.interpreter.context['output'], ['bonjour ', '[b]', '[i]', 'a ', '[/b]', '[/i]', '[b]', 'tous !', '[/b]'])
开发者ID:tommens,项目名称:sismic,代码行数:25,代码来源:test_examples.py

示例13: InternalTests

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

    def testInternalSent(self):
        step = self.interpreter.execute_once()
        self.assertEqual(step.event.name, 'next')

    def testInternalBeforeExternal(self):
        self.interpreter.send(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:tommens,项目名称:sismic,代码行数:26,代码来源:test_interpreter.py

示例14: test_after_memory

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

示例15: test_deep_memory

# 需要导入模块: from sismic.interpreter import Interpreter [as 别名]
# 或者: from sismic.interpreter.Interpreter import send [as 别名]
    def test_deep_memory(self):
        sc = io.import_from_yaml(open('tests/yaml/deep_history.yaml'))
        interpreter = Interpreter(sc, DummyEvaluator)

        interpreter.send(Event('next1')).send(Event('next2'))
        interpreter.execute()
        self.assertEqual(sorted(interpreter.configuration), ['active', 'concurrent_processes', 'process_1', 'process_2', 's12', 's22'])

        interpreter.send(Event('error1'))
        interpreter.execute()
        self.assertEqual(interpreter.configuration, ['pause'])
        self.assertEqual(sorted(interpreter._memory['active.H*']), ['concurrent_processes', 'process_1', 'process_2', 's12', 's22'])

        interpreter.send(Event('continue'))
        interpreter.execute()
        self.assertEqual(sorted(interpreter.configuration), ['active', 'concurrent_processes', 'process_1',
                                                           'process_2', 's12', 's22'])
开发者ID:tommens,项目名称:sismic,代码行数:19,代码来源:test_interpreter.py


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