示例#1
0
 def testStructure(self):
     tree = owyl.sequence(owyl.succeed(),
                          owyl.fail())
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['name', 'children'])
     self.assertEquals(structure,
                       {'name': 'sequence',
                        'children': [{'name': 'succeed', 'children': []},
                                     {'name': 'fail', 'children': []}]})
示例#2
0
    def testDescriptionSmallTree(self):
        tree = owyl.sequence(owyl.failAfter(after=10),
                             owyl.log('How did you execute me?'))

        viztree = OwylTree(tree)
        structure = truncate(viztree.get_structure(), ['name', 'desc', 'children'])
        self.assertEquals(structure, {'name': 'sequence', 'desc': '',
                                      'children': [{'name': 'failAfter', 'desc': '10',
                                                    'children': []},
                                                   {'name': 'log', 'desc': 'How did you execute me?',
                                                    'children': []}]})
示例#3
0
    def testYieldHookSmallTree(self):
        tree = owyl.sequence(owyl.succeed(),
                             owyl.fail())
        viztree = OwylTree(tree)
        structure = viztree.get_structure()

        mock = Mock()
        viztree.on_yield += [mock]
        tree = viztree.tree_with_hooks
        [x for x in owyl.visit(tree)]

        mock.assert_has_calls([call(structure['children'][0]['id'], True),
                               call(structure['children'][1]['id'], False),
                               call(structure['id'], False)])
示例#4
0
    def testHooksLog(self):
        tree = owyl.log('some message')
        viztree = OwylTree(tree)
        structure = viztree.get_structure()
        taskid = structure['id']

        mock = Mock()
        viztree.on_enter += [mock]
        viztree.on_yield += [mock]
        tree = viztree.tree_with_hooks
        [x for x in owyl.visit(tree)]

        mock.assert_has_calls([call(taskid),
                               call(taskid, True)])
示例#5
0
 def testStructureBig(self):
     tree = owyl.parallel(owyl.sequence(owyl.repeatAlways(blackboard.setBB()), owyl.log()),
                          owyl.selector(owyl.repeatUntilSucceed(blackboard.checkBB())),
                          owyl.repeatUntilFail(owyl.fail()))
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['name', 'children'])
     self.assertEquals(structure,
                       {'name': 'parallel',
                        'children': [{'name': 'sequence',
                                      'children': [{'name': 'repeatAlways',
                                                    'children': [{'name': 'setBB',
                                                                  'children': []}]},
                                                   {'name': 'log',
                                                    'children': []}]},
                                     {'name': 'selector',
                                      'children': [{'name': 'repeatUntilSucceed',
                                                    'children': [{'name': 'checkBB',
                                                                  'children': []}]}]},
                                     {'name': 'repeatUntilFail',
                                      'children': [{'name': 'fail',
                                                    'children': []}]}]})
示例#6
0
 def testDescriptionLog(self):
     tree = owyl.log('some message')
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['desc'])
     self.assertEquals(structure, {'desc': 'some message'})
示例#7
0
 def testDescriptionCheckBB(self):
     tree = blackboard.checkBB(key='somekey', check=lambda x: x == 3)
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['desc'])
     self.assertEquals(structure, {'desc': 'somekey'})
示例#8
0
 def testDescriptionSetBB(self):
     tree = blackboard.setBB(key='somekey', val=3)
     viztree = OwylTree(tree)
     structure = truncate(viztree.get_structure(), ['desc'])
     self.assertEquals(structure, {'desc': 'somekey 3'})