Beispiel #1
0
 def test_create_delete_tree(self):
     dbm = DBMan(config.LOSTConfig())
     tree = LabelTree(dbm)
     root_leaf = tree.create_root(ROOT_NAME, external_id=ROOT_EXTERNAL_ID)
     assert root_leaf.name == ROOT_NAME
     assert root_leaf.external_id == ROOT_EXTERNAL_ID
     assert tree.tree[root_leaf.idx] == root_leaf
     tree.delete_tree()
Beispiel #2
0
def tree_plus_childs():
    dbm = DBMan(config.LOSTConfig())
    tree = LabelTree(dbm)
    root_leaf = tree.create_root(ROOT_NAME, external_id=ROOT_EXTERNAL_ID)
    horse = tree.create_child(tree.root.idx,
                              CHILD_HORSE_NAME,
                              external_id=CHILD_HORSE_EXTERNAL_ID)
    cow = tree.create_child(tree.root.idx,
                            CHILD_COW_NAME,
                            external_id=CHILD_COW_EXTERNAL_ID)
    yield tree  # type: lost.logic.label.LabelTree
    tree.delete_tree()
Beispiel #3
0
    def test_import_df(self, tree_plus_childs):
        df = tree_plus_childs.to_df()
        df2 = df.copy()
        root_idx = df2[df2['parent_leaf_id'].isnull()].index.values[0]
        no_root_idx = df2[~df2['parent_leaf_id'].isnull()].index
        df2.loc[root_idx, 'name'] = 'second tree'
        df2.loc[root_idx, 'idx'] = 0
        df2.loc[no_root_idx, 'parent_leaf_id'] = 0

        dbm = DBMan(config.LOSTConfig())
        tree2 = LabelTree(dbm)
        root_leaf = tree2.import_df(df2)
        if root_leaf is None:
            raise Exception(
                'A label tree with name "{}" already exists. Clean your Test Database!'
                .format(df2.loc[root_idx, 'name']))
        for key, val in tree2.tree.items():
            print(val.to_df()[['idx', 'name', 'external_id',
                               'parent_leaf_id']])
        for ll in tree2.root.label_leaves:
            assert ll.name == CHILD_COW_NAME or ll.name == CHILD_HORSE_NAME
        tree2.delete_tree()
Beispiel #4
0
def tree():
    dbm = DBMan(config.LOSTConfig())
    tree = LabelTree(dbm)
    root_leaf = tree.create_root(ROOT_NAME, external_id=ROOT_EXTERNAL_ID)
    yield tree
    tree.delete_tree()