update pyright and some type annotations. also increase line length to 100 chars
Some checks failed
ci/woodpecker/push/tests Pipeline failed

Signed-off-by: Ivan Schaller <ivan@schaller.sh>
This commit is contained in:
Ivan Schaller 2023-07-02 16:40:09 +02:00
parent d7c5bd7d17
commit 873e6ab0e2
Signed by: olofvndrhr
GPG key ID: 2A6BE07D99C8C205
17 changed files with 316 additions and 182 deletions

View file

@ -75,6 +75,10 @@ install_deps_dev:
@echo "installing dependencies" @echo "installing dependencies"
@pip3 install -r contrib/requirements_dev.txt @pip3 install -r contrib/requirements_dev.txt
create_reqs:
@echo "creating requirements"
@pipreqs --savepath requirements.txt --mode gt --force mangadlp/
test_shfmt: test_shfmt:
@find . -type f \( -name "**.sh" -and -not -path "./.**" -and -not -path "./venv**" \) -exec shfmt -d -i 4 -bn -ci -sr "{}" \+; @find . -type f \( -name "**.sh" -and -not -path "./.**" -and -not -path "./venv**" \) -exec shfmt -d -i 4 -bn -ci -sr "{}" \+;

View file

@ -57,9 +57,7 @@ class Mangadex:
# get the uuid for the manga # get the uuid for the manga
def get_manga_uuid(self) -> str: def get_manga_uuid(self) -> str:
# isolate id from url # isolate id from url
uuid_regex = re.compile( uuid_regex = re.compile("[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}")
"[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}"
)
# try to get uuid in string # try to get uuid in string
try: try:
uuid = uuid_regex.search(self.url_uuid)[0] # type: ignore uuid = uuid_regex.search(self.url_uuid)[0] # type: ignore
@ -75,9 +73,7 @@ class Mangadex:
counter = 1 counter = 1
while counter <= 3: while counter <= 3:
try: try:
response = requests.get( response = requests.get(f"{self.api_base_url}/manga/{self.manga_uuid}", timeout=10)
f"{self.api_base_url}/manga/{self.manga_uuid}", timeout=10
)
except Exception as exc: except Exception as exc:
if counter >= 3: if counter >= 3:
log.error("Maybe the MangaDex API is down?") log.error("Maybe the MangaDex API is down?")
@ -118,9 +114,7 @@ class Mangadex:
break break
title = alt_title[self.language] # pyright:ignore title = alt_title[self.language] # pyright:ignore
except (KeyError, UnboundLocalError): except (KeyError, UnboundLocalError):
log.warning( log.warning("Manga title also not found in alt titles. Falling back to english title")
"Manga title also not found in alt titles. Falling back to english title"
)
else: else:
log.debug(f"Language={self.language}, Alt-title='{title}'") log.debug(f"Language={self.language}, Alt-title='{title}'")
return utils.fix_name(title) return utils.fix_name(title)
@ -139,9 +133,7 @@ class Mangadex:
try: try:
total_chapters: int = r.json()["total"] total_chapters: int = r.json()["total"]
except Exception as exc: except Exception as exc:
log.error( log.error("Error retrieving the chapters list. Did you specify a valid language code?")
"Error retrieving the chapters list. Did you specify a valid language code?"
)
raise exc raise exc
if total_chapters == 0: if total_chapters == 0:
log.error("No chapters available to download in specified language") log.error("No chapters available to download in specified language")
@ -190,9 +182,7 @@ class Mangadex:
continue continue
# export chapter data as a dict # export chapter data as a dict
chapter_index = ( chapter_index = chapter_num if not self.forcevol else f"{chapter_vol}:{chapter_num}"
chapter_num if not self.forcevol else f"{chapter_vol}:{chapter_num}"
)
chapter_data[chapter_index] = { chapter_data[chapter_index] = {
"uuid": chapter_uuid, "uuid": chapter_uuid,
"volume": chapter_vol, "volume": chapter_vol,

View file

@ -139,9 +139,7 @@ class MangaDLP:
# prechecks userinput/options # prechecks userinput/options
# no url and no readin list given # no url and no readin list given
if not self.url_uuid: if not self.url_uuid:
log.error( log.error('You need to specify a manga url/uuid with "-u" or a list with "--read"')
'You need to specify a manga url/uuid with "-u" or a list with "--read"'
)
raise ValueError raise ValueError
# checks if --list is not used # checks if --list is not used
if not self.list_chapters: if not self.list_chapters:
@ -179,9 +177,7 @@ class MangaDLP:
if self.chapters.lower() == "all": if self.chapters.lower() == "all":
chapters_to_download = self.manga_chapter_list chapters_to_download = self.manga_chapter_list
else: else:
chapters_to_download = utils.get_chapter_list( chapters_to_download = utils.get_chapter_list(self.chapters, self.manga_chapter_list)
self.chapters, self.manga_chapter_list
)
# show chapters to download # show chapters to download
log.info(f"Chapters selected: {', '.join(chapters_to_download)}") log.info(f"Chapters selected: {', '.join(chapters_to_download)}")
@ -192,9 +188,7 @@ class MangaDLP:
# prepare cache if specified # prepare cache if specified
if self.cache_path: if self.cache_path:
cache = CacheDB( cache = CacheDB(self.cache_path, self.manga_uuid, self.language, self.manga_title)
self.cache_path, self.manga_uuid, self.language, self.manga_title
)
cached_chapters = cache.db_uuid_chapters cached_chapters = cache.db_uuid_chapters
log.info(f"Cached chapters: {cached_chapters}") log.info(f"Cached chapters: {cached_chapters}")
@ -257,9 +251,7 @@ class MangaDLP:
{"Format": self.file_format[1:], **metadata}, {"Format": self.file_format[1:], **metadata},
) )
except Exception as exc: except Exception as exc:
log.warning( log.warning(f"Can't write metadata for chapter '{chapter}'. Reason={exc}")
f"Can't write metadata for chapter '{chapter}'. Reason={exc}"
)
# pack downloaded folder # pack downloaded folder
if self.file_format: if self.file_format:
@ -316,9 +308,7 @@ class MangaDLP:
# get image urls for chapter # get image urls for chapter
try: try:
chapter_image_urls = self.api.get_chapter_images( chapter_image_urls = self.api.get_chapter_images(chapter, self.download_wait)
chapter, self.download_wait
)
except KeyboardInterrupt as exc: except KeyboardInterrupt as exc:
log.critical("Keyboard interrupt. Stopping") log.critical("Keyboard interrupt. Stopping")
raise exc raise exc
@ -407,9 +397,7 @@ class MangaDLP:
# download images # download images
try: try:
downloader.download_chapter( downloader.download_chapter(chapter_image_urls, chapter_path, self.download_wait)
chapter_image_urls, chapter_path, self.download_wait
)
except KeyboardInterrupt as exc: except KeyboardInterrupt as exc:
log.critical("Keyboard interrupt. Stopping") log.critical("Keyboard interrupt. Stopping")
raise exc raise exc

View file

@ -1,9 +1,11 @@
import json import json
from pathlib import Path from pathlib import Path
from typing import Dict, List, Union from typing import List, Union
from loguru import logger as log from loguru import logger as log
from mangadlp.types import CacheData, CacheKeyData
class CacheDB: class CacheDB:
def __init__( def __init__(
@ -26,14 +28,12 @@ class CacheDB:
if not self.db_data.get(self.db_key): if not self.db_data.get(self.db_key):
self.db_data[self.db_key] = {} self.db_data[self.db_key] = {}
self.db_uuid_data = self.db_data[self.db_key] self.db_uuid_data: CacheKeyData = self.db_data[self.db_key]
if not self.db_uuid_data.get("name"): if not self.db_uuid_data.get("name"): # pyright:ignore
self.db_uuid_data.update({"name": self.name}) self.db_uuid_data.update({"name": self.name}) # pyright:ignore
self._write_db() self._write_db()
self.db_uuid_chapters: List[str] = ( self.db_uuid_chapters: List[str] = self.db_uuid_data.get("chapters") or [] # type:ignore
self.db_uuid_data.get("chapters") or [] # type:ignore
)
def _prepare_db(self) -> None: def _prepare_db(self) -> None:
if self.db_path.exists(): if self.db_path.exists():
@ -46,11 +46,11 @@ class CacheDB:
log.error("Can't create db-file") log.error("Can't create db-file")
raise exc raise exc
def _read_db(self) -> Dict[str, Dict[str, Union[str, List[str]]]]: def _read_db(self) -> CacheData:
log.info(f"Reading cache-db: {self.db_path}") log.info(f"Reading cache-db: {self.db_path}")
try: try:
db_txt = self.db_path.read_text(encoding="utf8") db_txt = self.db_path.read_text(encoding="utf8")
db_dict: Dict[str, Dict[str, Union[str, List[str]]]] = json.loads(db_txt) db_dict: CacheData = json.loads(db_txt)
except Exception as exc: except Exception as exc:
log.error("Can't load cache-db") log.error("Can't load cache-db")
raise exc raise exc

View file

@ -54,5 +54,4 @@ def download_chapter(
log.error("Can't write file") log.error("Can't write file")
raise exc raise exc
image_num += 1
sleep(download_wait) sleep(download_wait)

View file

@ -1,6 +1,6 @@
import logging import logging
import sys import sys
from typing import Any, Dict from typing import Any
from loguru import logger from loguru import logger
@ -24,22 +24,16 @@ class InterceptHandler(logging.Handler):
frame = frame.f_back # type: ignore frame = frame.f_back # type: ignore
depth += 1 depth += 1
logger.opt(depth=depth, exception=record.exc_info).log( logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage())
level, record.getMessage()
)
# init logger with format and log level # init logger with format and log level
def prepare_logger(loglevel: int = 20) -> None: def prepare_logger(loglevel: int = 20) -> None:
config: Dict[str, Any] = { stdout_handler: dict[str, Any] = {
"handlers": [
{
"sink": sys.stdout, "sink": sys.stdout,
"level": loglevel, "level": loglevel,
"format": LOGURU_FMT, "format": LOGURU_FMT,
} }
],
}
logging.basicConfig(handlers=[InterceptHandler()], level=loglevel) logging.basicConfig(handlers=[InterceptHandler()], level=loglevel)
logger.configure(**config) logger.configure(handlers=[stdout_handler])

View file

@ -10,9 +10,7 @@ METADATA_FILENAME = "ComicInfo.xml"
METADATA_TEMPLATE = Path("mangadlp/metadata/ComicInfo_v2.0.xml") METADATA_TEMPLATE = Path("mangadlp/metadata/ComicInfo_v2.0.xml")
# define metadata types, defaults and valid values. an empty list means no value check # define metadata types, defaults and valid values. an empty list means no value check
# {key: (type, default value, valid values)} # {key: (type, default value, valid values)}
METADATA_TYPES: Dict[ METADATA_TYPES: Dict[str, Tuple[Any, Union[str, int, None], List[Union[str, int, None]]]] = {
str, Tuple[Any, Union[str, int, None], List[Union[str, int, None]]]
] = {
"Title": (str, None, []), "Title": (str, None, []),
"Series": (str, None, []), "Series": (str, None, []),
"Number": (str, None, []), "Number": (str, None, []),
@ -72,14 +70,12 @@ def validate_metadata(metadata_in: ComicInfo) -> Dict[str, ComicInfo]:
# add default value if present # add default value if present
if metadata_default: if metadata_default:
log.debug( log.debug(f"Setting default value for Key:{key} -> value={metadata_default}")
f"Setting default value for Key:{key} -> value={metadata_default}"
)
metadata_valid["ComicInfo"][key] = metadata_default metadata_valid["ComicInfo"][key] = metadata_default
# check if metadata key is available # check if metadata key is available
try: try:
md_to_check: Union[str, int, None] = metadata_in[key] md_to_check: Union[str, int, None] = metadata_in[key] # pyright:ignore
except KeyError: except KeyError:
continue continue
# check if provided metadata item is empty # check if provided metadata item is empty
@ -87,19 +83,17 @@ def validate_metadata(metadata_in: ComicInfo) -> Dict[str, ComicInfo]:
continue continue
# check if metadata type is correct # check if metadata type is correct
log.debug(f"Key:{key} -> value={type(md_to_check)} -> check={metadata_type}") log.debug(
if not isinstance(md_to_check, metadata_type): f"Key:{key} -> value={type(md_to_check)} -> check={metadata_type}" # pyright:ignore
log.warning(
f"Metadata has wrong type: {key}:{metadata_type} -> {md_to_check}"
) )
if not isinstance(md_to_check, metadata_type):
log.warning(f"Metadata has wrong type: {key}:{metadata_type} -> {md_to_check}")
continue continue
# check if metadata is valid # check if metadata is valid
log.debug(f"Key:{key} -> value={md_to_check} -> valid={metadata_validation}") log.debug(f"Key:{key} -> value={md_to_check} -> valid={metadata_validation}")
if (len(metadata_validation) > 0) and (md_to_check not in metadata_validation): if (len(metadata_validation) > 0) and (md_to_check not in metadata_validation):
log.warning( log.warning(f"Metadata is invalid: {key}:{metadata_validation} -> {md_to_check}")
f"Metadata is invalid: {key}:{metadata_validation} -> {md_to_check}"
)
continue continue
log.debug(f"Updating metadata: '{key}' = '{md_to_check}'") log.debug(f"Updating metadata: '{key}' = '{md_to_check}'")

View file

@ -1,4 +1,4 @@
from typing import Optional, TypedDict from typing import List, Optional, TypedDict
class ComicInfo(TypedDict, total=False): class ComicInfo(TypedDict, total=False):
@ -48,3 +48,12 @@ class ChapterData(TypedDict):
chapter: str chapter: str
name: str name: str
pages: int pages: int
class CacheKeyData(TypedDict):
chapters: List[str]
name: str
class CacheData(TypedDict):
__root__: CacheKeyData

View file

@ -68,6 +68,12 @@ dependencies = [
"ruff>=0.0.247", "ruff>=0.0.247",
] ]
# black
[tool.black]
line-length = 100
target-version = ["py39"]
# pyright # pyright
[tool.pyright] [tool.pyright]
@ -97,13 +103,14 @@ select = [
"F", # pyflakes "F", # pyflakes
"RUF", # ruff specific "RUF", # ruff specific
] ]
line-length = 88 line-length = 100
fix = true fix = true
show-fixes = true show-fixes = true
format = "grouped" format = "grouped"
ignore-init-module-imports = true ignore-init-module-imports = true
respect-gitignore = true respect-gitignore = true
ignore = ["E501", "D103", "D100", "D102", "PLR2004"] ignore = ["E501", "D103", "D100", "D102", "PLR2004", "D403"]
#unfixable = ["F401"]
exclude = [ exclude = [
".direnv", ".direnv",
".git", ".git",
@ -120,6 +127,7 @@ exclude = [
[tool.ruff.per-file-ignores] [tool.ruff.per-file-ignores]
"__init__.py" = ["D104"] "__init__.py" = ["D104"]
"__about__.py" = ["D104", "F841"]
[tool.ruff.pylint] [tool.ruff.pylint]
max-args = 10 max-args = 10
@ -131,7 +139,7 @@ max-complexity = 10
convention = "google" convention = "google"
[tool.ruff.pycodestyle] [tool.ruff.pycodestyle]
max-doc-length = 88 max-doc-length = 100
# pytest # pytest

View file

@ -5,7 +5,9 @@ from mangadlp.app import MangaDLP
def test_check_api_mangadex(): def test_check_api_mangadex():
url = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
test = MangaDLP(url_uuid=url, list_chapters=True, download_wait=2) test = MangaDLP(url_uuid=url, list_chapters=True, download_wait=2)
assert test.api_used == Mangadex assert test.api_used == Mangadex

View file

@ -3,6 +3,7 @@ from pathlib import Path
import pytest import pytest
import requests import requests
from pytest import MonkeyPatch
from mangadlp import downloader from mangadlp import downloader
@ -17,7 +18,7 @@ def test_downloader():
] ]
chapter_path = Path("tests/test_folder1") chapter_path = Path("tests/test_folder1")
chapter_path.mkdir(parents=True, exist_ok=True) chapter_path.mkdir(parents=True, exist_ok=True)
images = [] images: list[str] = []
downloader.download_chapter(urls, str(chapter_path), 2) downloader.download_chapter(urls, str(chapter_path), 2)
for file in chapter_path.iterdir(): for file in chapter_path.iterdir():
images.append(file.name) images.append(file.name)
@ -28,7 +29,7 @@ def test_downloader():
shutil.rmtree(chapter_path, ignore_errors=True) shutil.rmtree(chapter_path, ignore_errors=True)
def test_downloader_fail(monkeypatch): def test_downloader_fail(monkeypatch: MonkeyPatch):
images = [ images = [
"https://uploads.mangadex.org/data/f1117c5e7aff315bc3429a8791c89d63/A1-c111d78b798f1dda1879334a3478f7ae4503578e8adf1af0fcc4e14d2a396ad4.png", "https://uploads.mangadex.org/data/f1117c5e7aff315bc3429a8791c89d63/A1-c111d78b798f1dda1879334a3478f7ae4503578e8adf1af0fcc4e14d2a396ad4.png",
"https://uploads.mangadex.org/data/f1117c5e7aff315bc3429a8791c89d63/A2-717ec3c83e8e05ed7b505941431a417ebfed6a005f78b89650efd3b088b951ec.png", "https://uploads.mangadex.org/data/f1117c5e7aff315bc3429a8791c89d63/A2-717ec3c83e8e05ed7b505941431a417ebfed6a005f78b89650efd3b088b951ec.png",

View file

@ -20,7 +20,9 @@ def test_no_read_and_url():
chapters = "1" chapters = "1"
file_format = "cbz" file_format = "cbz"
download_path = "tests" download_path = "tests"
command_args = f"-l {language} -c {chapters} --path {download_path} --format {file_format} --debug" command_args = (
f"-l {language} -c {chapters} --path {download_path} --format {file_format} --debug"
)
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
assert os.system(f"python3 {script_path} {command_args}") != 0 assert os.system(f"python3 {script_path} {command_args}") != 0
@ -30,7 +32,9 @@ def test_no_chaps():
language = "en" language = "en"
file_format = "cbz" file_format = "cbz"
download_path = "tests" download_path = "tests"
command_args = f"-u {url_uuid} -l {language} --path {download_path} --format {file_format} --debug" command_args = (
f"-u {url_uuid} -l {language} --path {download_path} --format {file_format} --debug"
)
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
assert os.system(f"python3 {script_path} {command_args}") != 0 assert os.system(f"python3 {script_path} {command_args}") != 0
@ -48,7 +52,7 @@ def test_no_volume():
def test_readin_list(): def test_readin_list():
list_file = "tests/test_list.txt" list_file = "tests/test_list.txt"
test_list = mdlpinput.readin_list(None, None, list_file) test_list = mdlpinput.readin_list(None, None, list_file) # pyright:ignore
assert test_list == [ assert test_list == [
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu", "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu",

View file

@ -4,21 +4,22 @@ import time
from pathlib import Path from pathlib import Path
import pytest import pytest
from pytest import MonkeyPatch
@pytest.fixture @pytest.fixture
def wait_10s(): def wait_10s(_: MonkeyPatch):
print("sleeping 10 seconds because of api timeouts") print("sleeping 10 seconds because of api timeouts")
time.sleep(10) time.sleep(10)
@pytest.fixture @pytest.fixture
def wait_20s(): def wait_20s(_: MonkeyPatch):
print("sleeping 20 seconds because of api timeouts") print("sleeping 20 seconds because of api timeouts")
time.sleep(20) time.sleep(20)
def test_manga_pre_hook(wait_10s): def test_manga_pre_hook(wait_10s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie" url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie"
manga_path = Path("tests/Shikimori's Not Just a Cutie") manga_path = Path("tests/Shikimori's Not Just a Cutie")
language = "en" language = "en"
@ -50,7 +51,7 @@ def test_manga_pre_hook(wait_10s):
hook_file.unlink() hook_file.unlink()
def test_manga_post_hook(wait_10s): def test_manga_post_hook(wait_10s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie" url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie"
manga_path = Path("tests/Shikimori's Not Just a Cutie") manga_path = Path("tests/Shikimori's Not Just a Cutie")
language = "en" language = "en"
@ -82,7 +83,7 @@ def test_manga_post_hook(wait_10s):
hook_file.unlink() hook_file.unlink()
def test_chapter_pre_hook(wait_10s): def test_chapter_pre_hook(wait_10s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie" url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie"
manga_path = Path("tests/Shikimori's Not Just a Cutie") manga_path = Path("tests/Shikimori's Not Just a Cutie")
language = "en" language = "en"
@ -114,7 +115,7 @@ def test_chapter_pre_hook(wait_10s):
hook_file.unlink() hook_file.unlink()
def test_chapter_post_hook(wait_10s): def test_chapter_post_hook(wait_10s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie" url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie"
manga_path = Path("tests/Shikimori's Not Just a Cutie") manga_path = Path("tests/Shikimori's Not Just a Cutie")
language = "en" language = "en"
@ -146,7 +147,7 @@ def test_chapter_post_hook(wait_10s):
hook_file.unlink() hook_file.unlink()
def test_all_hooks(wait_10s): def test_all_hooks(wait_10s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie" url_uuid = "https://mangadex.org/title/0aea9f43-d4a9-4bf7-bebc-550a512f9b95/shikimori-s-not-just-a-cutie"
manga_path = Path("tests/Shikimori's Not Just a Cutie") manga_path = Path("tests/Shikimori's Not Just a Cutie")
language = "en" language = "en"

View file

@ -5,12 +5,13 @@ from pathlib import Path
import pytest import pytest
import xmlschema import xmlschema
from pytest import MonkeyPatch
from mangadlp.metadata import validate_metadata, write_metadata from mangadlp.metadata import validate_metadata, write_metadata
@pytest.fixture @pytest.fixture
def wait_20s(): def wait_20s(_: MonkeyPatch):
print("sleeping 20 seconds because of api timeouts") print("sleeping 20 seconds because of api timeouts")
time.sleep(20) time.sleep(20)
@ -33,7 +34,7 @@ def test_metadata_creation():
"Format": "cbz", "Format": "cbz",
} }
write_metadata(metadata_path, metadata) write_metadata(metadata_path, metadata) # pyright:ignore
assert metadata_file.exists() assert metadata_file.exists()
read_in_metadata = metadata_file.read_text(encoding="utf8") read_in_metadata = metadata_file.read_text(encoding="utf8")
@ -59,7 +60,7 @@ def test_metadata_validation():
"Format": "cbz", "Format": "cbz",
} }
valid_metadata = validate_metadata(metadata) valid_metadata = validate_metadata(metadata) # pyright:ignore
assert valid_metadata["ComicInfo"] == { assert valid_metadata["ComicInfo"] == {
"Title": "title1", "Title": "title1",
@ -82,7 +83,7 @@ def test_metadata_validation_values():
"CommunityRating": 4, "CommunityRating": 4,
} }
valid_metadata = validate_metadata(metadata) valid_metadata = validate_metadata(metadata) # pyright:ignore
assert valid_metadata["ComicInfo"] == { assert valid_metadata["ComicInfo"] == {
"Notes": "Downloaded with https://github.com/olofvndrhr/manga-dlp", "Notes": "Downloaded with https://github.com/olofvndrhr/manga-dlp",
@ -101,7 +102,7 @@ def test_metadata_validation_values2():
"CommunityRating": 10, # invalid "CommunityRating": 10, # invalid
} }
valid_metadata = validate_metadata(metadata) valid_metadata = validate_metadata(metadata) # pyright:ignore
assert valid_metadata["ComicInfo"] == { assert valid_metadata["ComicInfo"] == {
"Notes": "Downloaded with https://github.com/olofvndrhr/manga-dlp", "Notes": "Downloaded with https://github.com/olofvndrhr/manga-dlp",
@ -110,8 +111,10 @@ def test_metadata_validation_values2():
} }
def test_metadata_chapter_validity(wait_20s): def test_metadata_chapter_validity(wait_20s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" url_uuid = (
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
)
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
metadata_path = manga_path / "Ch. 1 - Once In A Life Time Misfire/ComicInfo.xml" metadata_path = manga_path / "Ch. 1 - Once In A Life Time Misfire/ComicInfo.xml"
language = "en" language = "en"

View file

@ -1,11 +1,14 @@
import pytest import pytest
import requests import requests
from pytest import MonkeyPatch
from mangadlp.api.mangadex import Mangadex from mangadlp.api.mangadex import Mangadex
def test_uuid_link(): def test_uuid_link():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -33,7 +36,9 @@ def test_uuid_link_false():
def test_title(): def test_title():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -51,7 +56,9 @@ def test_alt_title():
def test_alt_title_fallback(): def test_alt_title_fallback():
url_uuid = "https://mangadex.org/title/d7037b2a-874a-4360-8a7b-07f2899152fd/mairimashita-iruma-kun" url_uuid = (
"https://mangadex.org/title/d7037b2a-874a-4360-8a7b-07f2899152fd/mairimashita-iruma-kun"
)
language = "fr" language = "fr"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -60,7 +67,9 @@ def test_alt_title_fallback():
def test_chapter_infos(): def test_chapter_infos():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -79,7 +88,9 @@ def test_chapter_infos():
def test_non_existing_manga(): def test_non_existing_manga():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-999999999999/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-999999999999/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
@ -88,12 +99,12 @@ def test_non_existing_manga():
assert e.type == KeyError assert e.type == KeyError
def test_api_failure(monkeypatch): def test_api_failure(monkeypatch: MonkeyPatch):
fail_url = ( fail_url = "https://api.mangadex.nonexistant/manga/a96676e5-8ae2-425e-b549-7f15dd34a6d8"
"https://api.mangadex.nonexistant/manga/a96676e5-8ae2-425e-b549-7f15dd34a6d8"
)
monkeypatch.setattr(requests, "get", fail_url) monkeypatch.setattr(requests, "get", fail_url)
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
@ -103,7 +114,9 @@ def test_api_failure(monkeypatch):
def test_chapter_lang_en(): def test_chapter_lang_en():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -112,7 +125,9 @@ def test_chapter_lang_en():
def test_empty_chapter_lang(): def test_empty_chapter_lang():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "ch" language = "ch"
forcevol = False forcevol = False
@ -122,7 +137,9 @@ def test_empty_chapter_lang():
def test_not_existing_lang(): def test_not_existing_lang():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "zz" language = "zz"
forcevol = False forcevol = False
@ -132,9 +149,7 @@ def test_not_existing_lang():
def test_create_chapter_list(): def test_create_chapter_list():
url_uuid = ( url_uuid = "https://mangadex.org/title/6fef1f74-a0ad-4f0d-99db-d32a7cd24098/fire-punch"
"https://mangadex.org/title/6fef1f74-a0ad-4f0d-99db-d32a7cd24098/fire-punch"
)
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -160,15 +175,76 @@ def test_create_chapter_list():
"19", "19",
"20", "20",
"21", "21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"34.5",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
"60",
"61",
"62",
"63",
"64",
"65",
"66",
"67",
"68",
"69",
"70",
"71",
"72",
"73",
"74",
"75",
"76",
"77",
"78",
"79",
"80",
"81",
"82",
"83",
] ]
assert test.create_chapter_list() == test_list assert test.create_chapter_list() == test_list
def test_create_chapter_list_forcevol(): def test_create_chapter_list_forcevol():
url_uuid = ( url_uuid = "https://mangadex.org/title/6fef1f74-a0ad-4f0d-99db-d32a7cd24098/fire-punch"
"https://mangadex.org/title/6fef1f74-a0ad-4f0d-99db-d32a7cd24098/fire-punch"
)
language = "en" language = "en"
forcevol = True forcevol = True
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -194,13 +270,78 @@ def test_create_chapter_list_forcevol():
"3:19", "3:19",
"3:20", "3:20",
"3:21", "3:21",
"3:22",
"3:23",
"3:24",
"3:25",
"3:26",
"3:27",
"3:28",
"4:29",
"4:30",
"4:31",
"4:32",
"4:33",
"4:34",
"4:34.5",
"4:35",
"4:36",
"4:37",
"4:38",
"4:39",
"5:40",
"5:41",
"5:42",
"5:43",
"5:44",
"5:45",
"5:46",
"5:47",
"5:48",
"5:49",
"6:50",
"6:51",
"6:52",
"6:53",
"6:54",
"6:55",
"6:56",
"6:57",
"6:58",
"6:59",
"6:60",
"7:61",
"7:62",
"7:63",
"7:64",
"7:65",
"7:66",
"7:67",
"7:68",
"7:69",
"7:70",
"8:71",
"8:72",
"8:73",
"8:74",
"8:75",
"8:76",
"8:77",
"8:78",
"8:79",
"8:80",
"8:81",
"8:82",
"8:83",
] ]
assert test.create_chapter_list() == test_list assert test.create_chapter_list() == test_list
def test_get_chapter_images(): def test_get_chapter_images():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -226,11 +367,11 @@ def test_get_chapter_images():
assert test.get_chapter_images(chapter_num, 2) == test_list assert test.get_chapter_images(chapter_num, 2) == test_list
def test_get_chapter_images_error(monkeypatch): def test_get_chapter_images_error(monkeypatch: MonkeyPatch):
fail_url = ( fail_url = "https://api.mangadex.org/at-home/server/e86ec2c4-c5e4-4710-bfaa-999999999999"
"https://api.mangadex.org/at-home/server/e86ec2c4-c5e4-4710-bfaa-999999999999" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
) )
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
@ -241,16 +382,18 @@ def test_get_chapter_images_error(monkeypatch):
def test_chapter_metadata(): def test_chapter_metadata():
url_uuid = "https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu" url_uuid = (
"https://mangadex.org/title/a96676e5-8ae2-425e-b549-7f15dd34a6d8/komi-san-wa-komyushou-desu"
)
language = "en" language = "en"
forcevol = False forcevol = False
test = Mangadex(url_uuid, language, forcevol) test = Mangadex(url_uuid, language, forcevol)
chapter_metadata = test.create_metadata("1") chapter_metadata = test.create_metadata("1")
manga_name = chapter_metadata["Series"] manga_name = chapter_metadata["Series"] # pyright:ignore
chapter_name = chapter_metadata["Title"] chapter_name = chapter_metadata["Title"] # pyright:ignore
chapter_num = chapter_metadata["Number"] chapter_num = chapter_metadata["Number"] # pyright:ignore
chapter_volume = chapter_metadata["Volume"] chapter_volume = chapter_metadata["Volume"] # pyright:ignore
chapter_url = chapter_metadata["Web"] chapter_url = chapter_metadata["Web"] # pyright:ignore
assert (manga_name, chapter_name, chapter_volume, chapter_num, chapter_url) == ( assert (manga_name, chapter_name, chapter_volume, chapter_num, chapter_url) == (
"Komi-san wa Komyushou Desu", "Komi-san wa Komyushou Desu",

View file

@ -5,27 +5,26 @@ import time
from pathlib import Path from pathlib import Path
import pytest import pytest
from pytest import MonkeyPatch
from mangadlp import app from mangadlp import app
@pytest.fixture @pytest.fixture
def wait_10s(): def wait_10s(_: MonkeyPatch):
print("sleeping 10 seconds because of api timeouts") print("sleeping 10 seconds because of api timeouts")
time.sleep(10) time.sleep(10)
@pytest.fixture @pytest.fixture
def wait_20s(): def wait_20s(_: MonkeyPatch):
print("sleeping 20 seconds because of api timeouts") print("sleeping 20 seconds because of api timeouts")
time.sleep(20) time.sleep(20)
def test_full_api_mangadex(wait_20s): def test_full_api_mangadex(wait_20s: MonkeyPatch):
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz"
)
mdlp = app.MangaDLP( mdlp = app.MangaDLP(
url_uuid="https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko", url_uuid="https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko",
language="en", language="en",
@ -44,16 +43,16 @@ def test_full_api_mangadex(wait_20s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
def test_full_with_input_cbz(wait_20s): def test_full_with_input_cbz(wait_20s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" url_uuid = (
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
)
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "cbz" file_format = "cbz"
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz"
)
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2" command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
os.system(f"python3 {script_path} {command_args}") os.system(f"python3 {script_path} {command_args}")
@ -64,16 +63,16 @@ def test_full_with_input_cbz(wait_20s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
def test_full_with_input_cbz_info(wait_20s): def test_full_with_input_cbz_info(wait_20s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" url_uuid = (
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
)
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "cbz" file_format = "cbz"
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz"
)
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --wait 2" command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --wait 2"
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
os.system(f"python3 {script_path} {command_args}") os.system(f"python3 {script_path} {command_args}")
@ -84,19 +83,17 @@ def test_full_with_input_cbz_info(wait_20s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
@pytest.mark.skipif( @pytest.mark.skipif(platform.machine() != "x86_64", reason="pdf only supported on amd64")
platform.machine() != "x86_64", reason="pdf only supported on amd64" def test_full_with_input_pdf(wait_20s: MonkeyPatch):
) url_uuid = (
def test_full_with_input_pdf(wait_20s): "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
url_uuid = "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" )
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "pdf" file_format = "pdf"
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.pdf")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.pdf"
)
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2" command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
os.system(f"python3 {script_path} {command_args}") os.system(f"python3 {script_path} {command_args}")
@ -107,16 +104,16 @@ def test_full_with_input_pdf(wait_20s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
def test_full_with_input_folder(wait_20s): def test_full_with_input_folder(wait_20s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" url_uuid = (
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
)
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "" file_format = ""
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire"
)
metadata_path = Path( metadata_path = Path(
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire/ComicInfo.xml" "tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire/ComicInfo.xml"
) )
@ -131,16 +128,16 @@ def test_full_with_input_folder(wait_20s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
def test_full_with_input_skip_cbz(wait_10s): def test_full_with_input_skip_cbz(wait_10s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" url_uuid = (
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
)
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "cbz" file_format = "cbz"
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz"
)
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2" command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
manga_path.mkdir(parents=True, exist_ok=True) manga_path.mkdir(parents=True, exist_ok=True)
@ -153,22 +150,22 @@ def test_full_with_input_skip_cbz(wait_10s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
def test_full_with_input_skip_folder(wait_10s): def test_full_with_input_skip_folder(wait_10s: MonkeyPatch):
url_uuid = "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" url_uuid = (
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
)
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "" file_format = ""
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire"
)
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format '{file_format}' --debug --wait 2" command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format '{file_format}' --debug --wait 2"
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
chapter_path.mkdir(parents=True, exist_ok=True) chapter_path.mkdir(parents=True, exist_ok=True)
os.system(f"python3 {script_path} {command_args}") os.system(f"python3 {script_path} {command_args}")
found_files = [] found_files: list[str] = []
for file in chapter_path.iterdir(): for file in chapter_path.iterdir():
found_files.append(file.name) found_files.append(file.name)
@ -184,17 +181,15 @@ def test_full_with_input_skip_folder(wait_10s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
def test_full_with_read_cbz(wait_20s): def test_full_with_read_cbz(wait_20s: MonkeyPatch):
url_list = Path("tests/test_list2.txt") url_list = Path("tests/test_list2.txt")
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "cbz" file_format = "cbz"
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz" command_args = f"--read {url_list!s} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
)
command_args = f"--read {str(url_list)} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
url_list.write_text( url_list.write_text(
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko" "https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
@ -208,17 +203,15 @@ def test_full_with_read_cbz(wait_20s):
shutil.rmtree(manga_path, ignore_errors=True) shutil.rmtree(manga_path, ignore_errors=True)
def test_full_with_read_skip_cbz(wait_10s): def test_full_with_read_skip_cbz(wait_10s: MonkeyPatch):
url_list = Path("tests/test_list2.txt") url_list = Path("tests/test_list2.txt")
language = "en" language = "en"
chapters = "1" chapters = "1"
file_format = "cbz" file_format = "cbz"
download_path = "tests" download_path = "tests"
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = Path( chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz" command_args = f"--read {url_list!s} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
)
command_args = f"--read {str(url_list)} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
script_path = "manga-dlp.py" script_path = "manga-dlp.py"
manga_path.mkdir(parents=True, exist_ok=True) manga_path.mkdir(parents=True, exist_ok=True)
chapter_path.touch() chapter_path.touch()

View file

@ -4,21 +4,22 @@ import time
from pathlib import Path from pathlib import Path
import pytest import pytest
from pytest import MonkeyPatch
@pytest.fixture @pytest.fixture
def wait_10s(): def wait_10s(_: MonkeyPatch):
print("sleeping 10 seconds because of api timeouts") print("sleeping 10 seconds because of api timeouts")
time.sleep(10) time.sleep(10)
@pytest.fixture @pytest.fixture
def wait_20s(): def wait_20s(_: MonkeyPatch):
print("sleeping 20 seconds because of api timeouts") print("sleeping 20 seconds because of api timeouts")
time.sleep(20) time.sleep(20)
def test_full_with_all_flags(wait_20s): def test_full_with_all_flags(wait_20s: MonkeyPatch):
manga_path = Path("tests/Tomo-chan wa Onna no ko") manga_path = Path("tests/Tomo-chan wa Onna no ko")
chapter_path = manga_path / "Ch. 1 - Once In A Life Time Misfire.cbz" chapter_path = manga_path / "Ch. 1 - Once In A Life Time Misfire.cbz"
cache_path = Path("tests/test_cache.json") cache_path = Path("tests/test_cache.json")