def test_comic_archive_write_zipfile() -> None: tmp_dir, settings = _setup_write_zipfile(TEST_CBZ) assert not TEST_CBZ.is_file() Comic._comic_archive_write_zipfile(settings, TEST_CBZ, tmp_dir) assert TEST_CBZ.is_file() assert TEST_CBZ.stat().st_size == TEST_ZIP_SIZE _teardown()
def test_comic_archive_compress_exception() -> None: old_format = "CBR" _, _, _, settings = _setup_compress(old_format) nag_about_gifs = False TMP_ROOT.mkdir(exist_ok=True) path = TMP_ROOT / "XXXXX" args = (path, old_format, settings, nag_about_gifs) excepted = False try: Comic.comic_archive_compress(args) except Exception: excepted = True pass assert excepted _teardown()
def test_comic_archive_uncompress_invalid() -> None: comic_path, fmt, uncomp_dir, settings = _setup_uncompress("CBR") settings.comics = True res = Comic.comic_archive_uncompress(settings, comic_path, "XXX") assert res[0] is None assert res[1] is not None assert res[1].final_path == comic_path _teardown()
def test_comic_archive_uncompress_cbz() -> None: comic_path, fmt, uncomp_dir, settings = _setup_uncompress("CBZ") settings.comics = True tmp_dir, stats, comment = Comic.comic_archive_uncompress( settings, comic_path, fmt) assert tmp_dir == uncomp_dir assert stats is None assert comment == EMPTY_STR _teardown()
def test_comic_archive_uncompress_invalid() -> None: comic_path, fmt, uncomp_dir, settings = _setup_uncompress("CBR") settings.comics = True tmp_dir, stats, comment = Comic.comic_archive_uncompress( settings, comic_path, "XXX") assert tmp_dir is None assert stats is not None assert stats.final_path == comic_path assert comment is None _teardown()
def test_comic_archive_uncompress_cbr() -> None: comic_path, fmt, uncomp_dir, settings = _setup_uncompress("CBR") settings.comics = True settings.verbose = 0 tmp_dir, stats, comment = Comic.comic_archive_uncompress( settings, comic_path, fmt) assert tmp_dir == uncomp_dir assert stats is None assert comment == TEST_COMMENT _teardown()
def test_comic_archive_uncompress_unset() -> None: comic_path, fmt, uncomp_dir, settings = _setup_uncompress("CBZ") tmp_dir, stats, comment = Comic.comic_archive_uncompress( settings, comic_path, fmt) assert tmp_dir is None assert stats is not None assert stats.final_path == comic_path assert stats.bytes_in == 0 assert stats.bytes_out == 0 assert comment is None _teardown()
def test_comic_archive_compress_tmp_path() -> None: old_format = "CBZ" old_path, old_size, optimized_archive, settings = _setup_compress( old_format) nag_about_gifs = False args = (old_path, old_format, settings, nag_about_gifs) assert optimized_archive.is_file() res = Comic.comic_archive_compress(args) assert optimized_archive.is_file() assert res.bytes_in == old_size assert res.bytes_out == TEST_ZIP_SIZE assert TEST_CBZ.stat().st_size == TEST_ZIP_SIZE _teardown()
def test_comic_archive_compress() -> None: old_format = "CBR" old_path, old_size, optimized_archive, settings = _setup_compress( old_format) nag_about_gifs = False args = (old_path, old_format, settings, nag_about_gifs, TEST_COMMENT) assert not optimized_archive.is_file() res = Comic.comic_archive_compress(args) assert optimized_archive.is_file() assert res.bytes_in == old_size assert res.bytes_out == COMMENT_ZIP_SIZE assert TEST_CBZ.stat().st_size == COMMENT_ZIP_SIZE with zipfile.ZipFile(res.final_path, "r") as zf: assert zf.comment == TEST_COMMENT _teardown()
def test_get_archive_tmp_dir() -> None: path = Path("foo") res = Comic._get_archive_tmp_dir(path) assert res == Path("picopt_tmp_" + str(path))
def test_get_comic_format_dir() -> None: res = Comic.get_comic_format(COMIC_DIR) assert res is None
def _test_get_comic_fmt(src: Path, fmt: Optional[str]) -> None: res = Comic.get_comic_format(src) assert res == fmt
def test_comic_method() -> None: res = Comic.comics(Settings(), ExtArgs("a", "b")) assert res == "CBZ"
def _setup_write_zipfile(old_path: Path) -> Tuple[Path, Settings]: tmp_dir = Comic._get_archive_tmp_dir(old_path) tmp_dir.mkdir(exist_ok=True, parents=True) test_file = tmp_dir / "test.txt" test_file.write_text("x") return tmp_dir, Settings()