mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
Pattern.search() takes pos as its second argument, not flags, so passing re.IGNORECASE (value 2) started the serial scan at index 2. Filenames that begin with the serial itself (e.g. SCUS-94163.bin) never matched, and the PS1/PS2/PSP serial index resolution was silently skipped in the IGDB, MobyGames, and ScreenScraper handlers. The regex already matches both cases via [a-zA-Z], and the serial is uppercased before the Redis lookup (#3621), so the intended flag added nothing. Drop the stray argument so serials are found anywhere in the filename, including at the start. Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
"""Tests for the MobyGames metadata handler."""
|
|
|
|
import json
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from handler.metadata.base_handler import PS1_SERIAL_INDEX_KEY
|
|
from handler.metadata.moby_handler import PS1_MOBY_ID, MobyGamesHandler
|
|
from handler.redis_handler import async_cache
|
|
|
|
|
|
class TestSonySerialFilenames:
|
|
"""Tests for Sony serial resolution in get_rom."""
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_serial_at_filename_start_resolves_title(self):
|
|
"""A serial in the first two characters of the filename must still hit
|
|
the serial index. Regression: re.IGNORECASE was passed as the ``pos``
|
|
argument of ``Pattern.search()``, skipping the first two characters,
|
|
so files named by their serial (e.g. ``SCUS-94163.bin``) were never
|
|
resolved."""
|
|
handler = MobyGamesHandler()
|
|
|
|
with (
|
|
patch(
|
|
"handler.metadata.moby_handler.MobyGamesHandler.is_enabled",
|
|
return_value=True,
|
|
),
|
|
patch.object(async_cache, "hget", new_callable=AsyncMock) as mock_hget,
|
|
patch.object(
|
|
MobyGamesHandler,
|
|
"_search_rom",
|
|
new_callable=AsyncMock,
|
|
return_value=None,
|
|
),
|
|
):
|
|
mock_hget.return_value = json.dumps({"title": "Gran Turismo"})
|
|
result = await handler.get_rom("SCUS-94163.bin", PS1_MOBY_ID)
|
|
|
|
mock_hget.assert_awaited_once_with(PS1_SERIAL_INDEX_KEY, "SCUS-94163")
|
|
assert result.get("name") == "Gran Turismo"
|
|
assert result["moby_id"] is None
|