Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/scryfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
"Jotun Grunt": "Jötun Grunt",
"Sol'kanar the Tainted": "Sol'Kanar the Tainted",
"Furnace Of Rath": "Furnace of Rath",
"Lim-Dul's Vault": "Lim-Dûl's Vault",
"Lim-Dûl's Vault": "Lim-Dûl's Vault",
# Ratonhnhaké꞉ton uses modifier letter colon (U+A789) in Scryfall, but ASCII colon in MTGO
"Ratonhnhaké:ton": "Ratonhnhaké꞉ton",
"Ratonhnhake:ton": "Ratonhnhaké꞉ton",
}

ALCHEMY_PREFIX = "A-"
Expand Down Expand Up @@ -74,6 +78,8 @@ def load_cache(self) -> bool:
else:
self._mappings = data
self._canonical_names = set()
self._mappings.update(STATIC_CORRECTIONS)
self._canonical_names.update(STATIC_CORRECTIONS.values())
logger.info(
"Loaded %d card mappings and %d canonical names from cache (%s)",
len(self._mappings),
Expand Down
35 changes: 35 additions & 0 deletions tests/test_scryfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,38 @@ def test_scryfall_normalizer_warning_on_unrecognized(tmp_path, caplog):
result = normalizer.normalize("Fake Card Name 12345")
assert result == "Fake Card Name 12345"
assert "Fake Card Name 12345" in caplog.text


def test_scryfall_normalizer_ratonhnhaketon(tmp_path, caplog):
cache_dir = tmp_path / ".cache"
cache_file = cache_dir / "scryfall_names.json"
cache_dir.mkdir(parents=True)

payload = {
"mappings": {},
"canonical": ["Ratonhnhaké\ua789ton", "Circle of Protection: Black"],
}
with open(cache_file, "w", encoding="utf-8") as f:
json.dump(payload, f)

normalizer = ScryfallNormalizer(cache_dir=str(cache_dir))

with caplog.at_level(logging.WARNING):
# Ratonhnhaké:ton with ASCII colon should normalize to modifier letter colon U+A789
assert normalizer.normalize("Ratonhnhaké:ton") == "Ratonhnhaké\ua789ton"
assert "not recognized" not in caplog.text

# Unaccented variation
assert normalizer.normalize("Ratonhnhake:ton") == "Ratonhnhaké\ua789ton"
assert "not recognized" not in caplog.text

# Already canonical form with U+A789
assert normalizer.normalize("Ratonhnhaké\ua789ton") == "Ratonhnhaké\ua789ton"
assert "not recognized" not in caplog.text

# Regular colon card should remain unchanged and recognized
assert (
normalizer.normalize("Circle of Protection: Black")
== "Circle of Protection: Black"
)
assert "not recognized" not in caplog.text
Loading