1
0

test: Add parameterized tests for parse_name function in myanimelist module

This commit is contained in:
Jon Michael Aanes (aider) 2025-03-16 22:08:40 +01:00
parent 87671dbd06
commit f492de825e

View File

@ -0,0 +1,19 @@
import pytest
from personal_data.fetchers.myanimelist import parse_name
@pytest.mark.parametrize("input_str, expected_group1, expected_group2", [
('"Soundscape"', "Soundscape", None),
('"Soundscape (サウンドスケープ)"', "Soundscape", "サウンドスケーブ"),
('1: "Soundscape"', "Soundscape", None),
('2: "Soundscape (サウンドスケーブ)"', "Soundscape", "サウンドスケーブ"),
])
def test_parse_name(input_str, expected_group1, expected_group2):
m = parse_name(input_str)
assert m is not None, f"parse_name returned None for input: {input_str}"
actual_group1 = m.group(1).strip() if m.group(1) is not None else None
actual_group2 = m.group(2).strip() if m.group(2) is not None else None
assert actual_group1 == expected_group1, f"Expected group(1): {expected_group1} but got: {actual_group1}"
if expected_group2 is None:
assert actual_group2 is None, f"Expected group(2) to be None but got: {actual_group2}"
else:
assert actual_group2 == expected_group2, f"Expected group(2): {expected_group2} but got: {actual_group2}"