def test_remove_file(self): name = "remove_file" src_dir = self._get_source_directory(name) file_path = join(src_dir, "foo") self._make_sample_file(file_path) obj = Pydumpfs() obj.do(self.dest_dir, src_dir) remove(file_path) self._do_test(name)
def test_new_file(self): name = "new_file" src_dir = self._get_source_directory(name) file_path = join(src_dir, "foo") if isfile(file_path): remove(file_path) elif isdir(file_path): rmtree(file_path) obj = Pydumpfs() obj.do(self.dest_dir, src_dir) self._make_sample_file(file_path) self._do_test(name)
def _do_test(self, name): src_dir = self._get_source_directory(name) obj = Pydumpfs(**self._get_pydumpfs_options()) backup_dir = obj.do(self.dest_dir, src_dir) self._compare_dir_recursively(backup_dir, src_dir)
def test_change_mode(self): name = "change_mode" src_dir = self._get_source_directory(name) file_path = join(src_dir, "foo") chmod(file_path, S_IRWXU | S_IRWXG | S_IRWXO) obj = Pydumpfs(**self._get_pydumpfs_options()) backup_dir1 = obj.do(self.dest_dir, src_dir) chmod(file_path, S_IRUSR) backup_dir2 = obj.do(self.dest_dir, src_dir) path1 = backup_dir1 + file_path path2 = backup_dir2 + file_path self.failIf(samefile(path1, path2))
def test_change_gid(self): name = "change_gid" src_dir = self._get_source_directory(name) file_path = join(src_dir, "foo") self._change_gid(file_path, 1000) obj = Pydumpfs(**self._get_pydumpfs_options()) backup_dir1 = obj.do(self.dest_dir, src_dir) self._change_gid(file_path, 0) backup_dir2 = obj.do(self.dest_dir, src_dir) path1 = backup_dir1 + file_path path2 = backup_dir2 + file_path self.failIf(samefile(path1, path2))
def test_update_file(self): name = "update_file" src_dir = self._get_source_directory(name) file_path = join(src_dir, "foo") self._make_sample_file(file_path) obj = Pydumpfs() obj.do(self.dest_dir, src_dir) file = open(file_path, "a") try: print >> file, "bar" finally: file.close() self._do_test(name)
def test_no_dest_dir(self): dest_dir = join(self.dest_dir, "test_no_dest_dir") obj = Pydumpfs(**self._get_pydumpfs_options()) try: backup_dir \ = obj.do(dest_dir, self._get_source_directory("new_file")) except PydumpfsError: pass else: self.assert_(False, "Can backup to directory which doesn't exist.")
def test_hard_link(self): name = "hard_link" src_dir = self._get_source_directory(name) obj = Pydumpfs(**self._get_pydumpfs_options()) backup_dir1 = obj.do(self.dest_dir, src_dir) backup_dir2 = obj.do(self.dest_dir, src_dir) foo_src_path = join(src_dir, "foo") path1 = backup_dir1 + foo_src_path path2 = backup_dir2 + foo_src_path self.assert_(samefile(path1, path2), "%(path1)r's i-node and %(path2)r's one are not same." % dict(path1=path1, path2=path2))