test(parser): expand coverage for raw, torrent, and path parsers

Add 13 new test cases across three parser test files:
- raw_parser: Chinese 第二季, 2160p resolution, bracketed Season N, multi-group with Chinese punctuation, English-only title
- torrent_parser: EP format, tc/zh-tw subtitle, no-language subtitle (ValidationError), multi-level path, [NNvN] version suffix
- path_parser: season=2/no-offset, large positive offset, offset yielding exactly Season 1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Estrella Pan
2026-02-22 20:48:53 +01:00
parent fb2dd17c0c
commit 9d4bd48ce5
3 changed files with 140 additions and 0 deletions

View File

@@ -89,3 +89,57 @@ class TestGenSavePath:
result = TorrentPath._gen_save_path(bangumi)
assert "Season 1" in result # Would be -4, so uses original season
def test_gen_save_path_season_two_no_offset(self):
"""Non-S1 base season with no offset resolves directly."""
from module.downloader.path import TorrentPath
from module.models import Bangumi
bangumi = Bangumi(
official_title="Test Anime",
year="2024",
season=2,
season_offset=0,
title_raw="test",
)
with patch("module.downloader.path.settings") as mock_settings:
mock_settings.downloader.path = "/downloads/Bangumi"
result = TorrentPath._gen_save_path(bangumi)
assert "Season 2" in result
def test_gen_save_path_large_positive_offset(self):
"""Large positive offset adds correctly."""
from module.downloader.path import TorrentPath
from module.models import Bangumi
bangumi = Bangumi(
official_title="Test Anime",
year="2024",
season=1,
season_offset=5,
title_raw="test",
)
with patch("module.downloader.path.settings") as mock_settings:
mock_settings.downloader.path = "/downloads/Bangumi"
result = TorrentPath._gen_save_path(bangumi)
assert "Season 6" in result # 1 + 5
def test_gen_save_path_offset_yields_exactly_season_one(self):
"""Offset that resolves to exactly Season 1 is kept."""
from module.downloader.path import TorrentPath
from module.models import Bangumi
bangumi = Bangumi(
official_title="Test Anime",
year="2024",
season=2,
season_offset=-1,
title_raw="test",
)
with patch("module.downloader.path.settings") as mock_settings:
mock_settings.downloader.path = "/downloads/Bangumi"
result = TorrentPath._gen_save_path(bangumi)
assert "Season 1" in result # 2 - 1 = 1

View File

@@ -107,5 +107,55 @@ def test_raw_parser():
assert info.episode == 1
assert info.season == 1
# Chinese season number via CHINESE_NUMBER_MAP ("二" → 2)
content = "[LoliHouse] 关于我转生变成史莱姆这档事 第二季 / Tensei shitara Slime Datta Ken 2nd Season - 01 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕]"
info = raw_parser(content)
assert info.group == "LoliHouse"
assert info.title_zh == "关于我转生变成史莱姆这档事"
assert info.title_en == "Tensei shitara Slime Datta Ken 2nd Season"
assert info.resolution == "1080p"
assert info.episode == 1
assert info.season == 2
# 4K resolution (2160p) — RESOLUTION_RE covers 2160 but untested
content = "[NC-Raws] 葬送的芙莉莲 / Sousou no Frieren - 03 [B-Global][WEB-DL][2160p][AVC AAC][Multi Sub][MKV]"
info = raw_parser(content)
assert info.group == "NC-Raws"
assert info.title_zh == "葬送的芙莉莲"
assert info.title_en == "Sousou no Frieren"
assert info.resolution == "2160p"
assert info.episode == 3
assert info.season == 1
# English "Season N" format (bracketed) — season_rule "Season \d{1,2}" branch
content = "[LoliHouse] 狼与香辛料 [Season 2] / Spice and Wolf - 01 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕]"
info = raw_parser(content)
assert info.group == "LoliHouse"
assert info.title_zh == "狼与香辛料"
assert info.title_en == "Spice and Wolf"
assert info.resolution == "1080p"
assert info.episode == 1
assert info.season == 2
# Multi-group, Chinese punctuation in title, single-letter Latin prefix in EN title
content = "[北宇治字幕组&LoliHouse] 地。-关于地球的运动- / Chi. Chikyuu no Undou ni Tsuite - 03 [WebRip 1080p HEVC-10bit AAC ASSx2][简繁日内封字幕]"
info = raw_parser(content)
assert info.group == "北宇治字幕组&LoliHouse"
assert info.title_zh == "地。-关于地球的运动-"
assert info.title_en == "Chi. Chikyuu no Undou ni Tsuite"
assert info.resolution == "1080p"
assert info.episode == 3
assert info.season == 1
# English-only title — name_process returns title_zh=None when no CJK chars
content = "[动漫国字幕组&LoliHouse] THE MARGINAL SERVICE - 08 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕]"
info = raw_parser(content)
assert info.group == "动漫国字幕组&LoliHouse"
assert info.title_en == "THE MARGINAL SERVICE"
assert info.title_zh is None
assert info.resolution == "1080p"
assert info.episode == 8
assert info.season == 1

View File

@@ -91,6 +91,42 @@ def test_torrent_parser():
assert sf.season == 3
assert sf.language == "zh-tw"
# EP number format — RULES[4] EP? branch (untested without dash separator)
file_name = "[Ohys-Raws] Kamen Rider Gaim EP33 (TV-Asahi 1280x720 x264 AAC).mp4"
bf = torrent_parser(file_name)
assert bf.title == "Kamen Rider Gaim"
assert bf.group == "Ohys-Raws"
assert bf.episode == 33
assert bf.season == 1
# "tc" language code → zh-tw (SUBTITLE_LANG["zh-tw"] includes "tc")
file_name = "葬送的芙莉莲 S01E05.tc.ass"
sf = torrent_parser(file_name, file_type="subtitle")
assert sf.title == "葬送的芙莉莲"
assert sf.season == 1
assert sf.episode == 5
assert sf.language == "zh-tw"
# Subtitle with no language code → SubtitleFile.language requires str; raises ValidationError
file_name = "Dungeon Meshi S01E01.srt"
with pytest.raises(Exception):
torrent_parser(file_name, file_type="subtitle")
# Full absolute multi-level path — get_path_basename strips all directories
file_name = "/downloads/Bangumi/葬送的芙莉莲 (2023)/Season 1/葬送的芙莉莲 S01E05.mp4"
bf = torrent_parser(file_name)
assert bf.title == "葬送的芙莉莲"
assert bf.season == 1
assert bf.episode == 5
# Version suffix [NNvN] — RULES[1] (?:v\d{1,2})? branch (v2 supported but untested)
file_name = "[Sakurato] Kaguya-sama wa Kokurasetai [12v2][AVC-8bit 1080p AAC][CHS].mp4"
bf = torrent_parser(file_name)
assert bf.title == "Kaguya-sama wa Kokurasetai"
assert bf.group == "Sakurato"
assert bf.episode == 12
assert bf.season == 1
class TestGetPathBasename:
def test_regular_path(self):