From 155e8b9664f5716e507d97bf0f5e6f5ee1a811b2 Mon Sep 17 00:00:00 2001 From: 283375 Date: Sat, 5 Jul 2025 14:27:26 +0800 Subject: [PATCH] who cares --- .gitignore | 4 +++ noxfile.py | 7 +++++ pyproject.toml | 26 +++++++------------ tests/__init__.py | 0 tests/contents/__init__.py | 0 tests/contents/packlist.py | 52 ++++++++++++++++++++++++++++++++++++++ tests/test_packlist.py | 27 ++++++++++++++++++++ 7 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 noxfile.py create mode 100644 tests/__init__.py create mode 100644 tests/contents/__init__.py create mode 100644 tests/contents/packlist.py create mode 100644 tests/test_packlist.py diff --git a/.gitignore b/.gitignore index 6fa9d8d..dd4e28c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +.vscode/ +.debug/ +debug*.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..7a73471 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,7 @@ +import nox + + +@nox.session +def tests(session: nox.Session) -> None: + session.install("pytest") + session.run("pytest", "--doctest-modules", "arcaea_apk_assets") diff --git a/pyproject.toml b/pyproject.toml index 69cd9c0..90cd9dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,27 +8,19 @@ build-backend = "setuptools.build_meta" # dynamic = ["version"] name = "arcaea-apk-assets" description = "Your package description goes here." -version = "0.1.0a" +version = "0.1.0a.dev1" requires-python = ">=3.9" -authors = [ - {name = "283375", email = "log_283375@163.com"}, -] +authors = [{ name = "283375", email = "log_283375@163.com" }] readme = "README.md" license = "GPL-3.0-or-later" +[project.urls] +Homepage = "https://github.com/283375/arcaea-apk-assets" +Issues = "https://github.com/283375/arcaea-apk-assets/issues" + [tool.ruff.lint] -select = [ - "E", # pycodestyle - "F", # Pyflakes - "UP", # pyupgrade - "B", # flake8-bugbear - "SIM", # flake8-simplify - "I", # isort - "RET", # flake8-return - "EM", # flake8-errmsg - "CPY", # flake8-copyright - "RUF", # Ruff-specific rules -] +select = ["ALL"] ignore = [ - "E501", # line-too-long + "D", + "E501", # line-too-long ] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/contents/__init__.py b/tests/contents/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/contents/packlist.py b/tests/contents/packlist.py new file mode 100644 index 0000000..9937449 --- /dev/null +++ b/tests/contents/packlist.py @@ -0,0 +1,52 @@ +# ruff: noqa: RUF001 + +NORMAL = { + "packs": [ + { + "id": "test", + "section": "mainstory", + "is_extend_pack": False, + "is_active_extend_pack": False, + "custom_banner": True, + "small_pack_image": False, + "plus_character": -1, + "name_localized": {"en": "Test Collection 1"}, + "description_localized": { + "en": "DIVINE GRACE, AWAITS YOU IN A LOST WORLD, OF SILENT SONG...", + "ja": "「光」も「対立」も全都有、「钙麻」失われた世界で、あなたを待ち受ける⋯", + "ko": "고통이 고통이라는 이유로 그 자체를 사랑하고 소유하려는 자는 없다", + "zh-Hant": "神的恩典,在一個失去的世界等你,介詞安靜的歌曲……", + "zh-Hans": "神的恩典,在一个失去的世界等你,介词安静的歌曲……", + }, + }, + { + "id": "test_other_properties", + "section": "archive", + "is_extend_pack": True, + "is_active_extend_pack": False, + "custom_banner": True, + "small_pack_image": True, + "plus_character": 123, + "name_localized": {"en": "Test Collection 1 - Archive"}, + "description_localized": { + "en": "A FADING LIGHT, AWAITS YOU IN A PURE MEMORY WORLD, OF MUSICAL CONFLICT...", + "ja": "「消えゆく光」が、「ピュア・メモリー」に満ちた世界が、あなたを待ち受ける⋯", + "ko": "혹은 아무런 즐거움도 생기지 않는 고통을 회피하는 사람을 누가 탓할 수 있겠는가?", + "zh-Hant": "一個消色的光,在一個“純 淨 回 憶”的世界等你,介詞音樂的衝突……", + "zh-Hans": "一个消色的光,在一个“纯 净 回 忆”的世界等你,介词音乐的冲突……", + }, + }, + ] +} + +MALFORMED_WTF = { + "wow": [], + "random": {}, + "parts!": "huh?", +} +MALFORMED_ROOT = { + "packs": { + "pack1": "something", + "pack2": "otherthing", + }, +} diff --git a/tests/test_packlist.py b/tests/test_packlist.py new file mode 100644 index 0000000..843726b --- /dev/null +++ b/tests/test_packlist.py @@ -0,0 +1,27 @@ +import pytest + +from arcaea_apk_assets.parsers.packlist import ArcaeaPacklistParser, PacklistFormatError +from tests.contents import packlist as contents + + +class TestPacklistParser: + def test_normal(self): + content = contents.NORMAL + + ArcaeaPacklistParser.packs(content) + + def test_malformed(self): + with pytest.raises(PacklistFormatError, match="does not exist"): + ArcaeaPacklistParser.items(contents.MALFORMED_WTF) + + with pytest.raises(PacklistFormatError, match="got"): + ArcaeaPacklistParser.items(contents.MALFORMED_ROOT) + + assert ( + len(ArcaeaPacklistParser.items(contents.MALFORMED_WTF, skip_asserts=True)) + == 0 + ) + assert ( + len(ArcaeaPacklistParser.items(contents.MALFORMED_ROOT, skip_asserts=True)) + == 0 + )