Ejemplo n.º 1
0
    def test_write_not_possible(self):
        v = VariableDesignator('Hello')

        with self.assertRaises(DeprecationWarning):
            v.current = "Goodbye"

        self.assertEqual(v.resolve(), "Hello")  # No change
Ejemplo n.º 2
0
    def test_basics(self):
        v = VariableDesignator('Hello')
        self.assertEqual(v.resolve(), "Hello")

        w = v.writeable
        w.write("Goodbye")
        self.assertEqual(v.resolve(), "Goodbye")
Ejemplo n.º 3
0
    def test_list_write_with_wrong_type(self):
        v = VariableDesignator(['a', 'b', 'c'])
        vw = v.writeable
        self.assertEqual(vw.resolve_type, [str])
        self.assertListEqual(v.resolve(), ['a', 'b', 'c'])

        with self.assertRaises(TypeError):
            vw.write([1, 2, 3, 4])
Ejemplo n.º 4
0
    def test_list_write(self):
        v = VariableDesignator(['a', 'b', 'c'])
        vw = v.writeable
        self.assertEqual(vw.resolve_type, [str])
        self.assertListEqual(v.resolve(), ['a', 'b', 'c'])

        vw.write(v.resolve() + ['d'])
        self.assertListEqual(v.resolve(), ['a', 'b', 'c', 'd'])
Ejemplo n.º 5
0
def make_legend():
    legend = Digraph('cluster_1')

    state = smach.State()
    parent_desig = Designator(
        name="parent_designator",
        resolve_type=[str])  # No resolve_type really needed but required
    desig = Designator(
        name="designator",
        resolve_type=[str])  # No resolve_type really needed but required
    vardesig = VariableDesignator(resolve_type=str, name="variable").writeable

    used_in_state = DesignatorUsedInState(state, desig, "role_resolved_from")
    written_in_state = DesignatorWrittenInState(state, vardesig,
                                                "role_written_to")
    used_in_desig = DesignatorUsedInDesignator(parent_desig, desig,
                                               "role_in_parent")

    usages = [used_in_state, written_in_state, used_in_desig]
    for usage in usages:
        usage.add_graphviz_edge(legend)

    legend.body.append('label = "Legend"')
    legend.body.append('color=black')
    legend.body.append('width=0.25')
    legend.body.append('height=0.25')
    legend.body.append('size="2.0, 2.0"')

    return legend
Ejemplo n.º 6
0
 def test_none_type_singular(self):
     with self.assertRaises(TypeError):
         v = VariableDesignator(resolve_type=None)
Ejemplo n.º 7
0
 def test_multi_element_type(self):
     with self.assertRaises(TypeError):
         v = VariableDesignator(resolve_type=[str, bool])
Ejemplo n.º 8
0
 def test_none_type_in_list(self):
     with self.assertRaises(TypeError):
         v = VariableDesignator(resolve_type=[None])
Ejemplo n.º 9
0
 def test_empty_list_type(self):
     with self.assertRaises(TypeError):
         v = VariableDesignator(resolve_type=[])
Ejemplo n.º 10
0
 def test_list(self):
     v = VariableDesignator(['a', 'b', 'c'])
     self.assertEqual(v.resolve_type, [str])
     self.assertListEqual(v.resolve(), ['a', 'b', 'c'])
Ejemplo n.º 11
0
 def test_current_deprecated(self):
     v = VariableDesignator('Hello')
     with self.assertRaises(DeprecationWarning):
         result = v.current
Ejemplo n.º 12
0
 def test_basics(self):
     v = VariableDesignator('Hello')
     self.assertEqual(v.resolve_type, str)
     self.assertEqual(v.resolve(), "Hello")
Ejemplo n.º 13
0
    def test_visited_and_unreachable(self):
        """In our RoboCup executives, we keep track of which items are 'processed' or visited,
        and which cannot be processed because they are unreachable.

        One way to do this, is to mark objectIDs (targets) as visited and unreachable in the reasoner,
        e.g. a global blackboard that can be manipulated an queried through Prolog.

        This gets messy with complex queries. With designators, it should be a lot simpler"""
        success = lambda goal: goal % 2  # Even targets will fail

        target_list = [i for i in range(10)] + [i for i in range(10)]  # all are in twice!
        targets = Designator(target_list)

        unreachable_set = set()
        unreachable = VariableDesignator(unreachable_set, resolve_type=set)

        visited_set = set()
        visited = VariableDesignator(visited_set, resolve_type=set)

        for target in target_list:
            if target not in unreachable.resolve() and target not in visited.resolve():
                print "Processing target {0}".format(target)
                if success(target):
                    visited.resolve().add(target)  # This is a set so no += [...]
                    print "Target {0} was successfull, its visited".format(target)
                else:
                    unreachable.resolve().add(target)  # This is a set so no += [...]
                    print "Target {0} failed, its unreachable".format(target)
            else:
                print "NOT processing target {0}: its unreachable or already visited".format(target)

        print "##### Done #####"
        print "These are unreachable: {0}".format(unreachable.resolve())
        print "These are visited: {0}".format(visited.resolve())

        self.assertEqual(len(unreachable.resolve()), 5)
        self.assertEqual(len(visited.resolve()), 5)
Ejemplo n.º 14
0
    def test_visited_and_unreachable(self):
        """In our RoboCup executives, we keep track of which items are 'processed' or visited,
        and which cannot be processed because they are unreachable.

        One way to do this, is to mark objectIDs (targets) as visited and unreachable in the reasoner,
        e.g. a global blackboard that can be manipulated an queried through Prolog.

        This gets messy with complex queries. With designators, it should be a lot simpler"""
        success = lambda goal: goal % 2  # Even targets will fail

        target_list = [i for i in range(10)] + [i for i in range(10)
                                                ]  # all are in twice!
        targets = Designator(target_list)

        unreachable_set = set()
        unreachable = VariableDesignator(unreachable_set, resolve_type=set)

        visited_set = set()
        visited = VariableDesignator(visited_set, resolve_type=set)

        for target in target_list:
            if target not in unreachable.resolve(
            ) and target not in visited.resolve():
                print("Processing target {0}".format(target))
                if success(target):
                    visited.resolve().add(
                        target)  # This is a set so no += [...]
                    print("Target {0} was successfull, its visited".format(
                        target))
                else:
                    unreachable.resolve().add(
                        target)  # This is a set so no += [...]
                    print("Target {0} failed, its unreachable".format(target))
            else:
                print(
                    "NOT processing target {0}: its unreachable or already visited"
                    .format(target))

        print("##### Done #####")
        print("These are unreachable: {0}".format(unreachable.resolve()))
        print("These are visited: {0}".format(visited.resolve()))

        self.assertEqual(len(unreachable.resolve()), 5)
        self.assertEqual(len(visited.resolve()), 5)