mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-18 09:23:26 -05:00
fix: make a patched test patch what actually runs
A test isolated the extra collection by patching resolve_platform_cores on packextras with create=True, while the module imported it inside the function, so the real resolver ran. The import is now module level, the test checks its stub was called, and no test may create the attribute it patches.
This commit is contained in:
1 parent
ef0023d78c
commit
e0bf0ee191
2 files changed
+25
-3
No files matched your search
@@ -14,6 +14,7 @@ from common import declared_root, expand_platform_declared_names, platform_decla
|
||||
from common import load_emulator_profiles
|
||||
from common import resolution_is_hash_exact
|
||||
from common import resolve_local_file
|
||||
from common import resolve_platform_cores
|
||||
from common import runs_standalone
|
||||
from common import sanitize_pack_path
|
||||
from common import size_fits
|
||||
@@ -616,7 +617,6 @@ def _collect_emulator_extras(
|
||||
|
||||
Works for ANY platform (RetroArch, Batocera, Recalbox, etc.)
|
||||
"""
|
||||
from common import resolve_platform_cores
|
||||
from verify import find_undeclared_files
|
||||
|
||||
profiles = (
|
||||
|
||||
@@ -479,6 +479,24 @@ class EverySharedGroupServesAPlatform(unittest.TestCase):
|
||||
self.assertEqual(sorted(groups - served), [])
|
||||
|
||||
|
||||
class PatchesTargetWhatRuns(unittest.TestCase):
|
||||
"""mock.patch.object with create set to True builds an attribute on a
|
||||
module when the name is missing: packextras imported resolve_platform_cores
|
||||
inside the function, the patch created a global nobody read, and the
|
||||
real function walked the repository while the test claimed to isolate
|
||||
it."""
|
||||
|
||||
def test_no_test_creates_the_attribute_it_patches(self):
|
||||
needle = "create" + "=True"
|
||||
offenders = []
|
||||
for path in sorted((ROOT / "tests").glob("test_*.py")):
|
||||
for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
|
||||
code = line.split("#", 1)[0]
|
||||
if needle in code:
|
||||
offenders.append(f"{path.name}:{number}")
|
||||
self.assertEqual(offenders, [])
|
||||
|
||||
|
||||
class FaqRegressions(unittest.TestCase):
|
||||
"""The FAQ states facts the code owns; these tie it back to the source.
|
||||
|
||||
@@ -2568,12 +2586,16 @@ class APinnedCoreFileTakesTheSlotFirst(unittest.TestCase):
|
||||
]
|
||||
config = {"systems": {}, "base_destination": "bios"}
|
||||
with mock.patch("verify.find_undeclared_files", return_value=undeclared), \
|
||||
mock.patch.object(packextras, "resolve_platform_cores", create=True,
|
||||
return_value=set()):
|
||||
mock.patch.object(packextras, "resolve_platform_cores",
|
||||
return_value=set()) as cores:
|
||||
extras = packextras._collect_emulator_extras(
|
||||
config, "emulators", {"files": {}, "indexes": {}}, set(), "bios", {}
|
||||
)
|
||||
self.assertEqual([e["source_profile"] for e in extras][:1], ["solarus"])
|
||||
# The stub is what ran: patched with create=True on a name the module
|
||||
# imported inside the function, it was never read and the real
|
||||
# resolve_platform_cores walked the repository's profiles.
|
||||
cores.assert_called_once()
|
||||
|
||||
|
||||
class ANameWithItsDirectoryIsTheDestination(unittest.TestCase):
|
||||
|
||||
Reference in new issue
Block a user