本文整理汇总了Python中sismic.io.import_from_yaml函数的典型用法代码示例。如果您正苦于以下问题:Python import_from_yaml函数的具体用法?Python import_from_yaml怎么用?Python import_from_yaml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了import_from_yaml函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_examples
def test_examples(self):
files = ['elevator', 'elevator_contract', 'microwave', 'tester_elevator_7th_floor_never_reached',
'tester_elevator_moves_after_10s', 'writer_options']
for f in files:
d = io.export_to_yaml(io.import_from_yaml(open(os.path.join('docs', 'examples', f+'.yaml'))))
# check
io.import_from_yaml(d)
示例2: test_examples
def test_examples(self):
files = ['elevator', 'elevator_contract', 'microwave', 'tester_elevator_7th_floor_never_reached',
'tester_elevator_moves_after_10s', 'writer_options']
for filename in files:
with self.subTest(filename=filename):
with open(os.path.join('docs', 'examples', filename + '.yaml')) as f:
io.import_from_yaml(f)
示例3: test_yaml_tests
def test_yaml_tests(self):
files = ['actions', 'composite', 'deep_history', 'infinite', 'internal', 'nested_parallel',
'nondeterministic', 'parallel', 'simple', 'timer']
for filename in files:
with self.subTest(filename=filename):
with open(os.path.join('tests', 'yaml', filename + '.yaml')) as f:
io.import_from_yaml(f)
示例4: test_yaml_tests
def test_yaml_tests(self):
files = ['actions', 'composite', 'deep_history', 'infinite', 'internal', 'nested_parallel',
'nondeterministic', 'parallel', 'simple', 'timer']
for f in files:
d = io.export_to_yaml(io.import_from_yaml(open(os.path.join('tests', 'yaml', f+'.yaml'))))
# check
io.import_from_yaml(d)
示例5: test_export_valid
def test_export_valid(self):
for f, filename in self.files:
with self.subTest(filename=filename):
sc_1 = io.import_from_yaml(f)
ex_1 = io.export_to_yaml(sc_1)
sc_2 = io.import_from_yaml(ex_1)
self.assertTrue(sc_2.validate())
示例6: setUp
def setUp(self):
with open('tests/yaml/simple.yaml') as f:
self.sc1 = io.import_from_yaml(f)
with open('tests/yaml/composite.yaml') as f:
self.sc2 = io.import_from_yaml(f)
for state in self.sc1.states:
self.sc1.rename_state(state, 'sc1_' + state)
示例7: test_7th_floor_never_reached_fails
def test_7th_floor_never_reached_fails(self):
tested = Interpreter(io.import_from_yaml(open('docs/examples/elevator.yaml')))
story = Story([Event('floorSelected', floor=4), Pause(2), Event('floorSelected', floor=7)])
trace = story.tell(tested).trace
test_story = teststory_from_trace(trace)
tester = Interpreter(io.import_from_yaml(open('docs/examples/tester_elevator_7th_floor_never_reached.yaml')))
self.assertFalse(test_story.tell(tester).final)
示例8: 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)
示例9: test_remove_nested_states
def test_remove_nested_states(self):
with open('tests/yaml/composite.yaml') as f:
self.sc = io.import_from_yaml(f)
self.sc.remove_state('s1')
self.assertFalse('s1a' in self.sc.states)
self.sc.validate()
with open('tests/yaml/composite.yaml') as f:
self.sc = io.import_from_yaml(f)
self.sc.remove_state('s1a')
self.assertFalse('s1a' in self.sc.states)
self.sc.validate()
示例10: test_transitions_to_unknown_state
def test_transitions_to_unknown_state(self):
yaml = """
statechart:
name: test
root state:
name: root
initial: s1
states:
- name: s1
transitions:
- target: s2
"""
with self.assertRaises(exceptions.StatechartError) as cm:
io.import_from_yaml(yaml)
self.assertIn('Unknown target state', str(cm.exception))
示例11: 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']
示例12: test_simple
def test_simple(self):
with open('tests/yaml/simple.yaml') as f:
sc = io.import_from_yaml(f)
interpreter = Interpreter(sc)
trace = Story([Pause(2), Event('goto s2'), Pause(3)]).tell(interpreter)
story = teststory_from_trace(trace)
expected = Story([
Event('execution started'),
Pause(2),
Event('step started'),
Event('state entered', state='root'),
Event('state entered', state='s1'),
Event('step ended'),
Event('step started'),
Event('event consumed', event=Event('goto s2')),
Event('state exited', state='s1'),
Event('transition processed', source='s1', target='s2', event=Event('goto s2')),
Event('state entered', state='s2'),
Event('step ended'),
Event('step started'),
Event('state exited', state='s2'),
Event('transition processed', source='s2', target='s3', event=None),
Event('state entered', state='s3'),
Event('step ended'),
Event('execution stopped')
])
for a, b in zip(story, expected):
self.assertEqual(a, b)
if isinstance(a, Event):
self.assertEqual(a.data.items(), b.data.items())
else:
self.assertEqual(a.duration, b.duration)
示例13: test_order_constraints
def test_order_constraints(self):
"""
test if the adding order of the constraints influences the coordinates of the statechart.
"""
with open("tests/elevator.yaml", 'r') as stream:
statechart = io.import_from_yaml(stream)
assert isinstance(statechart, sismic.model.Statechart)
root_box = RootBox(statechart)
root_box.add_constraint(
Constraint(root_box.get_box_by_name('doorsClosed'), 'south', root_box.get_box_by_name('doorsOpen')))
root_box.add_constraint(
Constraint(root_box.get_box_by_name('doorsClosed'), 'west', root_box.get_box_by_name('moving')))
root_box.transitions
coordinates1 = root_box.coordinates
set1 = root_box.constraints.copy()
root_box.add_constraint(
Constraint(root_box.get_box_by_name('doorsClosed'), 'north', root_box.get_box_by_name('doorsOpen')))
root_box.add_constraint(
Constraint(root_box.get_box_by_name('doorsClosed'), 'east', root_box.get_box_by_name('moving')))
root_box.add_constraint(
Constraint(root_box.get_box_by_name('doorsClosed'), 'west', root_box.get_box_by_name('moving')))
root_box.add_constraint(
Constraint(root_box.get_box_by_name('doorsClosed'), 'south', root_box.get_box_by_name('doorsOpen')))
root_box.transitions
coordinates2 = root_box.coordinates
set2 = root_box.constraints.copy()
self.assertEqual(set1, set2)
for key in coordinates1.keys():
self.assertEqual(coordinates1[key], coordinates2[key],
msg='the positions of ' + str(key) + ' are not equals')
示例14: 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)
示例15: test_declare_both_states_and_parallel_states
def test_declare_both_states_and_parallel_states(self):
yaml = """
statechart:
name: test
root state:
name: root
initial: s1
states:
- name: s1
parallel states:
- name: s2
"""
with self.assertRaises(exceptions.StatechartError) as cm:
io.import_from_yaml(yaml)
self.assertIn('root cannot declare both a "states" and a "parallel states" property', str(cm.exception))