Exemple #1
0
    def test_reformat_simple_submachine(self):
        states = {
            'a': State(
                [
                    ({ 'sub1': State({
                        'x': State() }) },
                     { } ),

                    ({ 'sub2': State({
                        'y': State({
                            'deep': State() })})},
                     { } ),
                ])
        }
        exp_states = [
            orthogonal('a', [

                composite('a[0].sub1', [
                    leaf('a[0].x') ]),

                composite('a[1].sub2', [
                    composite('a[1].y',  [
                        leaf('a[1].deep')
                    ]) ])
            ])
        ]

        assert reformat(states, {}) == (exp_states, {})
Exemple #2
0
 def test_nested_empty(self):
     states = [
         composite('a', [
             orthogonal('submachines', [
                 composite('sub1', [
                     leaf('sub11'),
                     composite('sub12', [
                         leaf('sub121'),
                         leaf('sub122'),
                     ])
                 ]),
                 composite('sub2', [
                     leaf('sub21'),
                     composite('sub22', [
                         leaf('sub221'),
                         leaf('sub222'),
                     ]),
                 ]),
             ]),
             composite('b', [
                 leaf('b1')
             ]),
         ]),
         composite('c', [
             leaf('c1'),
             leaf('c2'),
         ]),
     ]
     names = [st.name for st in flatten(states)]
     expected = ['a', 'submachines', 'sub1', 'sub11', 'sub12', 'sub121',
                 'sub122', 'sub2', 'sub21', 'sub22', 'sub221', 'sub222',
                 'b', 'b1', 'c', 'c1', 'c2']
     assert len(names) == len(expected)
     assert set(names) == set(expected)
Exemple #3
0
 def test_reformat_miro_machine(self):
     states, _ = reformat(*make_miro_machine(use_logging=False))
     expected_states = [
         composite('top', [
             composite('s', [
                 composite('s1', [
                     leaf('s11')
                 ]),
                 composite('s2', [
                     composite('s21', [
                         leaf('s211')
                     ])
                 ])
             ]),
             leaf('final')
         ])
     ]
     assert states == expected_states
Exemple #4
0
 def test_children_list_different_order_nested(self):
     s1 = State()
     s2 = State()
     s1.states = [
         composite('A', [leaf('1'), leaf('2')]),
         composite('B', [leaf('3'), leaf('4')]),
     ]
     s2.states = [
         composite('A', [leaf('2'), leaf('1')]),
         composite('B', [leaf('4'), leaf('3')]),
     ]
     assert s1 == s2
     s2.states = [
         composite('B', [leaf('4'), leaf('3')]),
         composite('A', [leaf('2'), leaf('1')]),
     ]
     assert s1 == s2
     s2.states = [
         composite('B', [leaf('4'), leaf('3')]),
         composite('A', [leaf('999'), leaf('1')]),
     ]
     assert not s1 == s2
Exemple #5
0
    def test_reformat_nested_submachines(self):
        states = {
            'a': State({
                'a1': State({
                    'a11': State(),
                }),
                'a2': State({
                    'a12': State(),
                }),
            }),
            'b': State(
            [
                (
                    {
                        'sub1': State({
                            'sub1a': State(),
                            'sub1_ortho': State(
                            [
                                ({ 'deep1': State({ 'deep2': State() }), },
                                    {}),
                                ({ 'deep1': State({ 'deep2': State() }), },
                                    {}),
                            ]),
                        }),
                    },
                    { }),

                (
                    { 'sub2': State({
                        'sub2a': State(),
                        'sub2b': State({
                            'deep': State()
                        }),
                    })},
                    { }
                ),
            ])
        }
        exp_states = [
            composite('a', [
                composite('a1', [
                    leaf('a11'),
                ]),
                composite('a2', [
                    leaf('a12'),
                ]),
            ]),
            orthogonal('b', [
                composite('b[0].sub1', [
                    leaf('b[0].sub1a'),
                    orthogonal('b[0].sub1_ortho', [
                        composite('b[0].sub1_ortho[0].deep1', [
                            leaf('b[0].sub1_ortho[0].deep2') ]),
                        composite('b[0].sub1_ortho[1].deep1', [
                            leaf('b[0].sub1_ortho[1].deep2') ]),
                    ]),

                ]),
                composite('b[1].sub2', [
                    leaf('b[1].sub2a'),
                    composite('b[1].sub2b', [
                        leaf('b[1].deep')
                    ]),
                ]),
            ])
        ]

        assert reformat(states, {}) == (exp_states, {})