def test_reshape(tmp_folder, tmp_files): num_files = len(tmp_files) tree = mj.Tree.plant(tmp_folder, 'my_third_tree') for file in tmp_files: s = mj.Atom(key='just_for_test') tree.grow(file, s) leaves = tree.leaves() for leaf in leaves: assert not leaf.is_compressed() assert len(tree.leaves()) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 tree.reshape(compress_all=True) weeds = tree.weeds() assert weeds['total_weeds'] == 0 leaves = tree.leaves() assert len(leaves) == num_files for leaf in leaves: assert leaf.is_compressed() tree.reshape(compress_all=False) weeds = tree.weeds() assert weeds['total_weeds'] == 0 leaves = tree.leaves() assert len(leaves) == num_files for leaf in leaves: assert not leaf.is_compressed() # Test that tree cannot be encrypted if there was no encryption key added to tree class with pytest.raises(mj.TreeError): tree.reshape(encrypt_all=True)
def several_atom_files(tmp_folder): zulus = mj.Zulu.range(n=30) atom = [mj.Atom(key='test_files__lots', zulu=x) for x in zulus] files = [mj.File.join(tmp_folder, f'{s}.txt') for s in atom] dev_create_test_files(files) yield files for file in files: file.delete(missing_ok=True)
def test_grow_compressed(tmp_folder, tmp_files): num_files = len(tmp_files) tree = mj.Tree.plant(tmp_folder, 'my_second_tree', compress_all=True) for file in tmp_files: s = mj.Atom(key='just_for_test') tree.grow(file, s) assert len(tree.leaves()) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0
def test_grow_encrypted(tmp_folder, tmp_files): num_files = len(tmp_files) tree = mj.Tree.plant(tmp_folder, 'my_second_tree', encrypt_all=True, encryption_key=mj.Crypt.generate_key()) for file in tmp_files: s = mj.Atom(key='just_for_test') tree.grow(file, s) assert len(tree.leaves()) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0
def test_prune(error, tmp_folder, several_atom_files): # TODO: Add negative levels, and None, and 0 to double check. num_files = len(several_atom_files) atom = mj.Atom(several_atom_files[0].stub()) if not len(atom.key.parts()) > 1: raise error(f'This test requires minimum two parts in key: {atom.key}') assert len(tmp_folder.list()) == num_files tree = mj.Tree.plant(tmp_folder, 'my_second_tree') for file in several_atom_files: tree.grow(file, delete_native=True) # Test if source has been deleted assert len(tmp_folder.list()) == 1 leaves = tree.leaves() assert len(leaves) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 assert len(tree._folder.list()) == 1 tree.reshape(key_level=0, date_level=0, time_level=0) leaves = tree.leaves() assert len(leaves) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 assert len(tree._folder.list()) == num_files tree.reshape(key_level=2, date_level=3, time_level=3) leaves = tree.leaves() assert len(leaves) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 assert len(tree._folder.list()) == 1 tree.reshape(key_level=0, date_level=0, time_level=0) leaves = tree.leaves() assert len(leaves) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 assert len(tree._folder.list()) == num_files tree.reshape(key_level=2, date_level=2, time_level=0) leaves = tree.leaves() assert len(leaves) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 assert len(tree._folder.list()) == 1 tree.reshape(key_level=1, date_level=2, time_level=2) leaves = tree.leaves() assert len(leaves) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 assert len(tree._folder.list()) == 1
def test_reshape_encrypted(tmp_folder, tmp_files): num_files = len(tmp_files) tree = mj.Tree.plant(tmp_folder, 'my_second_tree', encrypt_all=True, encryption_key=mj.Crypt.generate_key()) for file in tmp_files: s = mj.Atom(key='just_for_test') tree.grow(file, s) assert len(tree.leaves()) == num_files weeds = tree.weeds() assert weeds['total_weeds'] == 0 leaves = tree.leaves() assert len(leaves) == num_files for leaf in leaves: assert not leaf.is_compressed() assert leaf.is_encrypted() tree.reshape(compress_all=True) weeds = tree.weeds() assert weeds['total_weeds'] == 0 leaves = tree.leaves() assert len(leaves) == num_files for leaf in leaves: assert leaf.is_compressed() assert leaf.is_encrypted() tree.reshape(compress_all=False) weeds = tree.weeds() assert weeds['total_weeds'] == 0 leaves = tree.leaves() assert len(leaves) == num_files for leaf in leaves: assert not leaf.is_compressed() assert leaf.is_encrypted() tree.reshape(compress_all=False, encrypt_all=False) weeds = tree.weeds() assert weeds['total_weeds'] == 0 leaves = tree.leaves() assert len(leaves) == num_files for leaf in leaves: assert not leaf.is_compressed() assert not leaf.is_encrypted() tree.reshape(compress_all=True, encrypt_all=True) weeds = tree.weeds() assert weeds['total_weeds'] == 0 leaves = tree.leaves() assert len(leaves) == num_files for leaf in leaves: assert leaf.is_compressed() assert leaf.is_encrypted()
def several_atoms(): zulus = mj.Zulu.range(n=30) return [mj.Atom(key='test_files__lots', zulu=x) for x in zulus]