60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from sticker_downloader.config import ALL_FILE_TYPES, DownloadConfig, parse_file_types
|
|
from sticker_downloader.errors import InvalidFileType
|
|
|
|
|
|
@pytest.mark.parametrize("raw", ["", " ", None, "all", "ALL", " All "])
|
|
def test_blank_and_all_mean_everything(raw: str | None) -> None:
|
|
assert parse_file_types(raw) == frozenset(ALL_FILE_TYPES)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("raw", "expected"),
|
|
[
|
|
("webp", {"webp"}),
|
|
("webp,png", {"webp", "png"}),
|
|
(" WEBP , PNG ", {"webp", "png"}),
|
|
("webp png", {"webp", "png"}),
|
|
(".webp,.tgs", {"webp", "tgs"}),
|
|
("png,png", {"png"}),
|
|
],
|
|
)
|
|
def test_parses_explicit_type_lists(raw: str, expected: set[str]) -> None:
|
|
assert parse_file_types(raw) == frozenset(expected)
|
|
|
|
|
|
@pytest.mark.parametrize("raw", ["gif", "webp,gif", "jpeg", ",,,"])
|
|
def test_rejects_unsupported_types(raw: str) -> None:
|
|
with pytest.raises(InvalidFileType):
|
|
parse_file_types(raw)
|
|
|
|
|
|
def test_sorted_file_types_is_canonical_order() -> None:
|
|
config = DownloadConfig(file_types=frozenset({"png", "webp", "tgs"}))
|
|
assert config.sorted_file_types == ["webp", "tgs", "png"]
|
|
|
|
|
|
def test_wants_reports_membership() -> None:
|
|
config = DownloadConfig(file_types=frozenset({"webp"}))
|
|
assert config.wants("webp")
|
|
assert not config.wants("png")
|
|
|
|
|
|
def test_rejects_empty_type_set() -> None:
|
|
with pytest.raises(InvalidFileType):
|
|
DownloadConfig(file_types=frozenset())
|
|
|
|
|
|
def test_rejects_unknown_type_in_config() -> None:
|
|
with pytest.raises(InvalidFileType):
|
|
DownloadConfig(file_types=frozenset({"gif"}))
|
|
|
|
|
|
@pytest.mark.parametrize(("concurrency", "retries"), [(0, 3), (-1, 3), (1, 0)])
|
|
def test_rejects_nonsensical_limits(concurrency: int, retries: int) -> None:
|
|
with pytest.raises(ValueError):
|
|
DownloadConfig(concurrency=concurrency, retries=retries)
|