def test_add_file_and_modify(self): path = self.plain_folder + os.path.sep + "add_file_and_modify" fp = open(path, "wb") fp.write(b"hello world") fp.close() self.plain_tree = FileTree.from_fs(self.plain_folder) self.isPass() path = self.plain_folder + os.path.sep + "add_file_and_modify" fp = open(path, "wb") fp.write(b"hello world again") fp.close() self.plain_tree = FileTree.from_fs(self.plain_folder) self.plain_tree.get("add_file_and_modify").mtime += 1 self.isPass()
def test_add_file(self): path = self.plain_folder + os.path.sep + "add_file" fp = open(path, "wb") fp.write(b"hello world") fp.close() self.plain_tree = FileTree.from_fs(self.plain_folder) self.isPass()
def test_modify_file_in_folder(self): path = self.plain_tree.get("sync/file/modify").fs_path(self.plain_folder) fp = open(path, "wb") fp.write(b"hello world again") fp.close() self.plain_tree = FileTree.from_fs(self.plain_folder) self.plain_tree.get("sync/file/modify").mtime += 1 self.isPass()
def test_modify_file_in_folder(self): path = self.plain_tree.get("sync/file/modify").fs_path( self.plain_folder) fp = open(path, "wb") fp.write(b"hello world again") fp.close() self.plain_tree = FileTree.from_fs(self.plain_folder) self.plain_tree.get("sync/file/modify").mtime += 1 self.isPass()
def test_walk_tree_with_rule(self): clear_folder(self.directory_path) prepare_filetree(self.directory_path, ''' ignore/b/c:1 ignore/bb:2 include/d/e: 3 include/dd: 4 whatever_file: 5 ''') rule_set = FileRuleSet() rule_set.add_rule_by_string("ignore: name eq ignore") filetree = FileTree.from_fs(self.directory_path, rule_set=rule_set) self.assertEqual(len(filetree.files()), 3) self.assertEqual(len(filetree.folders()), 2)
def test_walk_tree_with_rule(self): clear_folder(self.directory_path) prepare_filetree( self.directory_path, ''' ignore/b/c:1 ignore/bb:2 include/d/e: 3 include/dd: 4 whatever_file: 5 ''') rule_set = FileRuleSet() rule_set.add_rule_by_string("ignore: name eq ignore") filetree = FileTree.from_fs(self.directory_path, rule_set=rule_set) self.assertEqual(len(filetree.files()), 3) self.assertEqual(len(filetree.folders()), 2)
def setUp(self): self.crypto = Crypto('password') self.plain_folder = mkdtemp() self.plain_folder_check = mkdtemp() self.encrypted_folder = mkdtemp() prepare_filetree(self.plain_folder, ''' sync_file_modify:hello world sync_file_delete:delete sync/file/modify:hello world empty_dir_delete/ not_empty_dir/dir2/dir3/file dir2/file2 ''') self.plain_tree = self.plain_tree = FileTree.from_fs(self.plain_folder) self.plain_tree_check = FileTree() self.encrypted_tree = FileTree() self.snapshot_tree = FileTree()
def test_walk_tree(self): prepare_filetree(self.directory_path, ''' a b/ c/d/e/f 1/2 ''') filetree = FileTree.from_fs(self.directory_path) self.assertEqual(filetree.get('a').isdir, False) self.assertEqual(filetree.get('b').isdir, True) self.assertEqual(filetree.get('c').isdir, True) self.assertEqual(filetree.get('c/d').isdir, True) self.assertEqual(filetree.get('c/d/e').isdir, True) self.assertEqual(filetree.get('c/d/e/f').isdir, False) self.assertEqual(filetree.get('1').isdir, True) self.assertEqual(filetree.get('1/2').isdir, False) self.assertEqual(len(filetree.files()), 3) self.assertEqual(len(filetree.folders()), 5)
def setUp(self): self.crypto = Crypto('password') self.plain_folder = mkdtemp() self.plain_folder_check = mkdtemp() self.encrypted_folder = mkdtemp() prepare_filetree( self.plain_folder, ''' sync_file_modify:hello world sync_file_delete:delete sync/file/modify:hello world empty_dir_delete/ not_empty_dir/dir2/dir3/file dir2/file2 ''') self.plain_tree = self.plain_tree = FileTree.from_fs(self.plain_folder) self.plain_tree_check = FileTree() self.encrypted_tree = FileTree() self.snapshot_tree = FileTree()
def test_walk_tree(self): prepare_filetree( self.directory_path, ''' a b/ c/d/e/f 1/2 ''') filetree = FileTree.from_fs(self.directory_path) self.assertEqual(filetree.get('a').isdir, False) self.assertEqual(filetree.get('b').isdir, True) self.assertEqual(filetree.get('c').isdir, True) self.assertEqual(filetree.get('c/d').isdir, True) self.assertEqual(filetree.get('c/d/e').isdir, True) self.assertEqual(filetree.get('c/d/e/f').isdir, False) self.assertEqual(filetree.get('1').isdir, True) self.assertEqual(filetree.get('1/2').isdir, False) self.assertEqual(len(filetree.files()), 3) self.assertEqual(len(filetree.folders()), 5)
def test_delete_non_empty_folder(self): path = self.plain_tree.get("not_empty_dir").fs_path(self.plain_folder) shutil.rmtree(path) self.plain_tree = FileTree.from_fs(self.plain_folder) self.isPass()
def test_delete_file(self): path = self.plain_tree.get("sync_file_delete").fs_path(self.plain_folder) os.remove(path) self.plain_tree = FileTree.from_fs(self.plain_folder) self.isPass()
def test_delete_file(self): path = self.plain_tree.get("sync_file_delete").fs_path( self.plain_folder) os.remove(path) self.plain_tree = FileTree.from_fs(self.plain_folder) self.isPass()