示例#1
0
 def setUp(self):
     self.root = UserInterfaceItem()
     self.child1 = UserInterfaceItem()
     self.child2 = UserInterfaceItem()
     self.subchild = UserInterfaceItem()
     self.root.add_child(self.child1)
     self.root.add_child(self.child2)
     self.child2.add_child(self.subchild)
     self.items = [self.root, self.child1, self.child2, self.subchild]
示例#2
0
class TestUIBase(unittest.TestCase):
    def setUp(self):
        self.root = UserInterfaceItem()
        self.child1 = UserInterfaceItem()
        self.child2 = UserInterfaceItem()
        self.subchild = UserInterfaceItem()
        self.root.add_child(self.child1)
        self.root.add_child(self.child2)
        self.child2.add_child(self.subchild)
        self.items = [self.root, self.child1, self.child2, self.subchild]

    def test_recursive_method(self):
        for item in self.items:
            item.mock = Mock()

        self.root.recursive_child_operation("mock")

        for item in self.items:
            self.assertTrue(item.mock.called)

    def test_relative_positions(self):
        data = [  # root, child2, subchild, subchild answer
            [Vector(0, 0), Vector(0, 0), Vector(0, 0), Vector(0, 0)],
            [Vector(10, 0), Vector(0, 10), Vector(-10, -10), Vector(0, 0)],
            [Vector(20, 10), Vector(3, 0), Vector(0, 7), Vector(23, 17)],
        ]

        for root, child2, subchild, result in data:
            self.root.position = root
            self.child2.position = child2
            self.subchild.position = subchild

            self.assertEqual(result, self.subchild.absolute_position)
示例#3
0
    def create_tag_dict(self):
        # Scoures all submodules of the akeldama package and imports each. This
        # ensures that the classes derived are all loaded, and thus registered.
        base_dir = os.path.dirname(akeldama.__file__)
        for _, name, _ in pkgutil.walk_packages([base_dir]):
            importlib.import_module(name, 'akeldama')

        # Get the registered classes
        classes = UserInterfaceItem.getDerivedClasses()
        self.tag_dict = dict()
        for clss in classes:
            self.tag_dict[clss.__name__] = clss

        logging.info('TAG DICT: {}'.format(self.tag_dict))