Exemplo n.º 1
0
 def test_create_new_tree_from_old_node_link_save_load(self):
     first_tree = TestImageTree.create_one_high_tree()
     first_tree_filename = 'tcntfonlsl.tsv'
     second_tree_filename = 'saveload_nl.tsv'
     if os.path.isfile(first_tree_filename):
         os.remove(first_tree_filename)
     if os.path.isfile(second_tree_filename):
         os.remove(second_tree_filename)
     first_tree.set_filename(first_tree_filename)
     serializer.save_tree(first_tree)
     quad_key = '321'
     new_link = first_tree.get_link()
     new_tree_result = tree_creator.create_new_from_old_insert_node_link(
         old_tree=first_tree,
         link_to_insert=new_link,
         quad_key=quad_key,
         new_tree_name='sln',
         filename=second_tree_filename)
     new_tree = new_tree_result.value
     serializer.save_tree_only_filename(new_tree, new_tree.filename)
     self.assertTrue(os.path.isfile(second_tree_filename))
     self.assertTrue(os.path.isfile(first_tree.filename))
     loaded_tree = serializer.load_link_new_serializer(new_tree.get_link())
     self.assertEqual(loaded_tree, new_tree)
     os.remove(second_tree_filename)
     os.remove(first_tree_filename)
Exemplo n.º 2
0
 def test_save_load_compact(self):
     filename = 'test_compact.tsv.gzip'
     tree = TestImageTree.create_one_high_tree(filename)
     serializer.save_tree(tree)
     loaded_tree = serializer.load_link_new_serializer(
         utilities.format_node_address(filename, node_name=tree.name))
     self.assertEqual(tree, loaded_tree)
     os.remove(filename)
Exemplo n.º 3
0
 def test_load_root_name(self):
     filename = 'test_load_root.tsv.gz'
     tree = TestImageTree.create_one_high_tree(filename=filename)
     serializer.save_tree(tree)
     loaded_tree = serializer.load_link_new_serializer(
         utilities.format_node_address(filename=filename, node_name='son'))
     self.assertEqual('son', loaded_tree.name)
     self.assertEqual(1, loaded_tree.height(max_height=7))
     os.remove(filename)
Exemplo n.º 4
0
 def test_save_load_infinite(self):
     tree = TestImageTree.create_one_high_tree()
     tree.get_children()[0] = tree
     filename = 'test_infinite.tsv.gz'
     tree.set_filename(filename)
     serializer.save_tree(tree)
     new_tree = serializer.load_link_new_serializer(
         utilities.format_node_address(filename=filename,
                                       node_name='father'))
     self.assertEqual('father', new_tree.name)
     os.remove(filename)
Exemplo n.º 5
0
 def test_save_load_random(self):
     tree = treegenerator.TreeGenerator.create_random_tree('ra',
                                                           4,
                                                           pixel=(0, 0, 0),
                                                           variance=1)
     filename = 'rat.tsv.gz'
     tree.set_filename(filename)
     root_link = utilities.format_node_address(filename, node=tree.name)
     serializer.save_tree(tree)
     another_tree = serializer.load_link_new_serializer(link=root_link)
     self.assertEqual(tree, another_tree)
     os.remove(filename)
Exemplo n.º 6
0
 def test_save_load_different_format(self):
     filename_extensions = ['.tsv', '.tsv.gz', '.itpb', '.itpb.gz']
     base_filename = 'sldf'
     for extension in filename_extensions:
         filename = base_filename + extension
         tree = TestImageTree.create_one_high_tree(filename)
         serializer.save_tree(tree)
         loaded_tree = serializer.load_link_new_serializer(
             utilities.format_node_address(filename, node_name=tree.name))
         self.assertEqual(tree.select(lambda x: x.name),
                          loaded_tree.select(lambda x: x.name))
         os.remove(filename)
Exemplo n.º 7
0
 def test_multiple_file_link_load(self):
     tree = TestImageTree.create_one_high_tree()
     second_filename = 'second.tsv.gz'
     tree._children_links[2] = utilities.format_node_address(
         filename=second_filename, node_name=tree.get_children()[2].name)
     tree.get_children()[2].filename = second_filename
     serializer.save_tree(tree)
     self.assertTrue(os.path.isfile(second_filename))
     link = tree.get_link()
     loaded_tree = serializer.load_link_new_serializer(link=link)
     self.assertEqual(loaded_tree, tree)
     os.remove(second_filename)
Exemplo n.º 8
0
 def test_create_new_tree_from_old_jpg_save_load(self):
     if os.path.isfile(TestImageTree.father_filename):
         os.remove(TestImageTree.father_filename)
     first_tree = TestImageTree.create_one_high_tree()
     serializer.save_tree(first_tree)
     quad_key = '021'
     new_link = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Maquette_EDM_salon_du_Bourget_2013_DSC_0192.JPG/273px-Maquette_EDM_salon_du_Bourget_2013_DSC_0192.JPG'
     filename = 'saveload_jpg.tsv'
     new_tree = tree_creator.create_new_from_old_insert_jpg(
         old_tree=first_tree,
         link_to_insert=new_link,
         quad_key=quad_key,
         new_tree_name='slj',
         filename=filename).value
     serializer.save_tree_only_filename(new_tree, new_tree.filename)
     self.assertTrue(os.path.isfile(filename))
     self.assertTrue(os.path.isfile(first_tree.filename))
     loaded_tree = serializer.load_link_new_serializer(new_tree.get_link())
     self.assertEqual(loaded_tree, new_tree)
     os.remove(filename)
     os.remove(first_tree.filename)
Exemplo n.º 9
0
 def test_create_new_tree_from_old_node_link(self):
     first_tree = TestImageTree.create_one_high_tree()
     first_tree_filename = 'tcntfonl0.tsv'
     if os.path.isfile(first_tree_filename):
         os.remove(first_tree_filename)
     first_tree.set_filename(first_tree_filename)
     serializer.save_tree(first_tree)
     quad_key = '01'
     new_link = first_tree.get_link()
     new_tree = tree_creator.create_new_from_old_insert_node_link(
         old_tree=first_tree,
         link_to_insert=new_link,
         quad_key=quad_key,
         new_tree_name='hosa',
         filename='newctfo.tsv').value
     self.assertEqual('hosa', new_tree.name)
     self.assertEqual(new_link,
                      new_tree.get_descendant(quad_key).get_link())
     self.assertEqual(TestImageTree.father_pixel,
                      tuple(new_tree.get_np_array(1).flatten()))
     self.assertEqual(
         TestImageTree.father_pixel,
         tuple(new_tree.get_descendant(quad_key).get_np_array(1).flatten()))
     os.remove(first_tree_filename)