chore: hoist test imports to module level

This commit is contained in:
Abdessamad Derraz committed 2026-10-06 13:59:50 +02:00
1 parent 38655d1d23
commit 913ba09600
9 files changed
+31 -47

No files matched your search

+2 -2
View File
@@ -16,8 +16,8 @@ from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from common import load_platform_config, load_platform_registry
from generate_readme import extract_notes, extract_targets
from common import load_platform_config, load_platform_registry # noqa: E402
from generate_readme import extract_notes, extract_targets # noqa: E402
PLATFORMS = str(REPO_ROOT / "platforms")
+2 -2
View File
@@ -17,8 +17,8 @@ from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from cross_reference import FileConsumers
from generate_site import generate_system_page
from cross_reference import FileConsumers # noqa: E402
from generate_site import generate_system_page # noqa: E402
_TMP = tempfile.TemporaryDirectory()
_ROOT = Path(_TMP.name)
+8 -23
View File
@@ -10,17 +10,23 @@ exercised is a promise to contributors backed by nothing.
from __future__ import annotations
import importlib
import sys
import unittest
import urllib.error
from pathlib import Path
from unittest import mock
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from scraper import emudeck_scraper, libretro_scraper # noqa: E402
from scraper.base_scraper import ( # noqa: E402
BaseScraper,
BiosRequirement,
ChangeSet,
fetch_github_latest_version,
github_headers,
)
@@ -238,14 +244,9 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
@staticmethod
def _refuse(*_args, **_kwargs):
import urllib.error
raise urllib.error.HTTPError("https://api.github.com/x", 403, "rate limited", {}, None)
def test_every_pinned_scraper_raises(self):
import importlib
from unittest import mock
for name in (
"scraper.bizhawk_scraper",
"scraper.romm_scraper",
@@ -259,45 +260,29 @@ class UnreadableReleaseStopsTheScrape(unittest.TestCase):
module.Scraper()
def test_a_release_lookup_raises(self):
from unittest import mock
from scraper.base_scraper import fetch_github_latest_version
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
RuntimeError
):
fetch_github_latest_version("libretro/RetroArch")
def test_the_token_is_sent(self):
from unittest import mock
from scraper.base_scraper import github_headers
with mock.patch.dict("os.environ", {"GITHUB_TOKEN": "t0k"}):
self.assertEqual(github_headers()["Authorization"], "Bearer t0k")
def test_emudeck_cores_raise(self):
"""EmuDeck wrote cores: [] when the GitHub listing was refused."""
from unittest import mock
from scraper.emudeck_scraper import Scraper
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
RuntimeError
):
Scraper()._fetch_installed_emulators()
emudeck_scraper.Scraper()._fetch_installed_emulators()
def test_libretro_core_metadata_raises(self):
"""libretro dropped every system name and manufacturer when the
core-info listing was refused."""
from unittest import mock
from scraper.libretro_scraper import Scraper
with mock.patch("urllib.request.urlopen", self._refuse), self.assertRaises(
RuntimeError
):
Scraper()._fetch_core_metadata()
libretro_scraper.Scraper()._fetch_core_metadata()
if __name__ == "__main__":
+2 -3
View File
@@ -17,7 +17,8 @@ import yaml
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from generate_site import _availability_check, _file_badges
from common import load_database # noqa: E402
from generate_site import _availability_check, _file_badges # noqa: E402
SHA1 = "a" * 40
DB = {
@@ -40,8 +41,6 @@ class UnsourceableIsNotHeld(unittest.TestCase):
self.assertNotIn("in repo", badges)
def test_no_profile_entry_is_shown_held(self):
from common import load_database
db_path = REPO_ROOT / "database.json"
if not db_path.exists():
self.skipTest("database.json is not built")
+3 -3
View File
@@ -21,9 +21,9 @@ import yaml
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
import common
from common import build_zip_contents_index, compute_hashes
from generate_pack import generate_split_packs
import common # noqa: E402
from common import build_zip_contents_index, compute_hashes # noqa: E402
from generate_pack import generate_split_packs # noqa: E402
class SplitPartNames(unittest.TestCase):
+2 -4
View File
@@ -16,6 +16,7 @@ from __future__ import annotations
import os
import stat
import subprocess
import sys
import tempfile
import unittest
@@ -26,6 +27,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
import generate_pack as builder # noqa: E402
from artifacts import artifact_lock # noqa: E402
import split_pack # noqa: E402
LIMIT = 4096
@@ -141,10 +143,6 @@ class SplitHoldsTheDirectory(SplitFixture):
the pack the build had just written."""
def test_a_held_directory_is_left_alone(self):
import subprocess
from artifacts import artifact_lock
for target in (self.dist, self.pack):
with self.subTest(target=target.name), artifact_lock(str(self.dist)):
proc = subprocess.run(
+4 -5
View File
@@ -11,12 +11,16 @@ standalone_cores dropped them from its pack.
from __future__ import annotations
import json
import sys
import unittest
from pathlib import Path
import yaml
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from cross_reference import cross_reference # noqa: E402
DUAL_PROFILE = {
"emulator": "Dual",
@@ -73,11 +77,6 @@ class CrossReferenceReadsTheBuildThePlatformRuns(unittest.TestCase):
where verify and the pack builder found 26."""
def _gaps(self, standalone_cores):
import sys
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from cross_reference import cross_reference
empty_db = {"files": {}, "indexes": {}}
report = cross_reference(
{"dual": DUAL_PROFILE}, {}, empty_db, standalone_cores=standalone_cores
+2 -2
View File
@@ -17,8 +17,8 @@ from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from common import build_target_cores_cache
from generate_pack import _target_cores_for
from common import build_target_cores_cache # noqa: E402
from generate_pack import _target_cores_for # noqa: E402
class CheckReadsTheTargetLikeTheBuild(unittest.TestCase):
+6 -3
View File
@@ -19,7 +19,12 @@ from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from truth import _diff_system, _match_renames, _merge_file_into_system # noqa: E402
from truth import ( # noqa: E402
_diff_system,
_match_renames,
_merge_file_into_system,
generate_platform_truth,
)
def _entry(name: str, **hashes) -> dict:
@@ -205,8 +210,6 @@ class OnlySystemDirectoryEntries(unittest.TestCase):
verify deliberately leave them out of."""
def test_a_file_read_elsewhere_is_not_asked_of_the_platform(self):
from truth import generate_platform_truth
profiles = {
"core": {
"emulator": "Core",