def test_eq(self) -> None: other_filesystem: BaseFileSystem = mock.Mock(spec=BaseFileSystem) other_path: Path = mock.Mock(spec=Path) assert self.sut == self.sut assert self.sut == CopyFile(self.filesystem, self.path) assert self.sut != CopyFile(other_filesystem, self.path) assert self.sut != CopyFile(self.filesystem, other_path) assert self.sut != CopyFileSystemObject(self.filesystem, self.path) assert self.sut != CopyDirectory(self.filesystem, self.path) assert self.sut != mock.Mock()
def test_copy_file_to_file(self) -> None: src_path: Path = Path("", "/some/file") dst_path: Path = Path("", "/another/file/name") content: bytes = b"random content" self.src_fs.file_write(src_path, content) self.sut.copy_file_to_file(CopyFile(self.src_fs, src_path), CopyFile(self.dst_fs, dst_path)) assert self.dst_fs.file_read(dst_path) == content
def test_copy_file_to_file(self) -> None: src_path: Path = random_local_path(root=self.src_tmp_dir.name)[0] dst_path: Path = random_path(self.bucket_name) content: bytes = randstr().encode() self.src_fs.file_write(src_path, content) self.sut.copy_file_to_file(CopyFile(self.src_fs, src_path), CopyFile(self.dst_fs, dst_path)) assert self.dst_fs.file_read(dst_path) == content
def test_copy_file_to_file(self) -> None: src_path: Path = random_path(self.src_bucket_name) dst_path: Path = random_path(self.dst_bucket_name) content: bytes = randstr().encode() self.fs.file_write(src_path, content) self.sut.copy_file_to_file(CopyFile(self.fs, src_path), CopyFile(self.fs, dst_path)) assert self.fs.file_read(dst_path) == content
def test_file(self) -> None: sub_name: str = mock.Mock(spec=str) sub_path: Path = self.path.child(sub_name) output: CopyFile = self.sut.file(sub_name) assert output == CopyFile(self.filesystem, sub_path)
def copy_dir_to_dir(self, src: CopyDirectory, dst: CopyDirectory) -> None: dir_path_str: str = src.fs.path_to_string(src.path) src_dir_tail: str = dir_path_str[dir_path_str.find("/") + 1:] dir_path_str = src.fs.path_to_string(dst.path) dst_dir_tail: str = dir_path_str[dir_path_str.find("/") + 1:] for src_obj_path in self._list_dir(src.path.drive, src_dir_tail): dst_obj_path: str = src_obj_path.replace(src_dir_tail, dst_dir_tail) if src_obj_path.endswith("/"): copy_source = { 'Bucket': src.path.drive, 'Key': src_obj_path } self._s3_client.copy(copy_source, dst.path.drive, dst_obj_path) else: src_file: CopyFile = CopyFile(src.fs, src.fs.parse_path(f'{src.path.drive}/{src_obj_path}')) dst_file: CopyFile = CopyFile(dst.fs, dst.fs.parse_path(f'{dst.path.drive}/{dst_obj_path}')) self.copy_file_to_file(src_file, dst_file)
def copy_object(self) -> CopyFileSystemObject: return CopyFile(self._fs, self._path)