From 5f18caec31635e6b20ecd0d42b1d738e5cce3d2d Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:11:23 +0100 Subject: [PATCH] refactor: put scripts/ on the test path once tests/__init__ now puts the repository root and scripts/ on sys.path, so no test module inserts them and every import sits in the import block. ruff accepts the bare `import tests` the modules keep for its side effects. The last suppressions go: helper test modules import as tests., files open in with blocks, lambdas become functions. --- pyproject.toml | 4 + tests/__init__.py | 7 ++ tests/test_adler32_resolution.py | 8 +- tests/test_agnostic_scan.py | 12 +-- tests/test_agnostic_scan_mode.py | 4 +- tests/test_agnostic_scope.py | 4 +- tests/test_agnostic_substitute.py | 8 +- tests/test_amberelec_targets.py | 9 +-- tests/test_arcade_parents.py | 8 +- tests/test_archive_build.py | 9 +-- tests/test_archive_choice.py | 4 +- tests/test_archive_recipes.py | 4 +- tests/test_artifact_lock.py | 15 ++-- tests/test_atomic_artifacts.py | 7 +- tests/test_audit_regressions.py | 31 +------- tests/test_auto_fetch_lookup.py | 8 +- tests/test_autorun.py | 13 ++- tests/test_batocera_cores.py | 5 +- tests/test_batocera_md5_list.py | 28 +++---- tests/test_bios_companions.py | 8 +- tests/test_bios_layout.py | 2 +- tests/test_bundled_identity.py | 8 +- tests/test_cache_independent_counts.py | 4 +- tests/test_campaign.py | 5 +- tests/test_case_insensitive_platforms.py | 7 +- tests/test_casefold_cache.py | 8 +- tests/test_check_freshness.py | 9 +-- tests/test_check_release.py | 6 +- tests/test_checks_have_values.py | 4 +- tests/test_cited_lines.py | 10 +-- tests/test_content_checks.py | 16 ++-- tests/test_content_declarations.py | 6 +- tests/test_contributing_text.py | 10 +-- tests/test_core_data_trees.py | 12 ++- tests/test_core_file_fills_declaration.py | 12 ++- tests/test_core_probe.py | 4 +- tests/test_core_size_refusal.py | 16 ++-- tests/test_coverage_cache.py | 8 +- tests/test_cross_reference_sources.py | 10 +-- tests/test_crypto_aes.py | 8 +- tests/test_crypto_unique_data.py | 10 +-- tests/test_crypto_verify.py | 10 +-- tests/test_data_dir_refs.py | 4 +- tests/test_data_only_refs.py | 4 +- tests/test_dataclass_defaults.py | 2 +- tests/test_db_aliases.py | 6 +- tests/test_declared_names.py | 10 +-- tests/test_dedup.py | 8 +- tests/test_derivations.py | 8 +- tests/test_deterministic_zip.py | 2 +- tests/test_directory_entries.py | 20 ++--- tests/test_doc_pages.py | 7 +- tests/test_doc_surfaces.py | 12 ++- tests/test_download.py | 7 +- tests/test_e2e.py | 17 +--- tests/test_elec_scrapers.py | 12 ++- tests/test_emuelec_targets.py | 8 +- tests/test_emulator_pack_counts.py | 3 +- tests/test_entry_categories.py | 6 +- tests/test_export_counts.py | 28 +++---- tests/test_export_native_layer.py | 9 +-- tests/test_export_report.py | 5 +- tests/test_exporters.py | 21 ++--- tests/test_extra_identity.py | 12 ++- tests/test_extract_targets.py | 11 +-- tests/test_fbneo_parser.py | 2 +- tests/test_file_consumers.py | 10 +-- tests/test_fileless_audit.py | 4 +- tests/test_finalize_pack_names.py | 6 +- tests/test_find_embedded.py | 7 +- tests/test_find_pinned_revision.py | 11 +-- tests/test_flycast_layout.py | 2 +- tests/test_foreign_tree.py | 10 +-- tests/test_foreign_tree_names.py | 8 +- tests/test_frontend_digest.py | 11 ++- tests/test_game_catalogs.py | 9 +-- tests/test_game_data_homonyms.py | 10 +-- tests/test_game_headers.py | 10 +-- tests/test_game_regions.py | 10 +-- tests/test_games_index.py | 10 +-- tests/test_gap_settlement.py | 10 +-- tests/test_handheld_launchers.py | 7 +- tests/test_hash_merge.py | 2 +- tests/test_hashing.py | 8 +- tests/test_hidden_extras.py | 8 +- tests/test_identity.py | 5 +- tests/test_install.py | 30 ++----- tests/test_install_app.py | 11 +-- tests/test_install_cores.py | 12 +-- tests/test_install_experience.py | 13 +-- tests/test_install_expert.py | 3 +- tests/test_install_filesystems.py | 11 +-- tests/test_install_from.py | 14 ++-- tests/test_install_games.py | 7 +- tests/test_install_journeys.py | 12 ++- tests/test_install_offline.py | 20 ++--- tests/test_install_pack.py | 2 +- tests/test_install_removal.py | 11 +-- tests/test_install_selection.py | 8 +- tests/test_install_tui.py | 97 ++++++++++------------- tests/test_lakka_targets.py | 2 +- tests/test_large_file_cache.py | 5 +- tests/test_launcher_aliases.py | 2 +- tests/test_launcher_evidence.py | 5 +- tests/test_launcher_gaps.py | 4 +- tests/test_launcher_layer.py | 5 +- tests/test_launcher_paths.py | 14 ++-- tests/test_launcher_placement.py | 14 ++-- tests/test_launchers.py | 12 ++- tests/test_launchers_amberelec.py | 10 +-- tests/test_launchers_emudeck.py | 12 ++- tests/test_launchers_emuelec.py | 12 ++- tests/test_launchers_knulli.py | 12 ++- tests/test_launchers_recalbox.py | 14 ++-- tests/test_launchers_retrobat.py | 10 +-- tests/test_launchers_retrodeck.py | 8 +- tests/test_launchers_retropie.py | 10 +-- tests/test_launchers_rocknix.py | 12 ++- tests/test_libretro_layout.py | 12 ++- tests/test_libretro_slugs.py | 4 +- tests/test_maker_folder_names.py | 15 ++-- tests/test_mame_devices.py | 7 +- tests/test_mame_parser.py | 2 +- tests/test_mame_ref_audit.py | 5 +- tests/test_manifest_entry.py | 10 +-- tests/test_md5_pack_context.py | 3 +- tests/test_measurements.py | 19 +++-- tests/test_minui_platform.py | 11 +-- tests/test_name_tiebreak.py | 8 +- tests/test_native_mode.py | 12 +-- tests/test_nec_filing.py | 4 +- tests/test_no_case_collisions.py | 8 +- tests/test_no_game_data.py | 18 ++--- tests/test_np2_fonts.py | 8 +- tests/test_optional_dependencies.py | 2 +- tests/test_owner_resolution.py | 14 ++-- tests/test_pack_conformance_dirs.py | 10 +-- tests/test_pack_core_extras.py | 8 +- tests/test_pack_counts.py | 27 +++---- tests/test_pack_destinations.py | 4 +- tests/test_pack_failures.py | 8 +- tests/test_pack_file_names.py | 7 +- tests/test_pack_grouping.py | 4 +- tests/test_pack_integrity.py | 5 +- tests/test_pack_member_identity.py | 8 +- tests/test_pack_probe.py | 13 ++- tests/test_pack_readme.py | 8 +- tests/test_path_conflict_status.py | 14 ++-- tests/test_path_null_copies.py | 4 +- tests/test_path_suffix.py | 5 +- tests/test_pin_build.py | 8 +- tests/test_platform_inheritance.py | 8 +- tests/test_platform_keys.py | 4 +- tests/test_port.py | 7 +- tests/test_profile_checks.py | 8 +- tests/test_profile_names.py | 8 +- tests/test_profile_paths.py | 2 +- tests/test_profile_repositories.py | 10 +-- tests/test_profile_sync.py | 5 +- tests/test_prose_style.py | 5 +- tests/test_proven_name.py | 10 +-- tests/test_provenance.py | 2 +- tests/test_pypi_package.py | 7 +- tests/test_refresh_data_dirs.py | 10 +-- tests/test_refresh_failures.py | 7 +- tests/test_refresh_stale.py | 7 +- tests/test_region.py | 8 +- tests/test_region_agnostic_scan.py | 4 +- tests/test_region_check.py | 8 +- tests/test_region_groups.py | 8 +- tests/test_region_held.py | 8 +- tests/test_region_platform_index.py | 8 +- tests/test_region_required_only.py | 7 +- tests/test_release_packs.py | 9 +-- tests/test_report_excerpt.py | 9 +-- tests/test_required_only_archives.py | 2 +- tests/test_required_only_twins.py | 12 +-- tests/test_resolution_evidence.py | 8 +- tests/test_retired_files.py | 8 +- tests/test_retrodeck_scraper_errors.py | 9 +-- tests/test_romfolders_card.py | 18 ++--- tests/test_romfolders_es.py | 5 +- tests/test_romm_hash_rule.py | 12 ++- tests/test_romset_recipes.py | 19 +++-- tests/test_save_root.py | 17 ++-- tests/test_schema_semantic_gate.py | 3 +- tests/test_scraper_contract.py | 12 ++- tests/test_sega_filing.py | 4 +- tests/test_shared_groups.py | 10 +-- tests/test_shipped_content.py | 10 +-- tests/test_site_agents.py | 8 +- tests/test_site_arcade_boards.py | 13 ++- tests/test_site_availability.py | 10 +-- tests/test_site_bootstrap.py | 13 ++- tests/test_site_built_gate.py | 4 +- tests/test_site_components.py | 7 +- tests/test_site_console_folders.py | 2 +- tests/test_site_content_data.py | 12 ++- tests/test_site_copy.py | 6 +- tests/test_site_cores.py | 12 ++- tests/test_site_css.py | 2 +- tests/test_site_demo.py | 12 ++- tests/test_site_density_cards.py | 10 +-- tests/test_site_emulator_page.py | 8 +- tests/test_site_emulators.py | 12 ++- tests/test_site_entry.py | 21 +++-- tests/test_site_entry_tables.py | 12 ++- tests/test_site_exports.py | 10 +-- tests/test_site_freshness.py | 12 ++- tests/test_site_funnel.py | 14 ++-- tests/test_site_handheld.py | 12 ++- tests/test_site_images.py | 8 +- tests/test_site_inputs.py | 12 ++- tests/test_site_insights.py | 6 +- tests/test_site_integration.py | 14 ++-- tests/test_site_nav.py | 18 ++--- tests/test_site_page_text.py | 14 ++-- tests/test_site_picker.py | 4 +- tests/test_site_platform_density.py | 8 +- tests/test_site_platform_hashes.py | 11 +-- tests/test_site_privacy.py | 2 +- tests/test_site_pronouns.py | 3 +- tests/test_site_reference.py | 33 ++++---- tests/test_site_render.py | 8 +- tests/test_site_search.py | 18 ++--- tests/test_site_steps.py | 12 ++- tests/test_site_system_links.py | 8 +- tests/test_site_system_names.py | 14 ++-- tests/test_site_system_sections.py | 8 +- tests/test_site_systems.py | 16 ++-- tests/test_site_validation.py | 7 +- tests/test_site_wanted.py | 18 ++--- tests/test_site_weight.py | 17 ++-- tests/test_site_wiki.py | 17 ++-- tests/test_site_write.py | 8 +- tests/test_slot.py | 5 +- tests/test_slots.py | 4 +- tests/test_slots_shipped_file.py | 10 +-- tests/test_source_ref_targets.py | 14 ++-- tests/test_split_extras.py | 10 +-- tests/test_split_names.py | 12 +-- tests/test_split_pack.py | 11 ++- tests/test_standalone_links.py | 12 ++- tests/test_standalone_mode.py | 8 +- tests/test_standalone_probe.py | 10 +-- tests/test_system_ids.py | 10 +-- tests/test_system_pack_extras.py | 8 +- tests/test_system_pack_parity.py | 2 +- tests/test_system_selection.py | 11 ++- tests/test_target_names.py | 7 +- tests/test_target_scrapers.py | 10 +-- tests/test_target_systems.py | 9 +-- tests/test_target_verify.py | 9 +-- tests/test_tool_messages.py | 15 ++-- tests/test_torrentzip.py | 9 +-- tests/test_truth_data_dir_readers.py | 11 +-- tests/test_truth_diff.py | 10 +-- tests/test_truth_layout.py | 7 +- tests/test_twin_declaration_status.py | 14 ++-- tests/test_twin_declarations.py | 12 +-- tests/test_undeclared_dedup.py | 7 +- tests/test_unplaced_extras.py | 16 ++-- tests/test_upstream.py | 5 +- tests/test_upstream_index.py | 10 +-- tests/test_validate_pr.py | 7 +- tests/test_validate_pr_flow.py | 7 +- tests/test_validate_pr_hashes.py | 4 +- tests/test_validated_choice.py | 10 +-- tests/test_validation_scope.py | 6 +- tests/test_variant_choice.py | 7 +- tests/test_variant_identity.py | 2 +- tests/test_verify_all_dir.py | 2 +- tests/test_verify_data_dir_notice.py | 10 +-- tests/test_verify_emulator_evidence.py | 8 +- tests/test_verify_listing.py | 12 +-- tests/test_verify_pack_choice.py | 4 +- tests/test_verify_release_asset.py | 16 ++-- tests/test_version_basis.py | 15 ++-- tests/test_which_pack.py | 7 +- tests/test_workflow_paths.py | 4 +- tests/test_zipped_member.py | 10 +-- 281 files changed, 1036 insertions(+), 1659 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a4a5ab8c5..ee472e36a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,6 +89,10 @@ ignore = [ "RET504", "RET505", "RET506", "RET508", ] +[tool.ruff.lint.pyflakes] +# Each test module imports the tests package first for its isolation (offline, scratch under tmp/). +allowed-unused-imports = ["tests"] + [tool.ruff.lint.mccabe] max-complexity = 15 diff --git a/tests/__init__.py b/tests/__init__.py index c473147f9..eb38760b6 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -13,10 +13,17 @@ temporary directory instead of naming the missing parent. from __future__ import annotations import os +import sys import tempfile from pathlib import Path os.environ.setdefault("RETROBIOS_OFFLINE", "1") +# The modules under test import each other by bare name (common, verify), as +# the scripts do when run from scripts/, and install.py sits at the root. +_REPOSITORY = Path(__file__).resolve().parent.parent +for _path in (str(_REPOSITORY), str(_REPOSITORY / "scripts")): + if _path not in sys.path: + sys.path.insert(0, _path) # The installer reads the XDG base directories as RetroArch and the # emulators do. The CI runner sets XDG_CONFIG_HOME to its own home, so tests # that fake HOME found the runner's folders instead of theirs. A test that diff --git a/tests/test_adler32_resolution.py b/tests/test_adler32_resolution.py index 83483eb4c..7326e6e92 100644 --- a/tests/test_adler32_resolution.py +++ b/tests/test_adler32_resolution.py @@ -9,21 +9,19 @@ corrected it later, every other reader of the resolution did not. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json import shutil -import sys import tempfile import unittest import zlib from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import adler32_of, resolve_local_file -from common import adler32_of, resolve_local_file # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class TheAcceptedChecksumWins(unittest.TestCase): diff --git a/tests/test_agnostic_scan.py b/tests/test_agnostic_scan.py index 254527ca3..d5b2a80af 100644 --- a/tests/test_agnostic_scan.py +++ b/tests/test_agnostic_scan.py @@ -12,20 +12,16 @@ BIOS root of platforms that do not run that emulator. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import common # noqa: E402 -import generate_pack as builder # noqa: E402 -import packextras # noqa: E402 +import common +import generate_pack as builder +import packextras SIZE = 1024 diff --git a/tests/test_agnostic_scan_mode.py b/tests/test_agnostic_scan_mode.py index c8db42d81..2d12f9d1a 100644 --- a/tests/test_agnostic_scan_mode.py +++ b/tests/test_agnostic_scan_mode.py @@ -8,15 +8,13 @@ libretro core, while verify set the entry aside. Reads the repository. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class ScanFollowsTheBuild(unittest.TestCase): diff --git a/tests/test_agnostic_scope.py b/tests/test_agnostic_scope.py index 2e6443761..4fffefe1c 100644 --- a/tests/test_agnostic_scope.py +++ b/tests/test_agnostic_scope.py @@ -9,17 +9,15 @@ was not where it looks. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class AgnosticScan(unittest.TestCase): diff --git a/tests/test_agnostic_substitute.py b/tests/test_agnostic_substitute.py index 8b30d53d7..bc0083c4e 100644 --- a/tests/test_agnostic_substitute.py +++ b/tests/test_agnostic_substitute.py @@ -7,18 +7,16 @@ the slot missing and the manifest omitted it. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from validation import agnostic_substitute -from validation import agnostic_substitute # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class AgnosticSubstitute(unittest.TestCase): diff --git a/tests/test_amberelec_targets.py b/tests/test_amberelec_targets.py index 5abb32518..96801cf25 100644 --- a/tests/test_amberelec_targets.py +++ b/tests/test_amberelec_targets.py @@ -8,16 +8,11 @@ the firmware of cores its image never had. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest -from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from scraper.targets import amberelec_targets_scraper as scraper # noqa: E402 +from scraper.targets import amberelec_targets_scraper as scraper MAKEFILE = """RG351P: \tDEVICE=RG351P ARCH=aarch64 ./scripts/build_distro diff --git a/tests/test_arcade_parents.py b/tests/test_arcade_parents.py index cbc61d58e..1c7197ae0 100644 --- a/tests/test_arcade_parents.py +++ b/tests/test_arcade_parents.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import io import json @@ -11,14 +11,14 @@ import unittest import zipfile from pathlib import Path +from scripts.scraper import arcade_parent_importer as api + ROOT = Path(__file__).resolve().parent.parent TMP_ROOT = ROOT / "tmp" / "tests" TMP_ROOT.mkdir(parents=True, exist_ok=True) FIXTURES = ROOT / "tests" / "fixtures" / "arcade_parents" COMMITTED = ROOT / "games" / "arcade" -from scripts.scraper import arcade_parent_importer as api # noqa: E402 - try: from jsonschema import Draft202012Validator except ImportError: # validate_schemas.py is the only tool that needs it @@ -411,10 +411,8 @@ class CommittedIndex(unittest.TestCase): @unittest.skipIf(Draft202012Validator is None, "jsonschema not installed") def test_each_file_is_read_at_its_profile_pin(self) -> None: """A bumped profile kept the game-to-BIOS map of the old code.""" - import sys from unittest import mock - sys.path.insert(0, str(ROOT / "scripts")) import validate_schemas self.assertEqual(validate_schemas._arcade_pin_errors(), []) diff --git a/tests/test_archive_build.py b/tests/test_archive_build.py index 9d79a2a45..321642c3d 100644 --- a/tests/test_archive_build.py +++ b/tests/test_archive_build.py @@ -6,7 +6,7 @@ plus recipes/archives.json, without a copy of that archive from elsewhere. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json @@ -18,13 +18,12 @@ import zipfile from pathlib import Path from unittest import mock +import archive_build +from torrentzip import build_torrentzip + ROOT = Path(__file__).resolve().parent.parent TMP_ROOT = ROOT / "tmp" / "tests" TMP_ROOT.mkdir(parents=True, exist_ok=True) -sys.path.insert(0, str(ROOT / "scripts")) - -import archive_build # noqa: E402 -from torrentzip import build_torrentzip # noqa: E402 ROM_A = b"first rom payload" * 50 ROM_B = b"second rom payload" * 40 diff --git a/tests/test_archive_choice.py b/tests/test_archive_choice.py index 549cc5678..971288eb2 100644 --- a/tests/test_archive_choice.py +++ b/tests/test_archive_choice.py @@ -7,12 +7,11 @@ seven of the eight members Batocera checks were missing. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os import shutil -import sys import tempfile import unittest import zipfile @@ -20,7 +19,6 @@ import zlib from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class PreferredArchive(unittest.TestCase): diff --git a/tests/test_archive_recipes.py b/tests/test_archive_recipes.py index 083fe9437..0345fbc7d 100644 --- a/tests/test_archive_recipes.py +++ b/tests/test_archive_recipes.py @@ -9,17 +9,15 @@ those members were never read there, and the archive matched no recipe. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import unittest import zipfile from collections import defaultdict from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) # Sets whose archive also carries the ROMs of devices the machine references # (listxml device_ref). A device looks for its ROMs under its own name, then diff --git a/tests/test_artifact_lock.py b/tests/test_artifact_lock.py index aec1ec691..f8cf08fbe 100644 --- a/tests/test_artifact_lock.py +++ b/tests/test_artifact_lock.py @@ -7,7 +7,7 @@ ZIPs, which surfaces as BadZipFile far from its cause. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import subprocess @@ -17,19 +17,18 @@ import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import ( # noqa: E402 +from common import ( ArtifactLockBusy, artifact_lock, hold_artifact_lock, hold_repository_outputs, publish_hold, ) -from tests.scratchtree import scratch_checkout # noqa: E402 -import artifacts # noqa: E402 -from unittest import mock # noqa: E402 +from tests.scratchtree import scratch_checkout +import artifacts +from unittest import mock + +REPO_ROOT = Path(__file__).resolve().parent.parent def _tempdir(test: unittest.TestCase) -> str: diff --git a/tests/test_atomic_artifacts.py b/tests/test_atomic_artifacts.py index 3d0904290..7123be45a 100644 --- a/tests/test_atomic_artifacts.py +++ b/tests/test_atomic_artifacts.py @@ -8,7 +8,7 @@ path in bios/: a scan running beside the copy hashed the truncated file. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import sys @@ -17,10 +17,9 @@ import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import artifacts -import artifacts # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class WholeOrNothing(unittest.TestCase): diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 47527c0cb..4bd9eb283 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import contextlib @@ -24,15 +24,9 @@ from unittest import mock import yaml try: - import jsonschema # noqa: F401 + import jsonschema except ImportError: - HAS_JSONSCHEMA = False -else: - HAS_JSONSCHEMA = True - -sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - + jsonschema = None import install from scripts import pipeline, region, region_audit from scripts.common import resolve_local_file, safe_extract_zip @@ -42,6 +36,7 @@ from scripts.generate_pack import ( verify_pack_against_platform, ) +HAS_JSONSCHEMA = jsonschema is not None ROOT = Path(__file__).resolve().parent.parent TMP_ROOT = ROOT / "tmp" / "tests" TMP_ROOT.mkdir(parents=True, exist_ok=True) @@ -1003,7 +998,6 @@ class FaqRegressions(unittest.TestCase): # Typed by hand, the table and the prose under it kept MAME 0.160 # and FinalBurn Neo 1.0.0.2, versions no source at the pins states, # and the test holding them to the profiles kept the errors in step. - sys.path.insert(0, str(ROOT / "scripts")) import generate_site from common import load_emulator_profiles @@ -3200,7 +3194,6 @@ class ACheckThatCannotAnswerDoesNotPass(unittest.TestCase): def test_an_unreachable_buildbot_is_not_a_fresh_verdict(self): """Every HEAD unanswered printed "16 unknown" and exited 0, so the online pipeline printed check_buildbot OK.""" - sys.path.insert(0, str(ROOT / "scripts")) import check_buildbot_system as cbs registry = str(ROOT / "platforms" / "_data_dirs.yml") @@ -3306,7 +3299,6 @@ class ContributorsSurviveAFailedRequest(unittest.TestCase): def _block(self, text: str): import tempfile - sys.path.insert(0, str(ROOT / "scripts")) from generate_readme import _existing_contributor_block with tempfile.NamedTemporaryFile("w", suffix=".md", delete=False) as handle: @@ -3335,7 +3327,6 @@ class ContributorsSurviveAFailedRequest(unittest.TestCase): self.assertEqual(self._block("# Title\n\n## Other\n\ntext\n"), []) def test_an_unreadable_file_yields_nothing(self): - sys.path.insert(0, str(ROOT / "scripts")) from generate_readme import _existing_contributor_block self.assertEqual(_existing_contributor_block("/nonexistent/README.md"), []) @@ -3862,7 +3853,6 @@ class HashMergeBackupsAreNotSources(unittest.TestCase): """ def test_the_validator_skips_a_backup(self): - sys.path.insert(0, str(ROOT / "scripts")) try: from validate_schemas import _validate_yaml_directory except ImportError as exc: @@ -5286,7 +5276,6 @@ class PipelineDocstringNamesThePrintedSteps(unittest.TestCase): source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8") doc = ast.get_docstring(ast.parse(source)) listed = set(re.findall(r"^ (\d[a-z0-9]*)\s{2,}", doc, re.M)) - sys.path.insert(0, str(ROOT / "scripts")) import pipeline printed = {pipeline.step_number(key) for key in pipeline.STEP_LABELS} @@ -5300,7 +5289,6 @@ class VerifyAllSummaryNamesWhatIsWrong(unittest.TestCase): say which platform carried it.""" def test_counts_carry_platforms_and_core_misses(self): - sys.path.insert(0, str(ROOT / "scripts")) import verify clean = {"severity_counts": {}, "undeclared_files": []} @@ -5322,7 +5310,6 @@ class VerifyAllSummaryNamesWhatIsWrong(unittest.TestCase): def test_a_file_missing_on_several_platforms_is_counted_once(self): """sfiii2a.zip missing on 15 platforms read '24 core file(s)' for 10 distinct files, the name printed 15 times on one line.""" - sys.path.insert(0, str(ROOT / "scripts")) import verify def missing(*names: str) -> dict: @@ -5372,7 +5359,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): listed among the files to source, with 19 more like it.""" def test_verify_does_not_count_it_missing(self): - sys.path.insert(0, str(ROOT / "scripts")) import verify entry = {"name": "n64.psh", "required": True, "in_repo": False, @@ -5384,7 +5370,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): self.assertNotIn("n64.psh", summary) def test_the_site_gives_it_its_own_status(self): - sys.path.insert(0, str(ROOT / "scripts")) import generate_site rows = generate_site._gap_export_rows({}, {"daedalusx64": { @@ -5397,7 +5382,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): def test_a_held_bundled_file_is_not_packed(self): """A file installed with the emulator is already on the user's machine, so the pack leaves it out even when the collection holds it.""" - sys.path.insert(0, str(ROOT / "scripts")) import verify entry = {"name": "n64.psh", "required": True, "in_repo": True, @@ -5410,7 +5394,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): def test_a_build_scope_keeps_it_for_the_other_build(self): """PPSSPP's standalone release ships assets/, its libretro core does not: bundled for one build, the entry still reaches a core's pack.""" - sys.path.insert(0, str(ROOT / "scripts")) from validation import deliverable entries = [{"ref": "ppsspp-assets", "mode": "libretro"}, @@ -5423,7 +5406,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): def test_a_platform_package_can_differ_both_ways(self): """Batocera's hcl package installs the binary alone, its blueMSX core package copies the machines beside the core.""" - sys.path.insert(0, str(ROOT / "scripts")) from validation import installed_with_emulator hcl = {"name": "data.pak", "bundled": True, "not_bundled_on": ["batocera"]} @@ -5435,7 +5417,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): self.assertTrue(installed_with_emulator(hcl)) def test_every_platform_named_is_registered(self): - sys.path.insert(0, str(ROOT / "scripts")) from common import list_registered_platforms, load_emulator_profiles known = set(list_registered_platforms(str(ROOT / "platforms"))) @@ -5457,7 +5438,6 @@ class BundledFilesAreNotToSource(unittest.TestCase): import yaml as _yaml - sys.path.insert(0, str(ROOT / "scripts")) import common with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: @@ -5540,7 +5520,6 @@ class GapsPageCountsOneWay(unittest.TestCase): def test_the_destination_is_the_list_entrys(self): from scripts.generate_site import _declared_destination - sys.path.insert(0, str(ROOT / "scripts")) from common import load_platform_config config = load_platform_config("amberelec", str(ROOT / "platforms")) @@ -5548,7 +5527,6 @@ class GapsPageCountsOneWay(unittest.TestCase): self.assertEqual(_declared_destination(config, detail), "bios/quasi88/N88_KNJ1.ROM") def test_verify_marks_the_settled_entry(self): - sys.path.insert(0, str(ROOT / "scripts")) import verify result = {"name": "cdibios.zip", "status": verify.Status.UNTESTED} @@ -7373,7 +7351,6 @@ class SkipPacksHelpSaysWhatRuns(unittest.TestCase): self.assertNotIn("docs/", text) def test_every_step_it_names_is_one_it_skips(self): - sys.path.insert(0, str(ROOT / "scripts")) import pipeline source = (ROOT / "scripts" / "pipeline.py").read_text(encoding="utf-8") diff --git a/tests/test_auto_fetch_lookup.py b/tests/test_auto_fetch_lookup.py index e166df0cd..f9352be87 100644 --- a/tests/test_auto_fetch_lookup.py +++ b/tests/test_auto_fetch_lookup.py @@ -3,23 +3,19 @@ content, and nothing it serves is kept unless every declared hash holds.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib import io import os -import sys import tempfile 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")) - -import auto_fetch # noqa: E402 +import auto_fetch PAYLOAD = b"keyboard mcu" SHA1 = hashlib.sha1(PAYLOAD).hexdigest() diff --git a/tests/test_autorun.py b/tests/test_autorun.py index 7d0515ead..0bcedf8c5 100644 --- a/tests/test_autorun.py +++ b/tests/test_autorun.py @@ -7,7 +7,7 @@ a function returning canned CI runs. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io @@ -23,13 +23,12 @@ import unittest.mock from pathlib import Path from types import MappingProxyType -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import autorun as ar +import bios_integrity as bib +import cleanup_disk as cd +import sync_release_assets as sra -import autorun as ar # noqa: E402 -import bios_integrity as bib # noqa: E402 -import cleanup_disk as cd # noqa: E402 -import sync_release_assets as sra # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] PY = "python" _ENV_KEYS = ("GIT_CONFIG_GLOBAL", "GIT_CONFIG_NOSYSTEM") diff --git a/tests/test_batocera_cores.py b/tests/test_batocera_cores.py index 271bd276c..03eceb66c 100644 --- a/tests/test_batocera_cores.py +++ b/tests/test_batocera_cores.py @@ -9,15 +9,12 @@ under it: amiberry, fsuae and vice were never in a target list. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "scripts")) ES_SYSTEMS = """\ dos: diff --git a/tests/test_batocera_md5_list.py b/tests/test_batocera_md5_list.py index e274b223a..d86e6039a 100644 --- a/tests/test_batocera_md5_list.py +++ b/tests/test_batocera_md5_list.py @@ -9,33 +9,31 @@ a list, and verify accepts any listed md5. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import tempfile import unittest import zipfile from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import resolve_local_file # noqa: E402 -from exporter import discover_exporters # noqa: E402 -from export_native import landed_changes # noqa: E402 -from exporter.baseline import NativeFile, build_native_model # noqa: E402 -from exporter.batocera_exporter import md5_list_support # noqa: E402 -from scraper import rocknix_scraper # noqa: E402 -from scraper.base_scraper import md5_field, requirement_entry # noqa: E402 -from scraper.batocera_scraper import ( # noqa: E402 +from common import resolve_local_file +from exporter import discover_exporters +from export_native import landed_changes +from exporter.baseline import NativeFile, build_native_model +from exporter.batocera_exporter import md5_list_support +from scraper import rocknix_scraper +from scraper.base_scraper import md5_field, requirement_entry +from scraper.batocera_scraper import ( SYSTEM_SLUG_MAP, extract_systems_dict, platform_systems, requirements_from_systems, ) -from siteexports import describe_change # noqa: E402 -from verify import Status, verify_entry_md5 # noqa: E402 +from siteexports import describe_change +from verify import Status, verify_entry_md5 + +REPO_ROOT = Path(__file__).resolve().parents[1] A = "dc2b9bf8da62ec93e868cfd29f0d067d" B = "924e392ed05558ffdb115408c263dccf" diff --git a/tests/test_bios_companions.py b/tests/test_bios_companions.py index 55b3f94e9..73486ca37 100644 --- a/tests/test_bios_companions.py +++ b/tests/test_bios_companions.py @@ -9,17 +9,15 @@ the Batocera BIOS folder. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from packextras import _companion_extensions, _companions -from packextras import _companion_extensions, _companions # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class Companions(unittest.TestCase): diff --git a/tests/test_bios_layout.py b/tests/test_bios_layout.py index 5a9f73d66..90ebad555 100644 --- a/tests/test_bios_layout.py +++ b/tests/test_bios_layout.py @@ -7,7 +7,7 @@ Oric and Tangerine: one machine, two folders, two pages. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import subprocess import unittest diff --git a/tests/test_bundled_identity.py b/tests/test_bundled_identity.py index d05fb9e18..10313b90f 100644 --- a/tests/test_bundled_identity.py +++ b/tests/test_bundled_identity.py @@ -13,19 +13,17 @@ entry is written with the hash of the file the emulator ships. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -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 common import load_database, resolve_local_file -from common import load_database, resolve_local_file # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent UNIDENTIFIED = { "abuse": 3, diff --git a/tests/test_cache_independent_counts.py b/tests/test_cache_independent_counts.py index c3d7189f3..77141ac0c 100644 --- a/tests/test_cache_independent_counts.py +++ b/tests/test_cache_independent_counts.py @@ -10,15 +10,13 @@ directory cache is not a collection. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class DeclaredFilesResolveWithoutDataCaches(unittest.TestCase): diff --git a/tests/test_campaign.py b/tests/test_campaign.py index 512d44365..e7a0e6ebb 100644 --- a/tests/test_campaign.py +++ b/tests/test_campaign.py @@ -10,7 +10,7 @@ resume and rerun on a changed core. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -20,7 +20,6 @@ import os import shutil import struct import subprocess -import sys import tempfile import unittest import unittest.mock @@ -29,8 +28,6 @@ from types import MappingProxyType import yaml -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - import campaign import campaign_profiles import campaign_rules as rules diff --git a/tests/test_case_insensitive_platforms.py b/tests/test_case_insensitive_platforms.py index 168460fcc..d328781ef 100644 --- a/tests/test_case_insensitive_platforms.py +++ b/tests/test_case_insensitive_platforms.py @@ -7,22 +7,21 @@ went red. The flag lived in retrobat.yml and vanished at the next scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib import io import os -import sys import tempfile import unittest from pathlib import Path import yaml +from common import load_platform_config + REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -from common import load_platform_config # noqa: E402 class CaseInsensitiveWhereTheFilesystemIs(unittest.TestCase): diff --git a/tests/test_casefold_cache.py b/tests/test_casefold_cache.py index 95cc6f67b..7d7d4116a 100644 --- a/tests/test_casefold_cache.py +++ b/tests/test_casefold_cache.py @@ -2,16 +2,14 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import _casefold_name_index -from common import _casefold_name_index # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class CasefoldIndexFollowsItsSource(unittest.TestCase): diff --git a/tests/test_check_freshness.py b/tests/test_check_freshness.py index ae0deb730..808d3bfc0 100644 --- a/tests/test_check_freshness.py +++ b/tests/test_check_freshness.py @@ -8,7 +8,7 @@ report is folded, since each of those decides whether a row says STALE. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import os @@ -18,11 +18,10 @@ import unittest from unittest import mock from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import check_freshness as cf +from common import yaml_load -import check_freshness as cf # noqa: E402 -from common import yaml_load # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class NativeCacheTests(unittest.TestCase): diff --git a/tests/test_check_release.py b/tests/test_check_release.py index 700338e87..416e3fcd1 100644 --- a/tests/test_check_release.py +++ b/tests/test_check_release.py @@ -7,13 +7,9 @@ whose checksums every user's `sha256sum --check` rejected. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest -from pathlib import Path - -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) import build_port from check_release import SIGNATURE, SUMS, Asset, compare_release, parse_sums diff --git a/tests/test_checks_have_values.py b/tests/test_checks_have_values.py index 8d9cea7a3..27a55f829 100644 --- a/tests/test_checks_have_values.py +++ b/tests/test_checks_have_values.py @@ -6,17 +6,15 @@ one. validate_schemas now refuses it. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import subprocess -import sys import unittest from pathlib import Path import yaml REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class ChecksHaveValues(unittest.TestCase): diff --git a/tests/test_cited_lines.py b/tests/test_cited_lines.py index 1cf8794e5..d3c77d6a3 100644 --- a/tests/test_cited_lines.py +++ b/tests/test_cited_lines.py @@ -7,18 +7,16 @@ does not hold the file. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path -ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(ROOT / "scripts")) +import upstream +from safeparse import yaml_load -import upstream # noqa: E402 -from safeparse import yaml_load # noqa: E402 +ROOT = Path(__file__).resolve().parents[1] CACHE = ROOT / ".cache" / "upstream" diff --git a/tests/test_content_checks.py b/tests/test_content_checks.py index a72cb90cf..1e99a62e0 100644 --- a/tests/test_content_checks.py +++ b/tests/test_content_checks.py @@ -11,23 +11,21 @@ any flash image whose size is a whole number of 64 KiB. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import struct -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_pack as builder +import packextras +from romdir import romdir_accepts, walk +from validation import _build_validation_index, check_file_validation -import common # noqa: E402 -import generate_pack as builder # noqa: E402 -import packextras # noqa: E402 -from romdir import romdir_accepts, walk # noqa: E402 -from validation import _build_validation_index, check_file_validation # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent # How each fork reads the table, as the profiles declare it. WX = {"reset_compare": 5, "missing_reset": "rejects", "terminated_names": False, diff --git a/tests/test_content_declarations.py b/tests/test_content_declarations.py index ae2401d96..2c9db3e60 100644 --- a/tests/test_content_declarations.py +++ b/tests/test_content_declarations.py @@ -8,14 +8,10 @@ declared file meets the entry and the label is not shipped a second time. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import os -import sys import unittest -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - from common import platform_declared_contents from validation import declaration_settles diff --git a/tests/test_contributing_text.py b/tests/test_contributing_text.py index baa4e85af..ef21ea8c8 100644 --- a/tests/test_contributing_text.py +++ b/tests/test_contributing_text.py @@ -6,19 +6,17 @@ the repository, five on the site, under two different titles. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_readme +import generate_site -import generate_readme # noqa: E402 -import generate_site # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent def _normalized(text: str) -> str: diff --git a/tests/test_core_data_trees.py b/tests/test_core_data_trees.py index 18e658ca5..db3c13278 100644 --- a/tests/test_core_data_trees.py +++ b/tests/test_core_data_trees.py @@ -10,19 +10,17 @@ reader now gets the tree, or the profile says its package installs it. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_pack as builder +from validation import deliverable, read_from_system_dir -import common # noqa: E402 -import generate_pack as builder # noqa: E402 -from validation import deliverable, read_from_system_dir # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PROFILES = { "demo": { diff --git a/tests/test_core_file_fills_declaration.py b/tests/test_core_file_fills_declaration.py index 52f281334..bde19394a 100644 --- a/tests/test_core_file_fills_declaration.py +++ b/tests/test_core_file_fills_declaration.py @@ -8,13 +8,12 @@ frontend sees a file at the path. verify kept it MISSING, so the pack said from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import contextlib import io import shutil -import sys import tempfile import unittest import zipfile @@ -24,12 +23,11 @@ from unittest import mock import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import _emulator_profiles_cache, load_platform_config +from generate_pack import generate_pack +from verify import verify_platform -from common import _emulator_profiles_cache, load_platform_config # noqa: E402 -from generate_pack import generate_pack # noqa: E402 -from verify import verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class ACoreFileFillsAFreeDeclaration(unittest.TestCase): diff --git a/tests/test_core_probe.py b/tests/test_core_probe.py index 19a05d7d7..6ba91014f 100644 --- a/tests/test_core_probe.py +++ b/tests/test_core_probe.py @@ -7,7 +7,7 @@ probe on it: staging, the worker process, strace, the record and its schema. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse import contextlib @@ -25,8 +25,6 @@ import unittest.mock from pathlib import Path from typing import ClassVar -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - import core_probe import measurement_records diff --git a/tests/test_core_size_refusal.py b/tests/test_core_size_refusal.py index 8c4a437f6..78ae6f59a 100644 --- a/tests/test_core_size_refusal.py +++ b/tests/test_core_size_refusal.py @@ -10,11 +10,10 @@ read one rule (validation.core_size_refusal). from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest import zipfile @@ -22,14 +21,13 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_db +import generate_pack as builder +from validation import core_size_refusal +from verify import find_undeclared_files, verify_platform -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -from validation import core_size_refusal # noqa: E402 -from verify import find_undeclared_files, verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent SIZED = """\ emulator: Sized diff --git a/tests/test_coverage_cache.py b/tests/test_coverage_cache.py index 8dd05038b..b5facaad2 100644 --- a/tests/test_coverage_cache.py +++ b/tests/test_coverage_cache.py @@ -9,18 +9,16 @@ tests change an input and expect a fresh computation. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_readme -import generate_readme # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class CoverageCache(unittest.TestCase): diff --git a/tests/test_cross_reference_sources.py b/tests/test_cross_reference_sources.py index 6f96e2d8e..3bfaee437 100644 --- a/tests/test_cross_reference_sources.py +++ b/tests/test_cross_reference_sources.py @@ -9,23 +9,21 @@ a directory called ROM). from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from cross_reference import ( # noqa: E402 +from cross_reference import ( _build_supplemental_index, cross_reference, entry_source, print_report, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + def _index(**over) -> dict: base = { diff --git a/tests/test_crypto_aes.py b/tests/test_crypto_aes.py index 1e86433f1..bd372c456 100644 --- a/tests/test_crypto_aes.py +++ b/tests/test_crypto_aes.py @@ -7,17 +7,15 @@ contributor with none of them. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import crypto_verify -import crypto_verify # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] STDLIB_OR_LOCAL = {"__future__", "hashlib", "struct", "collections", "pathlib", "sect233r1"} diff --git a/tests/test_crypto_unique_data.py b/tests/test_crypto_unique_data.py index 2124e00a2..3b09c0780 100644 --- a/tests/test_crypto_unique_data.py +++ b/tests/test_crypto_unique_data.py @@ -18,20 +18,16 @@ Layouts, from Azahar src/core/hw/unique_data.cpp and src/core/file_sys/otp.cpp: from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import struct -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import crypto_verify # noqa: E402 -import sect233r1 as ec # noqa: E402 +import crypto_verify +import sect233r1 as ec # A 2048-bit RSA key, the size the 3DS signatures use, from two fixed primes # so the fixture is reproducible and costs nothing to build. diff --git a/tests/test_crypto_verify.py b/tests/test_crypto_verify.py index a52dd03b6..b6dd83a30 100644 --- a/tests/test_crypto_verify.py +++ b/tests/test_crypto_verify.py @@ -14,21 +14,17 @@ constants rather than against itself. The AES vector is from NIST SP 800-38A. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import shutil -import sys import tempfile import unittest import unittest.mock from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import crypto_verify # noqa: E402 -import sect233r1 as ec # noqa: E402 +import crypto_verify +import sect233r1 as ec class FieldArithmetic(unittest.TestCase): diff --git a/tests/test_data_dir_refs.py b/tests/test_data_dir_refs.py index 9793ea24d..99b2b4247 100644 --- a/tests/test_data_dir_refs.py +++ b/tests/test_data_dir_refs.py @@ -6,14 +6,12 @@ verify only said "not cached" and refresh_data_dirs had nothing to fetch. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class DataDirRefsAreRegistered(unittest.TestCase): diff --git a/tests/test_data_only_refs.py b/tests/test_data_only_refs.py index 63eb4bd50..dcce22884 100644 --- a/tests/test_data_only_refs.py +++ b/tests/test_data_only_refs.py @@ -2,14 +2,12 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) try: import validate_schemas diff --git a/tests/test_dataclass_defaults.py b/tests/test_dataclass_defaults.py index fd9fbca22..d9ece9243 100644 --- a/tests/test_dataclass_defaults.py +++ b/tests/test_dataclass_defaults.py @@ -7,7 +7,7 @@ TypeError on the first loop. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import unittest diff --git a/tests/test_db_aliases.py b/tests/test_db_aliases.py index 0c51d415f..229d2a327 100644 --- a/tests/test_db_aliases.py +++ b/tests/test_db_aliases.py @@ -8,7 +8,7 @@ disk ROM then served the CoCo one. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import sys @@ -18,9 +18,9 @@ import unittest from pathlib import Path from unittest import mock +import generate_db + REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -import generate_db # noqa: E402 class _NoCoreInfo: diff --git a/tests/test_declared_names.py b/tests/test_declared_names.py index 76ff4c236..070223b30 100644 --- a/tests/test_declared_names.py +++ b/tests/test_declared_names.py @@ -8,21 +8,19 @@ set, enriched with every spelling the database knows. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from cross_reference import ( # noqa: E402 +from cross_reference import ( cross_reference, declared_names, load_platform_files, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + class FlatDeclaredSet(unittest.TestCase): def test_a_name_declared_under_another_system_id_is_not_a_gap(self): diff --git a/tests/test_dedup.py b/tests/test_dedup.py index 81e1f2d1e..04f4d84af 100644 --- a/tests/test_dedup.py +++ b/tests/test_dedup.py @@ -9,20 +9,16 @@ are both load-bearing. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io import os -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import dedup # noqa: E402 +import dedup class _Bios(unittest.TestCase): diff --git a/tests/test_derivations.py b/tests/test_derivations.py index 061205b0b..a620327d8 100644 --- a/tests/test_derivations.py +++ b/tests/test_derivations.py @@ -7,22 +7,20 @@ is two held ROMs end to end. The gap report listed them as acquisition targets. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os import shutil -import sys import tempfile import unittest import unittest.mock import zlib from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import derivations -import derivations # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent def _held(path: Path, data: bytes) -> dict: diff --git a/tests/test_deterministic_zip.py b/tests/test_deterministic_zip.py index 293f84b91..2dc59fed0 100644 --- a/tests/test_deterministic_zip.py +++ b/tests/test_deterministic_zip.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os diff --git a/tests/test_directory_entries.py b/tests/test_directory_entries.py index 7c86113ff..197f3d7a2 100644 --- a/tests/test_directory_entries.py +++ b/tests/test_directory_entries.py @@ -9,11 +9,10 @@ reported missing while 3 584 collected files stayed out of every pack. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json -import sys import tempfile import unittest from unittest import mock @@ -23,19 +22,16 @@ from pathlib import Path import yaml try: - import jsonschema # noqa: F401 + import jsonschema except ImportError: - HAS_JSONSCHEMA = False -else: - HAS_JSONSCHEMA = True + jsonschema = None +import common +import generate_db +import generate_pack as builder +import verify +HAS_JSONSCHEMA = jsonschema is not None REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -import verify # noqa: E402 PROFILE = """\ emulator: Demo diff --git a/tests/test_doc_pages.py b/tests/test_doc_pages.py index 72caa8d1c..63beb47ae 100644 --- a/tests/test_doc_pages.py +++ b/tests/test_doc_pages.py @@ -7,7 +7,7 @@ code moves, and nothing else notices. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import hashlib @@ -20,11 +20,10 @@ import unittest import zipfile from pathlib import Path +from tests.test_prose_style import _python_prose, _sentence_case + ROOT = Path(__file__).resolve().parent.parent WIKI = ROOT / "wiki" -sys.path.insert(0, str(ROOT / "scripts")) - -from tests.test_prose_style import _python_prose, _sentence_case # noqa: E402 FENCED = re.compile(r"^```.*?^```", re.S | re.M) PUBLISHED = sorted(WIKI.glob("*.md")) + [ROOT / "README.md", ROOT / "CONTRIBUTING.md"] diff --git a/tests/test_doc_surfaces.py b/tests/test_doc_surfaces.py index 90ef35ad8..90057de2c 100644 --- a/tests/test_doc_surfaces.py +++ b/tests/test_doc_surfaces.py @@ -9,21 +9,17 @@ tool prints, and a size is the one the release record holds. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import contextlib import re -import sys import unittest from functools import cache from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import release_record # noqa: E402 -from generate_readme import ( # noqa: E402 +import release_record +from generate_readme import ( SITE_URL, asset_links, contributing_text, @@ -32,6 +28,8 @@ from generate_readme import ( # noqa: E402 format_size, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + RECORD = release_record.load_record(REPO_ROOT / "release.json") REPO = "https://github.com/Abdess/retrobios" diff --git a/tests/test_download.py b/tests/test_download.py index c63643278..c084ffcb4 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -9,7 +9,7 @@ checksum of each layout and the staging location. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import functools @@ -30,6 +30,8 @@ import unittest import zipfile from pathlib import Path +import split_pack + REPO_ROOT = Path(__file__).resolve().parent.parent _spec = importlib.util.spec_from_file_location( "download", REPO_ROOT / "scripts" / "download.py" @@ -42,9 +44,6 @@ _spec.loader.exec_module(download) SHELL = REPO_ROOT / "scripts" / "download.sh" -sys.path.insert(0, str(REPO_ROOT / "scripts")) -import split_pack # noqa: E402 - # A slice of a real release: two whole packs, three split, and the checksums. RELEASE_ASSETS = [ "Batocera_43.1_BIOS_Pack.zip.001", diff --git a/tests/test_e2e.py b/tests/test_e2e.py index 781c592cf..e579f6777 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -17,7 +17,7 @@ Covers: from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -31,8 +31,6 @@ import zipfile from pathlib import Path from unittest import mock -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - import largefiles import yaml from common import ( @@ -65,11 +63,10 @@ from verify import ( ) try: - import jsonschema # noqa: F401 + import jsonschema except ImportError: - HAS_JSONSCHEMA = False -else: - HAS_JSONSCHEMA = True + jsonschema = None +HAS_JSONSCHEMA = jsonschema is not None def _h(data: bytes) -> dict: @@ -2949,7 +2946,6 @@ class TestE2E(unittest.TestCase): """--platform + --system is accepted (not rejected at validation stage).""" import argparse - sys.path.insert(0, "scripts") # Build the same parser as generate_pack.main() parser = argparse.ArgumentParser() parser.add_argument("--platform", "-p") @@ -3913,7 +3909,6 @@ class TestE2E(unittest.TestCase): def test_93_parse_retroarch_cfg(self): """Parse system_directory from retroarch.cfg.""" - sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from install import _parse_retroarch_system_dir cfg = os.path.join(self.root, "retroarch.cfg") @@ -3935,7 +3930,6 @@ class TestE2E(unittest.TestCase): def test_94_parse_emudeck_settings(self): """Parse emulationPath from EmuDeck settings.sh.""" - sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from install import _parse_bash_var settings = os.path.join(self.root, "settings.sh") @@ -3948,7 +3942,6 @@ class TestE2E(unittest.TestCase): def test_95_parse_ps1_var(self): """Parse $emulationPath from EmuDeck settings.ps1.""" - sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from install import _parse_ps1_var settings = os.path.join(self.root, "settings.ps1") @@ -3959,7 +3952,6 @@ class TestE2E(unittest.TestCase): def test_96_target_filtering(self): """--target filters files by cores field.""" - sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from install import _filter_by_target files = [ @@ -3975,7 +3967,6 @@ class TestE2E(unittest.TestCase): def test_97_standalone_copies(self): """Standalone keys copied to existing emulator dirs.""" - sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from install import do_standalone_copies bios_dir = Path(self.root) / "bios" diff --git a/tests/test_elec_scrapers.py b/tests/test_elec_scrapers.py index c6ee5c34d..a58dfd5d2 100644 --- a/tests/test_elec_scrapers.py +++ b/tests/test_elec_scrapers.py @@ -9,17 +9,13 @@ upstream files. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from scraper import amberelec_scraper, emuelec_scraper, knulli_scraper # noqa: E402 -from scraper.es_emulators import ( # noqa: E402 +from scraper import amberelec_scraper, emuelec_scraper, knulli_scraper +from scraper.es_emulators import ( attach_system_cores, es_cores, json_systems, @@ -27,6 +23,8 @@ from scraper.es_emulators import ( # noqa: E402 xml_systems, ) +REPO_ROOT = Path(__file__).resolve().parents[1] + CHECKER = ''' def checkBios(systems, prefix): diff --git a/tests/test_emuelec_targets.py b/tests/test_emuelec_targets.py index 2a7fc147b..aeb3e6f3a 100644 --- a/tests/test_emuelec_targets.py +++ b/tests/test_emuelec_targets.py @@ -9,17 +9,15 @@ firmware of cores its image never had. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper.targets import emuelec_targets_scraper as scraper -from scraper.targets import emuelec_targets_scraper as scraper # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] # packages/sx05re/emuelec/package.mk:8-77 at v4.8, PKG_EMUS and # PKG_EXPERIMENTAL shortened. diff --git a/tests/test_emulator_pack_counts.py b/tests/test_emulator_pack_counts.py index bf05abee1..55dff2a58 100644 --- a/tests/test_emulator_pack_counts.py +++ b/tests/test_emulator_pack_counts.py @@ -9,7 +9,7 @@ names and ten "missing". from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re import subprocess @@ -80,7 +80,6 @@ class APlaceholderIsAnsweredByEvidence(unittest.TestCase): import yaml - sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import _emulator_profiles_cache from generate_pack import generate_emulator_pack from verify import verify_emulator diff --git a/tests/test_entry_categories.py b/tests/test_entry_categories.py index 38e782ddb..4f58ecd7f 100644 --- a/tests/test_entry_categories.py +++ b/tests/test_entry_categories.py @@ -6,13 +6,9 @@ from what the cores the platform runs open, never from the entry's name. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest -from pathlib import Path - -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) import verify from exporter.candidates import ( diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index b39ee258d..c59b37789 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -9,28 +9,26 @@ from a file other than the one the hash describes. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import unittest from collections import OrderedDict from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from exporter.baseline import NativeFile, NativeSystem, Report, build_native_model +from exporter.bizhawk_exporter import Exporter as BizHawk +from exporter.misterfpga_exporter import Exporter as Mister +from exporter.romm_exporter import Exporter as Romm +from scraper.emudeck_scraper import FUNCTION_HASH_MAP +from exporter.emudeck_exporter import Exporter as EmuDeck +from exporter.retrobat_exporter import Exporter as RetroBat +from exporter.retrodeck_exporter import Exporter as RetroDeck +from exporter.recalbox_exporter import Exporter as Recalbox +from exporter.retropie_exporter import Exporter as RetroPie +from exporter.systemdat_exporter import Exporter as SystemDat -from exporter.baseline import NativeFile, NativeSystem, Report, build_native_model # noqa: E402 -from exporter.bizhawk_exporter import Exporter as BizHawk # noqa: E402 -from exporter.misterfpga_exporter import Exporter as Mister # noqa: E402 -from exporter.romm_exporter import Exporter as Romm # noqa: E402 -from scraper.emudeck_scraper import FUNCTION_HASH_MAP # noqa: E402 -from exporter.emudeck_exporter import Exporter as EmuDeck # noqa: E402 -from exporter.retrobat_exporter import Exporter as RetroBat # noqa: E402 -from exporter.retrodeck_exporter import Exporter as RetroDeck # noqa: E402 -from exporter.recalbox_exporter import Exporter as Recalbox # noqa: E402 -from exporter.retropie_exporter import Exporter as RetroPie # noqa: E402 -from exporter.systemdat_exporter import Exporter as SystemDat # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] A = "a" * 32 B = "b" * 32 diff --git a/tests/test_export_native_layer.py b/tests/test_export_native_layer.py index 902ea5d78..7113c8363 100644 --- a/tests/test_export_native_layer.py +++ b/tests/test_export_native_layer.py @@ -9,18 +9,17 @@ libretro's System.dat (N88EXT0-3.ROM) as if libretro declared them. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +from export_native import load_inputs -import common # noqa: E402 -from export_native import load_inputs # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class TheNativeLayerIsThePlatformsOwn(unittest.TestCase): diff --git a/tests/test_export_report.py b/tests/test_export_report.py index 776410ee8..13f277a9b 100644 --- a/tests/test_export_report.py +++ b/tests/test_export_report.py @@ -7,16 +7,13 @@ file from and no list to check the diff against. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import tempfile import unittest from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - import export_native from siteexports import generate_exports_page, load_export_reports diff --git a/tests/test_exporters.py b/tests/test_exporters.py index 306babfad..ae1781815 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -14,7 +14,7 @@ and skip when it has not been populated (python scripts/export_native.py from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import difflib import io @@ -30,18 +30,15 @@ import zipfile from collections import OrderedDict from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import ( # noqa: E402 +from common import ( list_registered_platforms, load_platform_config, native_layer, parse_untrusted_xml, ) -from exporter import discover_exporters # noqa: E402 -from exporter.base_exporter import BaseExporter # noqa: E402 -from export_native import ( # noqa: E402 +from exporter import discover_exporters +from exporter.base_exporter import BaseExporter +from export_native import ( SOURCES_INDEX, collect_originals, fetch, @@ -49,13 +46,15 @@ from export_native import ( # noqa: E402 pinned_base, source_key, ) -from exporter.baseline import ( # noqa: E402 +from exporter.baseline import ( NativeFile, NativeSystem, Report, build_native_model, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + UPSTREAM_CACHE = REPO_ROOT / ".cache" / "upstream-native" @@ -1605,7 +1604,9 @@ class AnExportIsWrittenAsItsBytes(unittest.TestCase): "rocknix-systems": "#!/usr/bin/python\n", }, {"rocknix-systems": 0o755}) self.assertEqual((root / "FirmwareDatabase.cs").read_bytes(), b"a\r\nb\r\n") - mode = lambda name: stat.S_IMODE((root / name).stat().st_mode) # noqa: E731 + def mode(name: str) -> int: + return stat.S_IMODE((root / name).stat().st_mode) + self.assertEqual(mode("rocknix-systems"), 0o755) self.assertEqual(mode("FirmwareDatabase.cs"), 0o644) self.assertEqual(sorted(p.name for p in root.iterdir()), diff --git a/tests/test_extra_identity.py b/tests/test_extra_identity.py index 1f1faca65..830fa8f15 100644 --- a/tests/test_extra_identity.py +++ b/tests/test_extra_identity.py @@ -8,18 +8,16 @@ Galaksija ROM and a PS2 ROM2.BIN. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import PROFILE_IDENTITY_FIELDS +from packextras import _collect_emulator_extras +from verify import find_undeclared_files -from common import PROFILE_IDENTITY_FIELDS # noqa: E402 -from packextras import _collect_emulator_extras # noqa: E402 -from verify import find_undeclared_files # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] ENTRY = { "name": "bios.rom", diff --git a/tests/test_extract_targets.py b/tests/test_extract_targets.py index 1995c4526..ac128c2b0 100644 --- a/tests/test_extract_targets.py +++ b/tests/test_extract_targets.py @@ -9,17 +9,15 @@ have vanished with it. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest 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 +REPO_ROOT = Path(__file__).resolve().parent.parent PLATFORMS = str(REPO_ROOT / "platforms") @@ -69,7 +67,6 @@ class ThePackGuideNamesTheInstallerDefault(unittest.TestCase): rule["path"] for rule in registry["retrobat"]["install"]["detect"] if rule["os"] == "windows" and rule["method"] == "path_exists" ) - sys.path.insert(0, str(REPO_ROOT / "scripts")) from siteguides import pack_manual # The pack guide text is data (platforms/_guides.yml): read what the diff --git a/tests/test_fbneo_parser.py b/tests/test_fbneo_parser.py index 583e75140..328839f5e 100644 --- a/tests/test_fbneo_parser.py +++ b/tests/test_fbneo_parser.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import tempfile import unittest diff --git a/tests/test_file_consumers.py b/tests/test_file_consumers.py index 87b2495ee..67c883242 100644 --- a/tests/test_file_consumers.py +++ b/tests/test_file_consumers.py @@ -8,19 +8,17 @@ homonym tests/test_game_data_homonyms.py forbids the resolver to serve. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from cross_reference import FileConsumers, entry_target +from generate_site import generate_system_page -from cross_reference import FileConsumers, entry_target # noqa: E402 -from generate_site import generate_system_page # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent _TMP = tempfile.TemporaryDirectory() _ROOT = Path(_TMP.name) diff --git a/tests/test_fileless_audit.py b/tests/test_fileless_audit.py index 62ba75023..53033a5b0 100644 --- a/tests/test_fileless_audit.py +++ b/tests/test_fileless_audit.py @@ -8,7 +8,7 @@ directory, and only a manual reading found it. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import sys import tempfile @@ -16,8 +16,6 @@ import unittest from pathlib import Path from unittest import mock -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - import fileless_audit ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_finalize_pack_names.py b/tests/test_finalize_pack_names.py index 7dff70d1c..901a2b597 100644 --- a/tests/test_finalize_pack_names.py +++ b/tests/test_finalize_pack_names.py @@ -7,7 +7,7 @@ attached to misterfpga by substring and checked against the full list: from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import sys @@ -16,9 +16,9 @@ import unittest import zipfile from pathlib import Path +from generate_pack import verify_and_finalize_packs + REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -from generate_pack import verify_and_finalize_packs # noqa: E402 class FinalizeByExactName(unittest.TestCase): diff --git a/tests/test_find_embedded.py b/tests/test_find_embedded.py index 451b788f8..3df63bdd6 100644 --- a/tests/test_find_embedded.py +++ b/tests/test_find_embedded.py @@ -3,7 +3,7 @@ the offset of every window that holds it, in a file or a ZIP member.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -18,10 +18,7 @@ import zlib from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import find_embedded # noqa: E402 +import find_embedded ROM = bytes(random.Random(8039).randrange(256) for _ in range(2048)) CRC = zlib.crc32(ROM) diff --git a/tests/test_find_pinned_revision.py b/tests/test_find_pinned_revision.py index 974010a55..5d96ac8d4 100644 --- a/tests/test_find_pinned_revision.py +++ b/tests/test_find_pinned_revision.py @@ -6,19 +6,14 @@ today's upstream no longer carries, but the bytes are in the project's history. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import unittest -from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import find_pinned_revision # noqa: E402 -import upstream # noqa: E402 +import find_pinned_revision +import upstream class ThePinnedRevisionIsInTheHistory(unittest.TestCase): diff --git a/tests/test_flycast_layout.py b/tests/test_flycast_layout.py index 3bbd01358..c549b7d47 100644 --- a/tests/test_flycast_layout.py +++ b/tests/test_flycast_layout.py @@ -9,7 +9,7 @@ and put every file one directory too deep. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import unittest from pathlib import Path diff --git a/tests/test_foreign_tree.py b/tests/test_foreign_tree.py index b8260e8af..c9b2e7726 100644 --- a/tests/test_foreign_tree.py +++ b/tests/test_foreign_tree.py @@ -9,20 +9,18 @@ to upstream PCSX2. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_db +from common import resolve_local_file -import generate_db # noqa: E402 -from common import resolve_local_file # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class ForeignTree(unittest.TestCase): diff --git a/tests/test_foreign_tree_names.py b/tests/test_foreign_tree_names.py index 258401f6b..a8a5b9b0a 100644 --- a/tests/test_foreign_tree_names.py +++ b/tests/test_foreign_tree_names.py @@ -9,20 +9,18 @@ served while data/bluemsx held the 8 KB one. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os import shutil -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import resolve_local_file -from common import resolve_local_file # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class ForeignTreeNames(unittest.TestCase): diff --git a/tests/test_frontend_digest.py b/tests/test_frontend_digest.py index a4ce6a5cd..27b367247 100644 --- a/tests/test_frontend_digest.py +++ b/tests/test_frontend_digest.py @@ -8,11 +8,10 @@ the pack and the manifest while verify, comparing md5, called it OK. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest import zipfile @@ -20,11 +19,11 @@ from pathlib import Path import yaml +from common import load_platform_config +from generate_pack import generate_manifest, generate_pack +from verify import verify_platform + REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -from common import load_platform_config # noqa: E402 -from generate_pack import generate_manifest, generate_pack # noqa: E402 -from verify import verify_platform # noqa: E402 class FrontendDigestDecides(unittest.TestCase): diff --git a/tests/test_game_catalogs.py b/tests/test_game_catalogs.py index ef3873ed3..638c3fa1a 100644 --- a/tests/test_game_catalogs.py +++ b/tests/test_game_catalogs.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import subprocess @@ -11,14 +11,13 @@ import tempfile import unittest from pathlib import Path +from region import REGIONS +from scripts.scraper import game_dat_importer as importer + ROOT = Path(__file__).resolve().parent.parent TMP_ROOT = ROOT / "tmp" / "tests" TMP_ROOT.mkdir(parents=True, exist_ok=True) FIXTURES = ROOT / "tests" / "fixtures" / "game_dats" -sys.path.insert(0, str(ROOT / "scripts")) - -from region import REGIONS # noqa: E402 -from scripts.scraper import game_dat_importer as importer # noqa: E402 try: from jsonschema import Draft202012Validator diff --git a/tests/test_game_data_homonyms.py b/tests/test_game_data_homonyms.py index 80ba9f87b..8542ef41a 100644 --- a/tests/test_game_data_homonyms.py +++ b/tests/test_game_data_homonyms.py @@ -12,19 +12,15 @@ carries `unsourceable:` until its own bytes are held. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os import re -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import ( # noqa: E402 +from common import ( build_zip_contents_index, load_data_dir_registry, load_database, @@ -33,6 +29,8 @@ from common import ( # noqa: E402 resolve_local_file, ) +REPO_ROOT = Path(__file__).resolve().parents[1] + def homonyms(claims: list[tuple[str, str, str, str]]) -> list[tuple[str, str, str]]: """(profile, destination, file) for name-only claims on a file that diff --git a/tests/test_game_headers.py b/tests/test_game_headers.py index 1b495bb66..69f1cc0ed 100644 --- a/tests/test_game_headers.py +++ b/tests/test_game_headers.py @@ -2,21 +2,19 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re -import sys import unittest from pathlib import Path import yaml -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +from common import load_emulator_profiles +from region import REGIONS -from common import load_emulator_profiles # noqa: E402 -from region import REGIONS # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent try: from jsonschema import Draft202012Validator diff --git a/tests/test_game_regions.py b/tests/test_game_regions.py index b3b76cf6d..37727c6cd 100644 --- a/tests/test_game_regions.py +++ b/tests/test_game_regions.py @@ -8,19 +8,17 @@ can lose its backing, then on the repository's own files. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import copy import json -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import game_rules +from common import load_emulator_profiles -import game_rules # noqa: E402 -from common import load_emulator_profiles # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] FIXTURES = REPO_ROOT / "tests" / "fixtures" / "game_rules" diff --git a/tests/test_games_index.py b/tests/test_games_index.py index 374f8e221..5cb8bfc51 100644 --- a/tests/test_games_index.py +++ b/tests/test_games_index.py @@ -7,7 +7,7 @@ so a test pins the join and not the state of the data. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import shutil @@ -16,14 +16,12 @@ import tempfile import unittest from pathlib import Path +import generate_games_index as gi +from romfolders import SystemResolver, load_setups + ROOT = Path(__file__).resolve().parent.parent TMP_ROOT = ROOT / "tmp" / "tests" TMP_ROOT.mkdir(parents=True, exist_ok=True) -sys.path.insert(0, str(ROOT / "scripts")) -sys.path.insert(0, str(ROOT)) - -import generate_games_index as gi # noqa: E402 -from romfolders import SystemResolver, load_setups # noqa: E402 SETUP = """\ setup: fixture diff --git a/tests/test_gap_settlement.py b/tests/test_gap_settlement.py index 917507662..529a14818 100644 --- a/tests/test_gap_settlement.py +++ b/tests/test_gap_settlement.py @@ -7,17 +7,15 @@ it. RetroArch names Galaksija's 4 KiB galaksija/rom1.bin, so DOSBox's from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from cross_reference import cross_reference +from validation import case_folded_slots, declaration_settles -from cross_reference import cross_reference # noqa: E402 -from validation import case_folded_slots, declaration_settles # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] SC55 = {"name": "ROM1.BIN", "path": "SC-55/ROM1.BIN", "size": 32768, "validation": ["size"], "required": True} diff --git a/tests/test_handheld_launchers.py b/tests/test_handheld_launchers.py index b8201acf3..1800a6254 100644 --- a/tests/test_handheld_launchers.py +++ b/tests/test_handheld_launchers.py @@ -10,7 +10,7 @@ the pad reaching the console, a compositor covering it) is not exercised. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -33,11 +33,10 @@ from pathlib import Path import yaml +import build_port + REPO_ROOT = Path(__file__).resolve().parent.parent PORTS = REPO_ROOT / "ports" -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import build_port # noqa: E402 _spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py") install = importlib.util.module_from_spec(_spec) diff --git a/tests/test_hash_merge.py b/tests/test_hash_merge.py index 83ee6a100..b6980a64c 100644 --- a/tests/test_hash_merge.py +++ b/tests/test_hash_merge.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import tempfile diff --git a/tests/test_hashing.py b/tests/test_hashing.py index 6237e4330..ebbcf8be6 100644 --- a/tests/test_hashing.py +++ b/tests/test_hashing.py @@ -2,19 +2,17 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import shutil -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import hashing -import hashing # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class HashesAreReadOncePerContent(unittest.TestCase): diff --git a/tests/test_hidden_extras.py b/tests/test_hidden_extras.py index bd4f8ff59..be5b01678 100644 --- a/tests/test_hidden_extras.py +++ b/tests/test_hidden_extras.py @@ -9,17 +9,15 @@ ROCKNIX's higan SGB1.sfc/program.rom under the file SGB1.sfc. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from packpaths import placement_block -from packpaths import placement_block # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class OneRule(unittest.TestCase): diff --git a/tests/test_identity.py b/tests/test_identity.py index 598e3ac37..6f09dde75 100644 --- a/tests/test_identity.py +++ b/tests/test_identity.py @@ -2,16 +2,13 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import shutil -import sys import tempfile import unittest from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) - import identity diff --git a/tests/test_install.py b/tests/test_install.py index 1169b23bf..9a5846aa1 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -1,7 +1,7 @@ """Tests for install.py platform detection and config parsing.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse import contextlib @@ -32,14 +32,13 @@ import urllib.error import zipfile from pathlib import Path, PurePosixPath +from tests.netguard import module_guard + REPO_ROOT = Path(__file__).resolve().parent.parent _spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py") install = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(install) -sys.path.insert(0, str(REPO_ROOT / "tests")) -from netguard import module_guard # noqa: E402 - # What a stale pin's failure says: the fix is one command. PIN_ADVICE = "install.py changed: python scripts/pin_installer.py rewrites both pins" @@ -477,7 +476,7 @@ class TheDataTreesCountInTheFreeSpace(unittest.TestCase): files the first installed.""" from types import SimpleNamespace - from test_install_selection import FakeRepository + from tests.test_install_selection import FakeRepository member = os.urandom(4096) results = [] @@ -1829,9 +1828,6 @@ class TargetFlagIsAppliedOrRefused(unittest.TestCase): self.assertEqual(targets[alias], targets["nintendo-switch"]) def test_every_alias_resolves_to_its_canonical_core_list(self): - import sys as _sys - - _sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import load_target_config for name in ("install/targets/retroarch.json",): @@ -1865,9 +1861,6 @@ class TargetFlagIsAppliedOrRefused(unittest.TestCase): "unknown target" on one side only, and a published null left behind once the builder filters a target makes the installer serve every core. """ - import sys as _sys - - _sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import list_available_targets, load_target_config platforms = str(REPO_ROOT / "platforms") @@ -2493,9 +2486,6 @@ class TestAvailablePlatforms(unittest.TestCase): def test_every_registered_platform_is_installable(self): """The installer serves every registered platform from its manifest.""" - import sys as _sys - - _sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import list_registered_platforms registered = set( @@ -2527,7 +2517,6 @@ class TestAvailablePlatforms(unittest.TestCase): def test_pin_script_writes_both_pins(self): """Every edit to install.py meant a sha256sum pasted by hand into two files with two syntaxes, and the failing test named no command.""" - sys.path.insert(0, str(REPO_ROOT / "scripts")) import pin_installer with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory: @@ -3418,7 +3407,6 @@ class CaseVariants(unittest.TestCase): folded = {e["dest"] for e in manifest["files"]} # A case-keeping RetroArch install is the Lakka list, less what # Lakka's own core packages install (installed_on: lakka). - sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import load_emulator_profiles installed = { @@ -4318,7 +4306,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): self.assertEqual(sorted(p.name for p in (bios / "dolphin-emu").iterdir()), ["Sys"]) def test_the_run_ends_on_the_archive_bytes_too(self): - from test_install_selection import FakeRepository + from tests.test_install_selection import FakeRepository member = os.urandom(300_000) with FakeRepository() as repo: @@ -4341,7 +4329,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): def test_the_plan_announces_the_archive_not_the_tree(self): """yaps2's tarball is 21.2 MB for a 6.5 MB tree, Cemu's 21.4 MB for 9.9 KB: the plan announced the tree, and the run downloaded far more.""" - from test_install_selection import FakeRepository + from tests.test_install_selection import FakeRepository member = b"profile" archive_size = 21_360_579 @@ -4483,7 +4471,6 @@ class DataDirectoriesAreInstalled(unittest.TestCase): manifest = json.loads((REPO_ROOT / "install" / "retroarch.json").read_text()) dirs = manifest.get("data_directories") or [] files = sum(len(d["files"]) for d in dirs) - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack written = generate_pack.PACK_DOCUMENTS + generate_pack.pack_markers( @@ -4733,7 +4720,7 @@ class ACheckThatFindsFilesMissingIsNoFailure(unittest.TestCase): BIOS folder to complete from a tool that never ran.""" def test_missing_is_3_and_a_failure_stays_1(self): - from test_install_selection import FakeRepository + from tests.test_install_selection import FakeRepository with FakeRepository() as repo: missing = repo.run("--no-input", "--check") @@ -7100,7 +7087,6 @@ class TheEventSchemaFileIsEventKeys(unittest.TestCase): outside Python could check a stream against.""" def _generator(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_event_schema return generate_event_schema @@ -7148,7 +7134,6 @@ class TheInstallerPageIsWrittenFromTheCode(unittest.TestCase): PAGE = REPO_ROOT / "wiki" / "installer.md" def setUp(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_installer_doc self.generator = generate_installer_doc @@ -7743,7 +7728,6 @@ class TheListVersionIsComparedWithTheSystems(unittest.TestCase): """A handheld without network installs from the pack: its manifest.json records the list's version, which generate_pack takes from the install list built with the same choices.""" - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack data = b"bios" install_list = {"version": "43.1", "files": [ diff --git a/tests/test_install_app.py b/tests/test_install_app.py index 2f30ec4ac..da29c43f3 100644 --- a/tests/test_install_app.py +++ b/tests/test_install_app.py @@ -8,7 +8,7 @@ menu) is not exercised. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import io @@ -23,13 +23,10 @@ import zipfile from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import install +from tests.test_install_selection import FakeRepository -import install # noqa: E402 -from test_install_selection import FakeRepository # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent INDEX = REPO_ROOT / "install" / "launchers" / "index.json" diff --git a/tests/test_install_cores.py b/tests/test_install_cores.py index 2f944e791..5766cfa52 100644 --- a/tests/test_install_cores.py +++ b/tests/test_install_cores.py @@ -8,7 +8,7 @@ which cores keep each system, the rule a pack built for a target follows. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io @@ -22,12 +22,10 @@ import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) +import install +from tests.test_install_selection import FakeRepository -import install # noqa: E402 -from test_install_selection import FakeRepository # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class CoreDirectories(unittest.TestCase): @@ -267,7 +265,6 @@ class TheBuildersOrder(unittest.TestCase): db_path = REPO_ROOT / "database.json" if not db_path.exists(): self.skipTest("database.json is not built") - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack as gp from common import load_emulator_profiles @@ -369,7 +366,6 @@ class APlatformOmissionKeepsItsClaim(unittest.TestCase): self.assertEqual(omitted, []) def test_the_generator_files_the_core_behind_the_platform(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack as gp held = {"cores": None} diff --git a/tests/test_install_experience.py b/tests/test_install_experience.py index 065bd22a9..e71d72537 100644 --- a/tests/test_install_experience.py +++ b/tests/test_install_experience.py @@ -7,7 +7,7 @@ honours Retry-After, and large files that resume where they stopped. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import errno @@ -25,12 +25,10 @@ import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) +import install +from tests.test_install_selection import FakeRepository -import install # noqa: E402 -from test_install_selection import FakeRepository # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PAYLOAD = bytes(range(256)) * 400 # 102400 bytes @@ -199,7 +197,6 @@ class ProgramsAreMarked(unittest.TestCase): the git mode cannot, hundreds of MAME archives carrying an execute bit.""" def test_header_decides(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack with tempfile.TemporaryDirectory() as tmp: @@ -227,7 +224,6 @@ class ManifestHashesMatchTheScan(unittest.TestCase): file holds, the same wrong value in two runs.""" def test_a_contradicted_hash_is_refused(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack with tempfile.TemporaryDirectory() as tmp: @@ -245,7 +241,6 @@ class ManifestHashesMatchTheScan(unittest.TestCase): """The retries went through the hash cache and got the first, wrong value back: one read of the file, then a refusal a second read would have avoided.""" - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack import hashing diff --git a/tests/test_install_expert.py b/tests/test_install_expert.py index a69dcdc63..1b7e21b75 100644 --- a/tests/test_install_expert.py +++ b/tests/test_install_expert.py @@ -9,7 +9,7 @@ platform and compare each (dest, sha1) with what the installer keeps. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import copy @@ -27,7 +27,6 @@ from pathlib import Path REPO_ROOT = Path(__file__).resolve().parent.parent # install.py runs on 3.8, the scripts it is compared with need 3.9. BUILDER_FLOOR = (3, 9) -sys.path.insert(0, str(REPO_ROOT / "scripts")) _spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py") install = importlib.util.module_from_spec(_spec) diff --git a/tests/test_install_filesystems.py b/tests/test_install_filesystems.py index 9f6adf31c..adf6761c5 100644 --- a/tests/test_install_filesystems.py +++ b/tests/test_install_filesystems.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import errno @@ -12,18 +12,15 @@ import json import os import shutil import subprocess -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) +import install +from tests.test_install_selection import FakeRepository -import install # noqa: E402 -from test_install_selection import FakeRepository # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class AndroidMediaScanner(unittest.TestCase): diff --git a/tests/test_install_from.py b/tests/test_install_from.py index f36d9125d..69980147a 100644 --- a/tests/test_install_from.py +++ b/tests/test_install_from.py @@ -11,7 +11,7 @@ never moved, and checked again once written. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import copy @@ -30,15 +30,13 @@ import zipfile from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) - -import install # noqa: E402 -from test_install_offline import ( # noqa: E402 +import install +from tests.test_install_offline import ( EXTRA, GBA, JP, PAYLOAD, US, Scratch, _entry, _offline_env, ) -from test_install_selection import FakeRepository # noqa: E402 +from tests.test_install_selection import FakeRepository + +REPO_ROOT = Path(__file__).resolve().parent.parent def _zip(path: Path, members: dict[str, bytes]) -> Path: diff --git a/tests/test_install_games.py b/tests/test_install_games.py index ccb1182f4..2bc52809d 100644 --- a/tests/test_install_games.py +++ b/tests/test_install_games.py @@ -8,7 +8,7 @@ index, published by scripts/generate_games_index.py. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import functools @@ -30,11 +30,10 @@ import zlib from pathlib import Path from unittest import mock +import install + REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) - -import install # noqa: E402 TMP_ROOT = REPO_ROOT / "tmp" / "tests" TMP_ROOT.mkdir(parents=True, exist_ok=True) diff --git a/tests/test_install_journeys.py b/tests/test_install_journeys.py index d48e0cb30..afb586c47 100644 --- a/tests/test_install_journeys.py +++ b/tests/test_install_journeys.py @@ -12,7 +12,7 @@ one that lengthens it has to say so here too. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import functools import hashlib @@ -29,13 +29,11 @@ import time import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) +import install +from tests import test_install_games as games +from tests.test_install_tui import DOWN, UP, Pty, pty, pyte -import install # noqa: E402 -import test_install_games as games # noqa: E402 -from test_install_tui import DOWN, UP, Pty, pty, pyte # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent END = "\x1b[F" ESC = "\x1b" diff --git a/tests/test_install_offline.py b/tests/test_install_offline.py index c6cdebaff..ef73adbcb 100644 --- a/tests/test_install_offline.py +++ b/tests/test_install_offline.py @@ -9,7 +9,7 @@ installs again from disk, --from-pack, every file checked by its hash. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -27,14 +27,11 @@ import unittest.mock import zipfile from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "scripts")) -sys.path.insert(0, str(REPO_ROOT / "tests")) +import install +import split_pack +from tests.test_install_selection import FakeRepository -import install # noqa: E402 -import split_pack # noqa: E402 -from test_install_selection import FakeRepository # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent US = b"us bios " * 64 JP = b"jp bios " * 64 @@ -435,7 +432,6 @@ class ABoardWithoutTheNetwork(Scratch): if p.is_file()} def test_the_builder_writes_both_into_the_pack_list(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack install_list = manifest() @@ -725,7 +721,7 @@ class OfflineMakesNoRequest(Scratch): learn its platform, since nothing said "make no request".""" def _served(self, *options: str, env: dict | None = None): - import test_install_selection + from tests import test_install_selection hits: list[str] = [] with FakeRepository() as repo, unittest.mock.patch.object( @@ -1029,7 +1025,7 @@ class OneOfflineVocabulary(Scratch): def test_the_command_suggested_keeps_the_offline_setting(self): """Sudo does not pass RETROBIOS_INSTALL_OFFLINE on.""" - import test_install_tui as tui + from tests import test_install_tui as tui args = tui._args(platform="retroarch", declared_only=False, offline=False) hint = install.Invocation() @@ -1048,7 +1044,7 @@ class OneOfflineVocabulary(Scratch): def test_the_screen_says_missing_not_failed(self): """On the full screen: "Finished with errors, 20 failed".""" - import test_install_tui as tui + from tests import test_install_tui as tui reason = f"not fetched: {install.OFFLINE_WORDS}" state = tui._installed_state(self.dest, 1, [{"dest": f"f{n}.bin", "reason": reason} diff --git a/tests/test_install_pack.py b/tests/test_install_pack.py index 817ed53ab..b6995c1ac 100644 --- a/tests/test_install_pack.py +++ b/tests/test_install_pack.py @@ -8,7 +8,7 @@ and a failure leaves no file behind. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse import functools diff --git a/tests/test_install_removal.py b/tests/test_install_removal.py index b5052493c..57a42a4fc 100644 --- a/tests/test_install_removal.py +++ b/tests/test_install_removal.py @@ -9,7 +9,7 @@ records no install writes (a crafted one, a drive that folds case). from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -18,7 +18,6 @@ import json import os import shutil import subprocess -import sys import tempfile import types import unittest @@ -26,12 +25,10 @@ import zipfile from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) +import install +from tests.test_install_selection import FakeRepository -import install # noqa: E402 -from test_install_selection import FakeRepository # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent try: import pty diff --git a/tests/test_install_selection.py b/tests/test_install_selection.py index 7b0a400e2..098b5e636 100644 --- a/tests/test_install_selection.py +++ b/tests/test_install_selection.py @@ -9,7 +9,7 @@ to one answer. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import functools @@ -30,10 +30,9 @@ import unittest from unittest import mock from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import region -import region # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent _spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py") install = importlib.util.module_from_spec(_spec) @@ -1375,7 +1374,6 @@ class ThePlatformsOwnSystemNamesAreAccepted(unittest.TestCase): source) def test_every_listed_system_gets_the_title_the_site_prints(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) from generate_pack import system_titles files = [{"dest": "a.bin", "systems": ["sony-playstation", "nintendo-gba"]}] diff --git a/tests/test_install_tui.py b/tests/test_install_tui.py index ed7634160..c72b432a7 100644 --- a/tests/test_install_tui.py +++ b/tests/test_install_tui.py @@ -9,7 +9,7 @@ installs it). from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse import contextlib @@ -40,16 +40,14 @@ import zipfile from pathlib import Path, PurePosixPath, PureWindowsPath from unittest import mock +import install +from tests.test_install_app import make_card +from tests.test_install_selection import FakeRepository, _QuietHandler +from tests.netguard import module_guard + REPO_ROOT = Path(__file__).resolve().parent.parent # install.py runs on 3.8, the scripts it is compared with need 3.9. BUILDER_FLOOR = (3, 9) -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "tests")) - -import install # noqa: E402 -from test_install_app import make_card # noqa: E402 -from test_install_selection import FakeRepository, _QuietHandler # noqa: E402 -from netguard import module_guard # noqa: E402 # No connection off the loopback and no card of the host reaches a test, in # this process or one it starts: 261 connections to @@ -3373,21 +3371,19 @@ class AReadErrorIsNotAClosedWindow(unittest.TestCase): import pty master, slave = pty.openpty() - screen = open(os.dup(slave), "w", encoding="utf-8") # noqa: SIM115 - terminal = mock.Mock(fd=slave, stdout=screen) try: - card = OSError(errno.EIO, "Input/output error", "/media/card/bios/x.bin") - self.assertFalse(install._closed_terminal(card, terminal)) - self.assertFalse(install._closed_terminal( - OSError(errno.ENOENT, "No such file"), terminal)) - os.close(master) - master = -1 - self.assertTrue(install._closed_terminal(card, terminal)) - self.assertTrue(install._closed_terminal(termios.error(errno.EIO, "gone"), - terminal)) + with open(os.dup(slave), "w", encoding="utf-8") as screen: + terminal = mock.Mock(fd=slave, stdout=screen) + card = OSError(errno.EIO, "Input/output error", "/media/card/bios/x.bin") + self.assertFalse(install._closed_terminal(card, terminal)) + self.assertFalse(install._closed_terminal( + OSError(errno.ENOENT, "No such file"), terminal)) + os.close(master) + master = -1 + self.assertTrue(install._closed_terminal(card, terminal)) + self.assertTrue(install._closed_terminal(termios.error(errno.EIO, "gone"), + terminal)) finally: - with contextlib.suppress(OSError): - screen.close() os.close(slave) if master >= 0: os.close(master) @@ -5076,7 +5072,7 @@ class SaveDirectoryRepository(FakeRepository): def _app_card(test: unittest.TestCase, system: str) -> tuple[Path, Path]: """A card of system in the repository's tmp/, its root and BIOS folder.""" - from test_install_app import make_card + from tests.test_install_app import make_card (REPO_ROOT / "tmp").mkdir(exist_ok=True) root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) @@ -5258,7 +5254,7 @@ class EndToEnd(unittest.TestCase): def card_repo(self, system: str) -> tuple[Path, Path]: - from test_install_app import AppRepository, make_card + from tests.test_install_app import AppRepository, make_card repo = self.repo(AppRepository) root = repo.root / "card" @@ -7599,7 +7595,7 @@ class _CardFixtures: regions: bool = True) -> tuple[Path, Path, dict]: """A list of plat's shape (the MinUI family records cores and regions, no system), the pack built from it and the files' payloads.""" - from test_install_offline import GBA, JP, US + from tests.test_install_offline import GBA, JP, US payloads = {"Bios/MGBA/gba_bios.bin": (GBA, "nintendo-gba", "mgba", None), "Bios/PS/scph5501.bin": (US, "sony-playstation", "pcsx_rearmed", @@ -7620,8 +7616,6 @@ class _CardFixtures: if sys.version_info < BUILDER_FLOOR: # generate_pack.py's context managers need Python 3.9. return listing, None, {} - sys.path.insert(0, str(REPO_ROOT / "scripts")) - self.addCleanup(sys.path.remove, str(REPO_ROOT / "scripts")) import generate_pack pack_list = {"files": [{"path": dest, "sha1": entry["sha1"], "size": entry["size"]} @@ -7864,7 +7858,7 @@ class _OutsideTextFindings: return out.getvalue() + err.getvalue() + events.getvalue() def test_a_pack_member_path_is_refused(self): - from test_install_offline import _pack, GBA + from tests.test_install_offline import _pack, GBA pack = _pack(self.root, "RetroArch_v1_BIOS_Pack.zip", {f"x{self.OSC}.bin": GBA}) text = self.run_install(_args(platform="retroarch", dest=self.dest, @@ -8461,7 +8455,7 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings, def test_a_pack_gets_the_menu_and_its_folder_named(self): """No menu and no folder before the copy, the pack's list recording no system.""" - from test_install_offline import _pack, PAYLOAD + from tests.test_install_offline import _pack, PAYLOAD downloads = self.root / "downloads" downloads.mkdir() @@ -9251,8 +9245,6 @@ class PacksWordingAndDocs(unittest.TestCase): @unittest.skipIf(sys.version_info < BUILDER_FLOOR, "generate_pack.py's context managers need Python 3.9") def test_a_pack_records_the_systems_of_its_files(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) - self.addCleanup(sys.path.remove, str(REPO_ROOT / "scripts")) import generate_pack install_list = {"files": [{"dest": "a.bin", "systems": ["3do"]}, @@ -9270,7 +9262,7 @@ class PacksWordingAndDocs(unittest.TestCase): self.assertIn("systems", schema["properties"]["files"]["items"]["properties"]) def pack(self, systems: bool) -> Path: - from test_install_offline import GBA, US + from tests.test_install_offline import GBA, US members = {"scph5501.bin": US, "gba_bios.bin": GBA} listed = [{"path": path, "sha1": hashlib.sha1(data).hexdigest(), @@ -9319,7 +9311,7 @@ class PacksWordingAndDocs(unittest.TestCase): def test_a_pack_cannot_write_escapes_through_its_system_names(self): """The titles and ids a pack records reached print() raw in the systems list.""" - from test_install_offline import GBA, US + from tests.test_install_offline import GBA, US members = {"scph5501.bin": US, "gba_bios.bin": GBA} listed = [{"path": path, "sha1": hashlib.sha1(data).hexdigest(), "size": len(data), @@ -10307,7 +10299,7 @@ class ScreenRowsAndFilters(unittest.TestCase): """Cannot create, then end 2 and nothing else.""" import subprocess - from test_install_offline import PAYLOAD, _offline_env, _pack + from tests.test_install_offline import PAYLOAD, _offline_env, _pack if os.name == "nt" or os.geteuid() == 0: self.skipTest("a folder that refuses writes is POSIX, and root writes anyway") @@ -10626,8 +10618,6 @@ class CardNamesAndHelp(_CardFixtures, unittest.TestCase): """The table left out the SHARE drives. It is generated: every card rule and SHARE drive file is a row, about.info among them.""" - sys.path.insert(0, str(REPO_ROOT / "scripts")) - self.addCleanup(sys.path.remove, str(REPO_ROOT / "scripts")) import generate_installer_doc page = (REPO_ROOT / "wiki" / "installer.md").read_text(encoding="utf-8") @@ -11257,22 +11247,20 @@ class MouseOnAPty(unittest.TestCase): master, slave = os.openpty() self.addCleanup(os.close, master) self.addCleanup(os.close, slave) - given = open(slave, encoding="utf-8", closefd=False) # noqa: SIM115 - shown = open(slave, "w", encoding="utf-8", closefd=False) # noqa: SIM115 - self.addCleanup(given.close) - self.addCleanup(shown.close) - terminal = install._TuiTerminal(given, shown) - terminal.mouse_allowed = True - terminal.enter() - terminal.set_mouse(True) - problems = install._tui_cleanup(terminal, [], {}, fresh_state()) - self.assertEqual(problems, []) - raw = b"" - while select.select([master], [], [], 0.2)[0]: - raw += os.read(master, 65536) - for mode in (b"1000", b"1006"): - self.assertGreater(raw.rfind(b"\x1b[?" + mode + b"l"), - raw.rfind(b"\x1b[?" + mode + b"h")) + with open(slave, encoding="utf-8", closefd=False) as given, \ + open(slave, "w", encoding="utf-8", closefd=False) as shown: + terminal = install._TuiTerminal(given, shown) + terminal.mouse_allowed = True + terminal.enter() + terminal.set_mouse(True) + problems = install._tui_cleanup(terminal, [], {}, fresh_state()) + self.assertEqual(problems, []) + raw = b"" + while select.select([master], [], [], 0.2)[0]: + raw += os.read(master, 65536) + for mode in (b"1000", b"1006"): + self.assertGreater(raw.rfind(b"\x1b[?" + mode + b"l"), + raw.rfind(b"\x1b[?" + mode + b"h")) def _painted_roles(text: str, style: str = "", colour: bool = True) -> list[tuple[str, str]]: @@ -12854,7 +12842,7 @@ class TapsOnAPtySeeFirst(unittest.TestCase): term.close() def test_the_game_data_row_keeps_the_ticks_to_the_install(self): - from test_install_tui import GameDataRepository + from tests.test_install_tui import GameDataRepository repo = self.repo(GameDataRepository) term = self.start() @@ -14704,8 +14692,6 @@ class ProvenCardsAndCounts(unittest.TestCase): def test_which_pack_names_the_first_screen(self): """Which-pack said the command opens a screen where Install and Choose systems are, the second screen.""" - sys.path.insert(0, str(REPO_ROOT / "scripts")) - self.addCleanup(sys.path.remove, str(REPO_ROOT / "scripts")) import generate_site words = " ".join(generate_site.first_screen_words()) @@ -15285,7 +15271,7 @@ class GamesEndToEnd(unittest.TestCase): """The real --tui on a card with games, against a loopback repository.""" def test_the_plan_opens_on_the_games_and_installs_only_them(self): - import test_install_games as games + from tests import test_install_games as games card = games.Card() self.addCleanup(card.close) @@ -16177,7 +16163,6 @@ class EmulatorChoiceMatchesTheEmulatorPack(unittest.TestCase): if sys.version_info < BUILDER_FLOOR: # The builder's floor: install.py alone keeps 3.8. raise unittest.SkipTest("generate_pack.py needs Python 3.9 or newer") - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack as gp from common import build_zip_contents_index diff --git a/tests/test_lakka_targets.py b/tests/test_lakka_targets.py index e4fb1cb31..de7ba49c1 100644 --- a/tests/test_lakka_targets.py +++ b/tests/test_lakka_targets.py @@ -7,7 +7,7 @@ platform outright. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import unittest diff --git a/tests/test_large_file_cache.py b/tests/test_large_file_cache.py index c78e79e98..2b4b7d925 100644 --- a/tests/test_large_file_cache.py +++ b/tests/test_large_file_cache.py @@ -8,14 +8,13 @@ that then replaced the cache entry. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import io import json import os import shutil -import sys import tempfile import threading import unittest @@ -23,8 +22,6 @@ import urllib.error from pathlib import Path from unittest import mock -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - import common import largefiles import check_release_assets diff --git a/tests/test_launcher_aliases.py b/tests/test_launcher_aliases.py index 76d1456ff..a1a5e6b5f 100644 --- a/tests/test_launcher_aliases.py +++ b/tests/test_launcher_aliases.py @@ -19,7 +19,7 @@ Three checks read the committed data: from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re import unittest diff --git a/tests/test_launcher_evidence.py b/tests/test_launcher_evidence.py index 8c1aca155..4d17179d4 100644 --- a/tests/test_launcher_evidence.py +++ b/tests/test_launcher_evidence.py @@ -7,14 +7,11 @@ build the platform ships loads the file and reads each key (config_reads). from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) - import yaml from common import load_platform_config diff --git a/tests/test_launcher_gaps.py b/tests/test_launcher_gaps.py index 3e698b321..0f61b0f38 100644 --- a/tests/test_launcher_gaps.py +++ b/tests/test_launcher_gaps.py @@ -10,7 +10,7 @@ two emulators, and a name held under another casing. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -25,8 +25,6 @@ import unittest from pathlib import Path from unittest import mock -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - import yaml import verify diff --git a/tests/test_launcher_layer.py b/tests/test_launcher_layer.py index 9034ec4ca..09d2d5d3e 100644 --- a/tests/test_launcher_layer.py +++ b/tests/test_launcher_layer.py @@ -8,19 +8,16 @@ and a fixed path the launcher passes (Batocera's x16emu shape). from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import inspect import os import shutil -import sys import tempfile import unittest import zipfile -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - import yaml from common import _emulator_profiles_cache, load_emulator_profiles, load_platform_config diff --git a/tests/test_launcher_paths.py b/tests/test_launcher_paths.py index a4e1565bd..d19388253 100644 --- a/tests/test_launcher_paths.py +++ b/tests/test_launcher_paths.py @@ -10,19 +10,15 @@ extractor writes. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from launchers import handed_directories, standalone_bindings # noqa: E402 -from scraper import retrobat_launchers as rl # noqa: E402 -from scraper.batocera_launchers import ( # noqa: E402 +from launchers import handed_directories, standalone_bindings +from scraper import retrobat_launchers as rl +from scraper.batocera_launchers import ( GENERATORS, IMPORTER, PATHS_MODULE, @@ -32,6 +28,8 @@ from scraper.batocera_launchers import ( # noqa: E402 working_directories, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + PATCH = "package/batocera/emulators/citron/002-adjust-paths.patch" PATCH_TEXT = textwrap.dedent("""\ diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp diff --git a/tests/test_launcher_placement.py b/tests/test_launcher_placement.py index fba05cc0c..3512fb631 100644 --- a/tests/test_launcher_placement.py +++ b/tests/test_launcher_placement.py @@ -9,13 +9,12 @@ and a platform with no such record keeps the profile's layout. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import io import json import shutil -import sys import tempfile import unittest import zipfile @@ -24,18 +23,17 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import ( # noqa: E402 +from common import ( _emulator_profiles_cache, load_emulator_profiles, load_platform_config, platform_layouts, standalone_set, ) -from generate_pack import generate_manifest, generate_pack # noqa: E402 -from verify import verify_platform # noqa: E402 +from generate_pack import generate_manifest, generate_pack +from verify import verify_platform + +REPO_ROOT = Path(__file__).resolve().parents[1] WORKING_DIRECTORY = { "emulator": "kick", "build": "standalone", "kind": "passes_path", "names": [], diff --git a/tests/test_launchers.py b/tests/test_launchers.py index d59449abb..4350948c5 100644 --- a/tests/test_launchers.py +++ b/tests/test_launchers.py @@ -8,20 +8,16 @@ is checked against the revision itself. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import dataclasses 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 scraper.batocera_launchers import ( # noqa: E402 +from scraper.batocera_launchers import ( CONFIGGEN, GENERATORS, IMPORTER, @@ -35,7 +31,9 @@ from scraper.batocera_launchers import ( # noqa: E402 hatari, lexaloffle, ) -from scraper.retropie_launchers import Launcher as PackageLauncher # noqa: E402 +from scraper.retropie_launchers import Launcher as PackageLauncher + +REPO_ROOT = Path(__file__).resolve().parent.parent PATHS = """from pathlib import Path from typing import Final diff --git a/tests/test_launchers_amberelec.py b/tests/test_launchers_amberelec.py index 39ce37130..112f48a3b 100644 --- a/tests/test_launchers_amberelec.py +++ b/tests/test_launchers_amberelec.py @@ -8,20 +8,18 @@ that is gone must stop the scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import amberelec_launchers as al +from scraper.configgen_launchers import LauncherShapeError -from scraper import amberelec_launchers as al # noqa: E402 -from scraper.configgen_launchers import LauncherShapeError # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent def text(block: str) -> str: diff --git a/tests/test_launchers_emudeck.py b/tests/test_launchers_emudeck.py index acd606440..4a1b85dfb 100644 --- a/tests/test_launchers_emudeck.py +++ b/tests/test_launchers_emudeck.py @@ -8,21 +8,19 @@ fixture's own lines, and a construct that is gone must stop the scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import emudeck_launchers as el +from scraper.emudeck_scraper import launcher_revision +from scraper.shell_launchers import LauncherPatternMissing, RepoTree, words -from scraper import emudeck_launchers as el # noqa: E402 -from scraper.emudeck_scraper import launcher_revision # noqa: E402 -from scraper.shell_launchers import LauncherPatternMissing, RepoTree, words # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent S = el.EMUSCRIPTS diff --git a/tests/test_launchers_emuelec.py b/tests/test_launchers_emuelec.py index 8ab6fa3fe..620be9c78 100644 --- a/tests/test_launchers_emuelec.py +++ b/tests/test_launchers_emuelec.py @@ -9,21 +9,19 @@ must stop the scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import emuelec_launchers as el +from scraper.emuelec_scraper import launcher_revision +from scraper.shell_launchers import LauncherPatternMissing, RepoTree -from scraper import emuelec_launchers as el # noqa: E402 -from scraper.emuelec_scraper import launcher_revision # noqa: E402 -from scraper.shell_launchers import LauncherPatternMissing, RepoTree # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent EMU = el.EMULATORS diff --git a/tests/test_launchers_knulli.py b/tests/test_launchers_knulli.py index 16500d681..aca3834af 100644 --- a/tests/test_launchers_knulli.py +++ b/tests/test_launchers_knulli.py @@ -8,21 +8,19 @@ gone must stop the scrape instead of returning nothing. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import knulli_launchers as kl +from scraper.batocera_launchers import hatari, melonds +from scraper.configgen_launchers import LauncherShapeError -from scraper import knulli_launchers as kl # noqa: E402 -from scraper.batocera_launchers import hatari, melonds # noqa: E402 -from scraper.configgen_launchers import LauncherShapeError # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent G = kl.GENERATORS diff --git a/tests/test_launchers_recalbox.py b/tests/test_launchers_recalbox.py index 4f5211862..95295b4b5 100644 --- a/tests/test_launchers_recalbox.py +++ b/tests/test_launchers_recalbox.py @@ -8,10 +8,9 @@ is checked against the tag itself. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import unittest from collections.abc import Callable from pathlib import Path @@ -19,11 +18,8 @@ from unittest import mock import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from scraper import recalbox_scraper # noqa: E402 -from scraper.recalbox_launchers import ( # noqa: E402 +from scraper import recalbox_scraper +from scraper.recalbox_launchers import ( ALL_CORES, AMIBERRY_CONFIG, AMIBERRY_GLOBAL, @@ -62,7 +58,9 @@ from scraper.recalbox_launchers import ( # noqa: E402 xroar, ) -from tests.test_launchers import placed # noqa: E402 +from tests.test_launchers import placed + +REPO_ROOT = Path(__file__).resolve().parent.parent # recalboxFiles.py:1-12, 173-174 FILES_MODULE_BLOCKS = { diff --git a/tests/test_launchers_retrobat.py b/tests/test_launchers_retrobat.py index c1be16844..1eb944cf0 100644 --- a/tests/test_launchers_retrobat.py +++ b/tests/test_launchers_retrobat.py @@ -8,19 +8,17 @@ the fixture's own lines, and a construct that is gone must stop the scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import textwrap import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import retrobat_launchers as rl +from scraper.retrobat_scraper import launcher_revision -from scraper import retrobat_launchers as rl # noqa: E402 -from scraper.retrobat_scraper import launcher_revision # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent G = rl.GENERATORS diff --git a/tests/test_launchers_retrodeck.py b/tests/test_launchers_retrodeck.py index e894d6838..9917b864c 100644 --- a/tests/test_launchers_retrodeck.py +++ b/tests/test_launchers_retrodeck.py @@ -8,19 +8,17 @@ cites. A construct that is gone or unknown must stop the scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import retrodeck_launchers as rd -from scraper import retrodeck_launchers as rd # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent def at(first_line: int, text: str) -> str: diff --git a/tests/test_launchers_retropie.py b/tests/test_launchers_retropie.py index fa1b74150..ca6048545 100644 --- a/tests/test_launchers_retropie.py +++ b/tests/test_launchers_retropie.py @@ -8,22 +8,20 @@ cites. A construct that is gone or unknown must stop the scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import dataclasses import json -import sys import textwrap import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import batocera_launchers +from scraper import retropie_launchers as rl -from scraper import batocera_launchers # noqa: E402 -from scraper import retropie_launchers as rl # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent EMULATORS = "scriptmodules/emulators" LIBRETRO = "scriptmodules/libretrocores" diff --git a/tests/test_launchers_rocknix.py b/tests/test_launchers_rocknix.py index 730645c63..a27647f08 100644 --- a/tests/test_launchers_rocknix.py +++ b/tests/test_launchers_rocknix.py @@ -9,21 +9,19 @@ configs differ, and a construct that is gone must stop the scrape. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from scraper import rocknix_launchers as rl +from scraper.rocknix_scraper import launcher_revision +from scraper.shell_launchers import LauncherPatternMissing, RepoTree -from scraper import rocknix_launchers as rl # noqa: E402 -from scraper.rocknix_scraper import launcher_revision # noqa: E402 -from scraper.shell_launchers import LauncherPatternMissing, RepoTree # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent SA = rl.STANDALONE diff --git a/tests/test_libretro_layout.py b/tests/test_libretro_layout.py index 6b0aa29fb..4bb8e8ef7 100644 --- a/tests/test_libretro_layout.py +++ b/tests/test_libretro_layout.py @@ -9,23 +9,21 @@ Sys from system/dolphin-emu/Sys and keeps User in the save directory. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from packpaths import _resolve_destination # noqa: E402 -from validation import ( # noqa: E402 +from packpaths import _resolve_destination +from validation import ( outside_gap_scope, read_from_save_dir, read_from_system_dir, ) +REPO_ROOT = Path(__file__).resolve().parents[1] + class PathIsTheDestination(unittest.TestCase): def test_no_prefix_on_a_file(self): diff --git a/tests/test_libretro_slugs.py b/tests/test_libretro_slugs.py index 1d571b002..97cc16b15 100644 --- a/tests/test_libretro_slugs.py +++ b/tests/test_libretro_slugs.py @@ -9,16 +9,14 @@ duplicate system carrying the quasi88 group. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path import yaml REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class ScrapedSystemIdsAreSlugs(unittest.TestCase): diff --git a/tests/test_maker_folder_names.py b/tests/test_maker_folder_names.py index cffe035af..856993a79 100644 --- a/tests/test_maker_folder_names.py +++ b/tests/test_maker_folder_names.py @@ -11,7 +11,7 @@ remains. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json @@ -25,14 +25,13 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_db +import generate_pack as builder +import generate_site +from verify import verify_platform -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -import generate_site # noqa: E402 -from verify import verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent MSX_DISK = b"M" * 16384 PC88_DISK = b"N" * 2048 diff --git a/tests/test_mame_devices.py b/tests/test_mame_devices.py index 5965f4050..defb2405f 100644 --- a/tests/test_mame_devices.py +++ b/tests/test_mame_devices.py @@ -9,7 +9,7 @@ filed under the systems of the machines that can load it, never guessed. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import io import json @@ -626,9 +626,6 @@ class APickReadsTheEntrySystems(unittest.TestCase): self.assertTrue(entry_serves_systems({}, profile, ["snk-neogeo-mvs"])) def test_the_gap_report_and_the_extras_carry_them(self): - import sys - - sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) from packextras import _collect_emulator_extras, _extra_system_ids from verify import find_undeclared_files @@ -1009,7 +1006,7 @@ class TheRepositoryProfile(unittest.TestCase): class Cli(unittest.TestCase): def test_devices_needs_a_listxml(self): - from scripts.scraper.mame_hash_scraper import build_parser, main # noqa: F401 + from scripts.scraper.mame_hash_scraper import main import sys from unittest import mock diff --git a/tests/test_mame_parser.py b/tests/test_mame_parser.py index c163e845b..c2cb59a4d 100644 --- a/tests/test_mame_parser.py +++ b/tests/test_mame_parser.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import tempfile diff --git a/tests/test_mame_ref_audit.py b/tests/test_mame_ref_audit.py index 210381ab8..5e1cf059c 100644 --- a/tests/test_mame_ref_audit.py +++ b/tests/test_mame_ref_audit.py @@ -7,15 +7,12 @@ found nineteen stale refs in one driver where profile_sync had flagged five. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import unittest from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - import mame_ref_audit from mame_ref_audit import declares diff --git a/tests/test_manifest_entry.py b/tests/test_manifest_entry.py index cf6022218..f35740427 100644 --- a/tests/test_manifest_entry.py +++ b/tests/test_manifest_entry.py @@ -9,20 +9,18 @@ an empty repo_path, and the installer refused the whole manifest. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import json -import sys import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_pack as gp +from manifestselect import SelectionIndex -import generate_pack as gp # noqa: E402 -from manifestselect import SelectionIndex # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent def _held_file(db: dict) -> tuple[str, dict] | None: diff --git a/tests/test_md5_pack_context.py b/tests/test_md5_pack_context.py index 078d36bb6..b2fe0c960 100644 --- a/tests/test_md5_pack_context.py +++ b/tests/test_md5_pack_context.py @@ -8,7 +8,7 @@ the bare file names under a pack called Standalone. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import subprocess @@ -75,7 +75,6 @@ class SystemAndEmulatorPacksKeepTheirNames(unittest.TestCase): import yaml - sys.path.insert(0, str(REPO_ROOT / "scripts")) import common import generate_db import generate_pack as gp diff --git a/tests/test_measurements.py b/tests/test_measurements.py index 61fb94f04..d81c319ad 100644 --- a/tests/test_measurements.py +++ b/tests/test_measurements.py @@ -8,26 +8,25 @@ against HEAD. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import copy import html +import importlib.util import json import os import re import shutil import sqlite3 import subprocess -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import measurement_records as mr +import sitemeasurements as sm -import measurement_records as mr # noqa: E402 -import sitemeasurements as sm # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent REPO_URL = "https://github.com/Abdess/retrobios" COMMIT = "e" * 40 @@ -300,7 +299,9 @@ class ReadAndIndex(Workspace): tables = [row[0] for row in connection.execute( "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY rowid")] self.assertEqual(tuple(tables), sm.TABLES) - count = lambda table: connection.execute(f"SELECT COUNT(*) FROM {table}").fetchone()[0] # noqa: E731 + def count(table: str) -> int: + return connection.execute(f"SELECT COUNT(*) FROM {table}").fetchone()[0] + records = [s.record for s in mr.read_records(self.tree)] self.assertEqual(count("runs"), len(records)) self.assertEqual(count("checks"), sum(1 for r in records if r.get("check"))) @@ -373,9 +374,7 @@ class ReadAndIndex(Workspace): self.assertTrue(list(Draft202012Validator(schema).iter_errors(record))) def test_a_version_4_record_needs_its_verdicts(self) -> None: - try: - from jsonschema import Draft202012Validator # noqa: F401 - except ImportError: + if importlib.util.find_spec("jsonschema") is None: self.skipTest("jsonschema is not installed") import validate_schemas diff --git a/tests/test_minui_platform.py b/tests/test_minui_platform.py index 5e6ed3ef3..206af8d01 100644 --- a/tests/test_minui_platform.py +++ b/tests/test_minui_platform.py @@ -11,7 +11,7 @@ profiles, placed below that folder. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -19,7 +19,6 @@ import io import json import os import shutil -import sys import tempfile import unittest import zipfile @@ -28,12 +27,10 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) -sys.path.insert(0, str(REPO_ROOT)) +from common import load_emulator_profiles, load_platform_config +from scraper import minui_scraper -from common import load_emulator_profiles, load_platform_config # noqa: E402 -from scraper import minui_scraper # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent MINARCH = ( "void Core_open(const char* core_path, const char* tag_name) {\n" diff --git a/tests/test_name_tiebreak.py b/tests/test_name_tiebreak.py index 347a8cb93..f8c7d1f32 100644 --- a/tests/test_name_tiebreak.py +++ b/tests/test_name_tiebreak.py @@ -7,17 +7,15 @@ without `validation: [size]` keeps its informative status. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import _by_affinity -from common import _by_affinity # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class DeclaredSizeOrders(unittest.TestCase): diff --git a/tests/test_native_mode.py b/tests/test_native_mode.py index 51bf58895..dd089059e 100644 --- a/tests/test_native_mode.py +++ b/tests/test_native_mode.py @@ -10,19 +10,17 @@ it, and these tests make the agreement checkable instead of reviewable. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io import json -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import nativemode -import nativemode # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class ModeVocabulary(unittest.TestCase): @@ -86,7 +84,9 @@ class BothConsumersAgree(unittest.TestCase): def test_builder_and_verifier_share_one_predicate(self): from generate_pack import _intentional_hash_exclusion - from verify import compute_severity # noqa: F401 (import proves wiring) + from verify import compute_severity + + self.assertTrue(callable(compute_severity)) for mode in nativemode.MODES: # No entries is never an exclusion, whatever the mode. diff --git a/tests/test_nec_filing.py b/tests/test_nec_filing.py index 329cf7f08..bfa49f606 100644 --- a/tests/test_nec_filing.py +++ b/tests/test_nec_filing.py @@ -9,14 +9,12 @@ no PC-88 emulator reads. Reads the repository. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) PC98 = {"pc-98", "nec-pc-98"} PC88 = {"nec-pc-88", "nec-pc-80"} diff --git a/tests/test_no_case_collisions.py b/tests/test_no_case_collisions.py index 027b4df1b..ac8c4fbbd 100644 --- a/tests/test_no_case_collisions.py +++ b/tests/test_no_case_collisions.py @@ -1,6 +1,6 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import subprocess import unittest @@ -74,9 +74,6 @@ class SharedGroupsAddNoSecondSpelling(unittest.TestCase): and verify counted one more required file.""" def test_no_group_entry_respells_a_declared_destination(self) -> None: - import sys - - sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import ( list_registered_platforms, load_emulator_profiles, @@ -120,9 +117,6 @@ class Np2kaiRhythmSamplesAreTwoSets(unittest.TestCase): from the profile shipped one spelling and reported both OK.""" def test_each_spelling_is_its_own_entry(self): - import sys - - sys.path.insert(0, str(REPO_ROOT / "scripts")) from common import load_emulator_profiles files = load_emulator_profiles(str(REPO_ROOT / "emulators"))["np2kai"]["files"] diff --git a/tests/test_no_game_data.py b/tests/test_no_game_data.py index 42a9d571f..44be1a6ee 100644 --- a/tests/test_no_game_data.py +++ b/tests/test_no_game_data.py @@ -9,7 +9,7 @@ full manifest. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import functools @@ -28,16 +28,14 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) -sys.path.insert(0, str(REPO_ROOT)) +import common +import generate_db +import generate_pack as builder +import install +import packverify +import verify -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -import install # noqa: E402 -import packverify # noqa: E402 -import verify # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PAYLOADS = { "System/firmware.rom": b"firmware of the console", diff --git a/tests/test_np2_fonts.py b/tests/test_np2_fonts.py index 0ff2196dd..97e8d4431 100644 --- a/tests/test_np2_fonts.py +++ b/tests/test_np2_fonts.py @@ -9,22 +9,20 @@ which fontpc98_read cannot parse, and FONT.ROM was never placed under its name. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os import shutil -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import resolve_local_file -from common import resolve_local_file # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] V98_SIZE = 0x46800 diff --git a/tests/test_optional_dependencies.py b/tests/test_optional_dependencies.py index 241d0d07a..d96f09466 100644 --- a/tests/test_optional_dependencies.py +++ b/tests/test_optional_dependencies.py @@ -7,7 +7,7 @@ fifteen errors instead of skipped schema checks. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import re diff --git a/tests/test_owner_resolution.py b/tests/test_owner_resolution.py index 70141c51a..10b4f5fa9 100644 --- a/tests/test_owner_resolution.py +++ b/tests/test_owner_resolution.py @@ -9,26 +9,24 @@ armsx2's pack ships without a reader, and MAME's neogeo.zip without MAME. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import cross_reference # noqa: E402 -import slots # noqa: E402 -from common import ( # noqa: E402 +import cross_reference +import slots +from common import ( build_zip_contents_index, load_database, load_emulator_profiles, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + class ReadersNameTheOwner(unittest.TestCase): @classmethod diff --git a/tests/test_pack_conformance_dirs.py b/tests/test_pack_conformance_dirs.py index 659564f6c..28356cb5f 100644 --- a/tests/test_pack_conformance_dirs.py +++ b/tests/test_pack_conformance_dirs.py @@ -8,20 +8,18 @@ all and never judged. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_pack as gp +import packverify -import generate_pack as gp # noqa: E402 -import packverify # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class ConformanceUsesTheRunDirectories(unittest.TestCase): diff --git a/tests/test_pack_core_extras.py b/tests/test_pack_core_extras.py index 9e659369b..b7df27caf 100644 --- a/tests/test_pack_core_extras.py +++ b/tests/test_pack_core_extras.py @@ -9,11 +9,10 @@ builder's in the same run. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest import zipfile @@ -21,10 +20,9 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import packverify -import packverify # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent def _held(files: dict, by_name: dict, path: str, payload: bytes) -> str: diff --git a/tests/test_pack_counts.py b/tests/test_pack_counts.py index bdb0ed3ed..2e5ed4d47 100644 --- a/tests/test_pack_counts.py +++ b/tests/test_pack_counts.py @@ -10,7 +10,7 @@ installer fetches and leaves out the data directories a pack also carries. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import io @@ -25,23 +25,20 @@ from unittest import mock import yaml try: - import jsonschema # noqa: F401 + import jsonschema except ImportError: - HAS_JSONSCHEMA = False -else: - HAS_JSONSCHEMA = True + jsonschema = None +import common +import generate_db +import generate_pack as builder +import generate_readme +import generate_site +import release_notes +import release_record +import split_pack +HAS_JSONSCHEMA = jsonschema is not None REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -import generate_readme # noqa: E402 -import generate_site # noqa: E402 -import release_notes # noqa: E402 -import release_record # noqa: E402 -import split_pack # noqa: E402 PROFILE = """\ emulator: Demo diff --git a/tests/test_pack_destinations.py b/tests/test_pack_destinations.py index cf41ce6a3..d832e491e 100644 --- a/tests/test_pack_destinations.py +++ b/tests/test_pack_destinations.py @@ -9,7 +9,7 @@ it and counted one more file from the cores. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib @@ -17,7 +17,6 @@ import io import json import os import shutil -import sys import tempfile import unittest import zipfile @@ -26,7 +25,6 @@ from pathlib import Path import yaml REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class _Fixture(unittest.TestCase): diff --git a/tests/test_pack_failures.py b/tests/test_pack_failures.py index d335377c7..d521a270f 100644 --- a/tests/test_pack_failures.py +++ b/tests/test_pack_failures.py @@ -7,20 +7,18 @@ keep serving from an older run, left the run green. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse import os -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_pack as gp -import generate_pack as gp # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] def _boom(*args, **kwargs): diff --git a/tests/test_pack_file_names.py b/tests/test_pack_file_names.py index 78f5ac048..37d38e62a 100644 --- a/tests/test_pack_file_names.py +++ b/tests/test_pack_file_names.py @@ -7,7 +7,7 @@ verify reported the same scope OK. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import sys @@ -15,10 +15,9 @@ import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from generate_pack import _name_part, generate_emulator_pack -from generate_pack import _name_part, generate_emulator_pack # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class PackFileNames(unittest.TestCase): diff --git a/tests/test_pack_grouping.py b/tests/test_pack_grouping.py index f7cf06114..9eba81986 100644 --- a/tests/test_pack_grouping.py +++ b/tests/test_pack_grouping.py @@ -8,15 +8,13 @@ ruled undecidable, and the keep overrode the drop. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class SlotPassReadsTheRegionGrouping(unittest.TestCase): diff --git a/tests/test_pack_integrity.py b/tests/test_pack_integrity.py index 0fa857329..b26cc3f19 100644 --- a/tests/test_pack_integrity.py +++ b/tests/test_pack_integrity.py @@ -14,7 +14,7 @@ date pack stays a failure. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import glob import os @@ -32,7 +32,6 @@ def _pack_path(platform_name: str) -> str | None: """Path of the platform's full pack, by the exact name the builder writes.""" if not os.path.isdir(DIST_DIR): return None - sys.path.insert(0, os.path.join(REPO_ROOT, "scripts")) from generate_pack import _expected_pack_names names = _expected_pack_names([platform_name], PLATFORMS_DIR, [], None) @@ -44,7 +43,6 @@ def _pack_path(platform_name: str) -> str | None: def _registered_platforms() -> list[str]: - sys.path.insert(0, os.path.join(REPO_ROOT, "scripts")) from common import list_registered_platforms return list_registered_platforms(PLATFORMS_DIR) @@ -57,7 +55,6 @@ def _profiles_newer_than(path: str, platform_name: str) -> list[str]: comment edited in any of 500 profiles used to disarm the integrity check of every pack on disk. """ - sys.path.insert(0, os.path.join(REPO_ROOT, "scripts")) from common import load_emulator_profiles, load_platform_config, resolve_platform_cores built = os.path.getmtime(path) diff --git a/tests/test_pack_member_identity.py b/tests/test_pack_member_identity.py index 9cc0fc826..10574805d 100644 --- a/tests/test_pack_member_identity.py +++ b/tests/test_pack_member_identity.py @@ -8,21 +8,20 @@ recognised by their members. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import io import json import re -import sys import tempfile import unittest import zipfile from pathlib import Path +from packverify import verify_pack + REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -from packverify import verify_pack # noqa: E402 class MembersMustBeKnown(unittest.TestCase): @@ -93,7 +92,6 @@ class OneComparisonOfArchiveMembers(unittest.TestCase): import tempfile import zipfile - sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) from packverify import _same_members def archive(members: dict) -> bytes: diff --git a/tests/test_pack_probe.py b/tests/test_pack_probe.py index f68a017bd..6811304b4 100644 --- a/tests/test_pack_probe.py +++ b/tests/test_pack_probe.py @@ -11,7 +11,7 @@ on disk. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io @@ -22,15 +22,12 @@ import unittest import zipfile from pathlib import Path + +import measurement_records as mr +import pack_probe as pp + REPO_ROOT = Path(__file__).resolve().parent.parent -import sys # noqa: E402 - -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import measurement_records as mr # noqa: E402 -import pack_probe as pp # noqa: E402 - TMP = REPO_ROOT / "tmp" / "tests" / "pack_probe" SATURN = { diff --git a/tests/test_pack_readme.py b/tests/test_pack_readme.py index 83748d59c..f8c47a612 100644 --- a/tests/test_pack_readme.py +++ b/tests/test_pack_readme.py @@ -8,19 +8,17 @@ does not have, while the registry names the path. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from packreadme import _build_readme -from packreadme import _build_readme # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] def _extract_lines(text: str) -> list[str]: diff --git a/tests/test_path_conflict_status.py b/tests/test_path_conflict_status.py index 653064812..81edf6df0 100644 --- a/tests/test_path_conflict_status.py +++ b/tests/test_path_conflict_status.py @@ -8,26 +8,24 @@ from the collection read as covered in the pack report and as missing in verify. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib import io import re -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_db +import generate_pack as builder +from verify import verify_platform -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -from verify import verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class ConflictingDeclarations(unittest.TestCase): diff --git a/tests/test_path_null_copies.py b/tests/test_path_null_copies.py index d3b583c5e..5b9b14018 100644 --- a/tests/test_path_null_copies.py +++ b/tests/test_path_null_copies.py @@ -8,15 +8,13 @@ Reads the repository: skips when the database is absent. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class NoPathNoCopy(unittest.TestCase): diff --git a/tests/test_path_suffix.py b/tests/test_path_suffix.py index 7b8e40b1b..eddef2f06 100644 --- a/tests/test_path_suffix.py +++ b/tests/test_path_suffix.py @@ -2,17 +2,14 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import shutil -import sys import tempfile import unittest from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) - from common import resolve_local_file from generate_db import _path_suffixes diff --git a/tests/test_pin_build.py b/tests/test_pin_build.py index 3a15fa91e..77829ca51 100644 --- a/tests/test_pin_build.py +++ b/tests/test_pin_build.py @@ -8,18 +8,16 @@ file, and check_freshness reads it again where the platform now stands. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import check_freshness as cf -import check_freshness as cf # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] RECALBOX = "https://gitlab.com/recalbox/recalbox" diff --git a/tests/test_platform_inheritance.py b/tests/test_platform_inheritance.py index d4ba642f7..081c1fe63 100644 --- a/tests/test_platform_inheritance.py +++ b/tests/test_platform_inheritance.py @@ -8,20 +8,18 @@ scraper and install block. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import shutil -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common -import common # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class AChildLeavesItsParentAlone(unittest.TestCase): diff --git a/tests/test_platform_keys.py b/tests/test_platform_keys.py index 95be6420a..9e6498cf5 100644 --- a/tests/test_platform_keys.py +++ b/tests/test_platform_keys.py @@ -8,15 +8,13 @@ counted as declared: 76 Batocera entries added names such as boot0.rom. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) # Where the camelCase key is the upstream format itself: scrapers read it, # the Batocera exporter writes it back. diff --git a/tests/test_port.py b/tests/test_port.py index c137525f5..e35093b4b 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -8,7 +8,7 @@ route of the port, and the other launchers, are in test_handheld_launchers. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import importlib.util @@ -24,12 +24,11 @@ import unittest import zipfile from pathlib import Path +import build_port + REPO_ROOT = Path(__file__).resolve().parent.parent PORT = REPO_ROOT / "ports" / "RetroBIOS" SHARED = REPO_ROOT / "ports" / "shared" -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import build_port # noqa: E402 _spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py") install = importlib.util.module_from_spec(_spec) diff --git a/tests/test_profile_checks.py b/tests/test_profile_checks.py index a7de1e04a..c71f2cc5b 100644 --- a/tests/test_profile_checks.py +++ b/tests/test_profile_checks.py @@ -9,20 +9,18 @@ check left out lets through a file the emulator refuses. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from validation import _build_validation_index, check_file_validation -from validation import _build_validation_index, check_file_validation # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] def _profile(name: str) -> dict: diff --git a/tests/test_profile_names.py b/tests/test_profile_names.py index 0883422a1..42ce7cbfc 100644 --- a/tests/test_profile_names.py +++ b/tests/test_profile_names.py @@ -7,16 +7,14 @@ own name that way. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import load_emulator_profiles -from common import load_emulator_profiles # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent STEM_NAMED = { # Template and test cores, no emulator page. diff --git a/tests/test_profile_paths.py b/tests/test_profile_paths.py index fd19be8f4..9ee5c00b8 100644 --- a/tests/test_profile_paths.py +++ b/tests/test_profile_paths.py @@ -8,7 +8,7 @@ app's own code joins that folder to its data root. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import unittest from pathlib import Path diff --git a/tests/test_profile_repositories.py b/tests/test_profile_repositories.py index 76e63fe00..3b2c18fb9 100644 --- a/tests/test_profile_repositories.py +++ b/tests/test_profile_repositories.py @@ -11,19 +11,17 @@ and skips. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -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")) +import upstream +from profile_sync import declared_repositories -import upstream # noqa: E402 -from profile_sync import declared_repositories # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent CACHE = Path(upstream.CACHE_DIR) if not CACHE.is_absolute(): diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index cd2cde195..2a45ddb70 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse import contextlib @@ -18,8 +18,6 @@ from unittest import mock import yaml -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - import profile_sync from profile_sync import ( EntryReport, @@ -6255,7 +6253,6 @@ class TestBranchCheckIsWired(unittest.TestCase): def test_contributing_and_ci_use_the_flags(self): root = Path(__file__).resolve().parents[1] - sys.path.insert(0, str(root / "scripts")) import generate_readme text = generate_readme.generate_contributing() diff --git a/tests/test_prose_style.py b/tests/test_prose_style.py index 715580712..197498171 100644 --- a/tests/test_prose_style.py +++ b/tests/test_prose_style.py @@ -8,7 +8,7 @@ not write them. This module names every place one comes back. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import io import re @@ -456,9 +456,6 @@ class GeneratedSiteProse(unittest.TestCase): """The site pages carry strings no tracked file shows verbatim.""" def test_generated_pages(self): - import sys - - sys.path.insert(0, str(ROOT / "scripts")) from generate_site import LOCAL_NOTE_DIRS from tests import sitepages diff --git a/tests/test_proven_name.py b/tests/test_proven_name.py index 812b4bf8d..87a196662 100644 --- a/tests/test_proven_name.py +++ b/tests/test_proven_name.py @@ -10,23 +10,21 @@ devkit ROMs by the name step. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json import os import shutil -import sys import tempfile import unittest import zlib from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_db +from common import resolve_local_file -import generate_db # noqa: E402 -from common import resolve_local_file # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] DEVKIT = b"D" * 64 RETAIL = b"R" * 64 diff --git a/tests/test_provenance.py b/tests/test_provenance.py index 51b72b677..3322f9acd 100644 --- a/tests/test_provenance.py +++ b/tests/test_provenance.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import tempfile diff --git a/tests/test_pypi_package.py b/tests/test_pypi_package.py index 2785257c9..496519a65 100644 --- a/tests/test_pypi_package.py +++ b/tests/test_pypi_package.py @@ -9,7 +9,7 @@ tests read what it wrote and run it. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import configparser import email.parser @@ -23,10 +23,9 @@ import unittest import zipfile from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import build_pypi -import build_pypi # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent MODULE_FILES = {"retrobios/__init__.py", "retrobios/__main__.py", "retrobios/install.py"} diff --git a/tests/test_refresh_data_dirs.py b/tests/test_refresh_data_dirs.py index 701c30287..1ce25ef60 100644 --- a/tests/test_refresh_data_dirs.py +++ b/tests/test_refresh_data_dirs.py @@ -9,11 +9,10 @@ empty JSON document. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import io import json -import sys import tempfile import threading import unittest @@ -21,11 +20,10 @@ import zipfile from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import refresh_data_dirs as rdd +from generate_pack import _data_directory_members -import refresh_data_dirs as rdd # noqa: E402 -from generate_pack import _data_directory_members # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] def _zip_bytes(files: dict[str, bytes]) -> bytes: diff --git a/tests/test_refresh_failures.py b/tests/test_refresh_failures.py index 2d0dd6ffc..f91527f13 100644 --- a/tests/test_refresh_failures.py +++ b/tests/test_refresh_failures.py @@ -8,7 +8,7 @@ failed, the cache left at the old version. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import os @@ -21,10 +21,9 @@ import zipfile from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import check_buildbot_system -import check_buildbot_system # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class GitThatCannotAnswer(unittest.TestCase): diff --git a/tests/test_refresh_stale.py b/tests/test_refresh_stale.py index 032be84e9..d907dfcce 100644 --- a/tests/test_refresh_stale.py +++ b/tests/test_refresh_stale.py @@ -8,7 +8,7 @@ by the refresh of the original its export patches. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import subprocess import sys @@ -19,10 +19,9 @@ from unittest import mock import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import refresh_stale as rs -import refresh_stale as rs # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] REGISTRY = { "retrobat": {"scraper": "retrobat", "target_scraper": None}, diff --git a/tests/test_region.py b/tests/test_region.py index 280ed9675..bd584dc78 100644 --- a/tests/test_region.py +++ b/tests/test_region.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io @@ -11,8 +11,6 @@ import sys import unittest from pathlib import Path -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - import common import region from packextras import emulator_region_drops @@ -475,7 +473,6 @@ class TestFallbackGroups(unittest.TestCase): ) def test_the_readme_names_a_slot_as_a_reader_does(self): - sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) from packreadme import _group_label self.assertEqual(_group_label("PicoDrive:variant:megacd"), "megacd (PicoDrive)") @@ -697,7 +694,6 @@ class TestReportAndBuilderNarrowTogether(unittest.TestCase): return tmp, root, db, config def test_the_report_withdraws_what_the_builder_withdraws(self): - sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) import common import generate_pack as builder import verify as reporter @@ -741,7 +737,6 @@ class TestReportAndBuilderNarrowTogether(unittest.TestCase): """A missing platform file is grouped and withdrawn under --region, but a missing core file was never grouped and stayed "required missing" for a region the request excludes.""" - sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) import common import verify as reporter @@ -771,7 +766,6 @@ class TestReportAndBuilderNarrowTogether(unittest.TestCase): def test_the_report_names_the_fallback_groups(self): """The pack README lists the systems kept whole because nothing answers the request. verify said all OK and named none.""" - sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) import common import verify as reporter diff --git a/tests/test_region_agnostic_scan.py b/tests/test_region_agnostic_scan.py index f6a7eda39..b41b67173 100644 --- a/tests/test_region_agnostic_scan.py +++ b/tests/test_region_agnostic_scan.py @@ -9,15 +9,13 @@ ROCKNIX. Reads the repository: skips when the database is absent. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class ScanCopiesStay(unittest.TestCase): diff --git a/tests/test_region_check.py b/tests/test_region_check.py index 5fd073ada..deb73d3f4 100644 --- a/tests/test_region_check.py +++ b/tests/test_region_check.py @@ -3,16 +3,14 @@ records settle.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import region_check as rc -import region_check as rc # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent PROFILE = { "systems": ["sony-playstation"], diff --git a/tests/test_region_groups.py b/tests/test_region_groups.py index e17edc86f..ee8277737 100644 --- a/tests/test_region_groups.py +++ b/tests/test_region_groups.py @@ -7,16 +7,14 @@ Enterprise group drop the German Enterprise ROM under --region us. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from packextras import extra_region_groups, system_spellings -from packextras import extra_region_groups, system_spellings # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class TheGroupFollowsWhatTheProfileSays(unittest.TestCase): diff --git a/tests/test_region_held.py b/tests/test_region_held.py index 73a07a6e1..7243e523a 100644 --- a/tests/test_region_held.py +++ b/tests/test_region_held.py @@ -8,20 +8,18 @@ Japanese one, and the system shipped no BIOS at all. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os import shutil -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from packextras import _ships -from packextras import _ships # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class ARefusedDumpHoldsNothing(unittest.TestCase): diff --git a/tests/test_region_platform_index.py b/tests/test_region_platform_index.py index 63278078d..4a4e9455a 100644 --- a/tests/test_region_platform_index.py +++ b/tests/test_region_platform_index.py @@ -8,16 +8,14 @@ voided the [europe] tag Genesis Plus GX and PicoDrive give it, and from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import region as region_mod -import region as region_mod # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] PROFILES = { "gpgx": {"emulator": "GPGX", "type": "libretro", "systems": ["sega-mega-cd"], diff --git a/tests/test_region_required_only.py b/tests/test_region_required_only.py index 471d43d96..4a4a40937 100644 --- a/tests/test_region_required_only.py +++ b/tests/test_region_required_only.py @@ -8,16 +8,15 @@ the optional winner: the slot shipped empty. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast -import sys import unittest from pathlib import Path +from packextras import platform_region_groups + REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -from packextras import platform_region_groups # noqa: E402 class RequiredOnlyBeforeRegion(unittest.TestCase): diff --git a/tests/test_release_packs.py b/tests/test_release_packs.py index 16b4c5ef8..bbe275310 100644 --- a/tests/test_release_packs.py +++ b/tests/test_release_packs.py @@ -13,7 +13,7 @@ platform has a permanent page at get// instead. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io @@ -26,11 +26,10 @@ from unittest import mock import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import release_record -import common # noqa: E402 -import release_record # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PLATFORMS = str(REPO_ROOT / "platforms") TMP_ROOT = REPO_ROOT / "tmp" diff --git a/tests/test_report_excerpt.py b/tests/test_report_excerpt.py index c64db7399..199104b97 100644 --- a/tests/test_report_excerpt.py +++ b/tests/test_report_excerpt.py @@ -3,16 +3,11 @@ went stale with every file the collection gained.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest -from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import generate_report_excerpt # noqa: E402 +import generate_report_excerpt RUN = [ "RetroDECK: 9/10 OK, 1 untested [md5]", diff --git a/tests/test_required_only_archives.py b/tests/test_required_only_archives.py index 417d642db..24327e43d 100644 --- a/tests/test_required_only_archives.py +++ b/tests/test_required_only_archives.py @@ -6,7 +6,7 @@ its _Required pack held them anyway: the archive loop never read `required`. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import subprocess import sys diff --git a/tests/test_required_only_twins.py b/tests/test_required_only_twins.py index cb08788fd..8e4231fd8 100644 --- a/tests/test_required_only_twins.py +++ b/tests/test_required_only_twins.py @@ -11,10 +11,9 @@ the manifest without a trace. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import tempfile import unittest import zipfile @@ -22,12 +21,9 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 +import common +import generate_db +import generate_pack as builder class RequiredTwins(unittest.TestCase): diff --git a/tests/test_resolution_evidence.py b/tests/test_resolution_evidence.py index 2d2c2c4e1..7e91f161b 100644 --- a/tests/test_resolution_evidence.py +++ b/tests/test_resolution_evidence.py @@ -10,20 +10,18 @@ predicate is that check. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import tempfile import unittest import zipfile import zlib from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common -import common # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PAYLOAD = b"THE BYTES THE ENTRY MEANS" OTHER = b"A DIFFERENT FILE ANSWERING TO THE SAME NAME" diff --git a/tests/test_retired_files.py b/tests/test_retired_files.py index e37ed1f4e..98744ef11 100644 --- a/tests/test_retired_files.py +++ b/tests/test_retired_files.py @@ -8,18 +8,16 @@ contribution of a file the collection had held. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import retired_files -import retired_files # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] OLD = "bd" * 20 NEW = "d9" * 20 diff --git a/tests/test_retrodeck_scraper_errors.py b/tests/test_retrodeck_scraper_errors.py index 7d2f2b282..6239482e3 100644 --- a/tests/test_retrodeck_scraper_errors.py +++ b/tests/test_retrodeck_scraper_errors.py @@ -7,20 +7,15 @@ PS2 BIOS and the pcsx2 standalone core, exit code 0. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import io import json -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)) - -from scripts.scraper.retrodeck_scraper import Scraper # noqa: E402 +from scripts.scraper.retrodeck_scraper import Scraper TREE = {"tree": [{"path": "pcsx2", "type": "tree"}, {"path": "ppsspp", "type": "tree"}]} diff --git a/tests/test_romfolders_card.py b/tests/test_romfolders_card.py index 615cd941d..3fb4e7e0c 100644 --- a/tests/test_romfolders_card.py +++ b/tests/test_romfolders_card.py @@ -7,21 +7,17 @@ schema and their own declared sources. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import unittest from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) - -from romfolders import split_refs # noqa: E402 -from safeparse import yaml_load # noqa: E402 -from scraper.romfolders import SourceError, load_sources, scrape_setup # noqa: E402 -from scraper.romfolders.__main__ import dump_setup # noqa: E402 -from scraper.romfolders.card import ( # noqa: E402 +from romfolders import split_refs +from safeparse import yaml_load +from scraper.romfolders import SourceError, load_sources, scrape_setup +from scraper.romfolders.__main__ import dump_setup +from scraper.romfolders.card import ( libretro_core, parse_allium, parse_bizhawk, @@ -39,6 +35,8 @@ from scraper.romfolders.card import ( # noqa: E402 ref, ) +ROOT = Path(__file__).resolve().parent.parent + FIXTURES = json.loads( (ROOT / "tests" / "fixtures" / "romfolders_card" / "files.json").read_text(encoding="utf-8") ) diff --git a/tests/test_romfolders_es.py b/tests/test_romfolders_es.py index b2b3abb99..1ad70b6b2 100644 --- a/tests/test_romfolders_es.py +++ b/tests/test_romfolders_es.py @@ -9,15 +9,12 @@ naming a declared source, and a second dump giving the same bytes. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import unittest from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) - from romfolders import setup_paths, split_refs from scraper.romfolders import ( Fetcher, diff --git a/tests/test_romm_hash_rule.py b/tests/test_romm_hash_rule.py index 17ec065e8..891ba26ef 100644 --- a/tests/test_romm_hash_rule.py +++ b/tests/test_romm_hash_rule.py @@ -8,22 +8,20 @@ a wrong declared size passed here and failed there. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json -import sys import tempfile import unittest import zlib from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from nativemode import HASH_RULES, SIZE_AND_ANY_HASH +from validation import baseline_verdict, frontend_digest_matches +from verify import Status, verify_entry_md5 -from nativemode import HASH_RULES, SIZE_AND_ANY_HASH # noqa: E402 -from validation import baseline_verdict, frontend_digest_matches # noqa: E402 -from verify import Status, verify_entry_md5 # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] PAYLOAD = b"romm firmware" diff --git a/tests/test_romset_recipes.py b/tests/test_romset_recipes.py index c929185dd..33d54ed71 100644 --- a/tests/test_romset_recipes.py +++ b/tests/test_romset_recipes.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json @@ -13,12 +13,7 @@ import zipfile import zlib from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -TMP_ROOT = ROOT / "tmp" / "tests" -TMP_ROOT.mkdir(parents=True, exist_ok=True) -sys.path.insert(0, str(ROOT / "scripts")) - -from romset_recipes import ( # noqa: E402 +from romset_recipes import ( AtomPool, collect_recipes, identify_archive, @@ -29,7 +24,7 @@ from romset_recipes import ( # noqa: E402 reconstruct, write_reconstructions, ) -from scripts.scraper.romset_dat_importer import ( # noqa: E402 +from scripts.scraper.romset_dat_importer import ( catalog_targets, compact_entries, holds_target, @@ -38,8 +33,12 @@ from scripts.scraper.romset_dat_importer import ( # noqa: E402 merge_snapshot, recipe_entries, ) -from scripts.scraper.logiqx_parser import parse_logiqx # noqa: E402 -from torrentzip import build_torrentzip, is_torrentzip # noqa: E402 +from scripts.scraper.logiqx_parser import parse_logiqx +from torrentzip import build_torrentzip, is_torrentzip + +ROOT = Path(__file__).resolve().parent.parent +TMP_ROOT = ROOT / "tmp" / "tests" +TMP_ROOT.mkdir(parents=True, exist_ok=True) ROM_A = b"first rom payload" ROM_B = b"second rom payload" diff --git a/tests/test_save_root.py b/tests/test_save_root.py index 6647fee06..7219e3c36 100644 --- a/tests/test_save_root.py +++ b/tests/test_save_root.py @@ -11,7 +11,7 @@ directory the frontend's config names. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import functools import hashlib @@ -29,25 +29,24 @@ import zipfile from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import yaml -import yaml # noqa: E402 - -from packpaths import ( # noqa: E402 +from packpaths import ( EMULATOR_PACK_SAVE_FOLDER, SaveLayout, _resolve_destination, save_destination, save_layout, ) -from validation import ( # noqa: E402 +from validation import ( entry_root, outside_gap_scope, read_from_save_dir, read_from_system_dir, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + _spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py") install = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(install) @@ -796,10 +795,6 @@ class TheProfilesFollowTheContract(unittest.TestCase): class TheScrapersReadTheSystemLists(unittest.TestCase): """libretro_systems, read from each platform's own system list.""" - def setUp(self) -> None: - sys.path.insert(0, str(REPO_ROOT)) - self.addCleanup(sys.path.remove, str(REPO_ROOT)) - def test_batocera_and_knulli_es_systems_yml(self): from scripts.scraper.batocera_scraper import es_systems_libretro_systems diff --git a/tests/test_schema_semantic_gate.py b/tests/test_schema_semantic_gate.py index 41a04dd50..a8a8d8cbf 100644 --- a/tests/test_schema_semantic_gate.py +++ b/tests/test_schema_semantic_gate.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import io import json @@ -14,7 +14,6 @@ from pathlib import Path from unittest import mock REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) try: import validate_schemas diff --git a/tests/test_scraper_contract.py b/tests/test_scraper_contract.py index a5c6e38a3..a3cb5e91d 100644 --- a/tests/test_scraper_contract.py +++ b/tests/test_scraper_contract.py @@ -10,7 +10,7 @@ exercised is a promise to contributors backed by nothing. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import importlib import io @@ -23,11 +23,8 @@ 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 +from scraper import emudeck_scraper, libretro_scraper +from scraper.base_scraper import ( BaseScraper, BiosRequirement, ChangeSet, @@ -35,6 +32,8 @@ from scraper.base_scraper import ( # noqa: E402 github_headers, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + class _StubScraper(BaseScraper): """Minimal scraper: returns what it was handed, or raises.""" @@ -611,7 +610,6 @@ class EveryTargetCoreReachesAProfile(unittest.TestCase): import yaml - sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) import check_freshness from common import load_emulator_profiles diff --git a/tests/test_sega_filing.py b/tests/test_sega_filing.py index 939fe0d40..9c2c2524b 100644 --- a/tests/test_sega_filing.py +++ b/tests/test_sega_filing.py @@ -9,14 +9,12 @@ Reads the repository. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class SegaFilesStayUnderSega(unittest.TestCase): diff --git a/tests/test_shared_groups.py b/tests/test_shared_groups.py index f418b570b..ba90a91f0 100644 --- a/tests/test_shared_groups.py +++ b/tests/test_shared_groups.py @@ -9,17 +9,15 @@ it back as a required file of RetroArch, Lakka and RetroPie. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import load_emulator_profiles +from safeparse import yaml_load -from common import load_emulator_profiles # noqa: E402 -from safeparse import yaml_load # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class SharedGroupsFollowTheProfiles(unittest.TestCase): diff --git a/tests/test_shipped_content.py b/tests/test_shipped_content.py index 860edc874..e105d2ebf 100644 --- a/tests/test_shipped_content.py +++ b/tests/test_shipped_content.py @@ -15,23 +15,21 @@ path each entry comes from. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib import json import os import re -import sys import unittest import zipfile from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import common +from nativemode import reads_file_contents -import common # noqa: E402 -from nativemode import reads_file_contents # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent def _declared_digests(entry: dict) -> dict[str, set[str]]: diff --git a/tests/test_site_agents.py b/tests/test_site_agents.py index 1dc4fbe21..0ca83ac2b 100644 --- a/tests/test_site_agents.py +++ b/tests/test_site_agents.py @@ -5,17 +5,15 @@ the fewest files the games need, and every address they give must exist. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import siteagents -import siteagents # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent DIST = REPO_ROOT / "website" / "dist" TOOLS = REPO_ROOT / "website" / "src" / "scripts" / "agent-tools.ts" diff --git a/tests/test_site_arcade_boards.py b/tests/test_site_arcade_boards.py index 0f22664c4..01e0b6780 100644 --- a/tests/test_site_arcade_boards.py +++ b/tests/test_site_arcade_boards.py @@ -11,7 +11,7 @@ link or carry their reason below. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import tempfile @@ -19,15 +19,12 @@ import unittest import zipfile from pathlib import Path + +import siterender +from sitestarlight import toc_slug + REPO_ROOT = Path(__file__).resolve().parents[1] -import sys # noqa: E402 - -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import siterender # noqa: E402 -from sitestarlight import toc_slug # noqa: E402 - # The boards the audit found with no section (N1, T-F3), by an id each. NAMED_BOARDS = { "sega-naomi": "Sega NAOMI", diff --git a/tests/test_site_availability.py b/tests/test_site_availability.py index 46efd86b6..f61ba4d6c 100644 --- a/tests/test_site_availability.py +++ b/tests/test_site_availability.py @@ -8,19 +8,17 @@ held across the site while the gaps page listed them as known absences. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -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 common import load_database +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 +REPO_ROOT = Path(__file__).resolve().parent.parent SHA1 = "a" * 40 DB = { diff --git a/tests/test_site_bootstrap.py b/tests/test_site_bootstrap.py index 18f6b8d4e..0f7e920d2 100644 --- a/tests/test_site_bootstrap.py +++ b/tests/test_site_bootstrap.py @@ -9,26 +9,23 @@ that long, so each copy reads install.py from the commit it was built from. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json import os import re import subprocess -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT)) -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import install +import sitebootstrap +from siteguides import INSTALL_BASE, INSTALL_PS1, INSTALL_SH, install_command -import install # noqa: E402 -import sitebootstrap # noqa: E402 -from siteguides import INSTALL_BASE, INSTALL_PS1, INSTALL_SH, install_command # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] WEBSITE = REPO_ROOT / "website" DOCS = WEBSITE / "src" / "content" / "docs" diff --git a/tests/test_site_built_gate.py b/tests/test_site_built_gate.py index 31b8d6d16..8b0ad37ba 100644 --- a/tests/test_site_built_gate.py +++ b/tests/test_site_built_gate.py @@ -15,11 +15,10 @@ Skips when the site is not built. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re -import sys import unittest from html import unescape from pathlib import Path @@ -27,7 +26,6 @@ from pathlib import Path import yaml REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) DIST = REPO_ROOT / "website" / "dist" DOCS = REPO_ROOT / "website" / "src" / "content" / "docs" diff --git a/tests/test_site_components.py b/tests/test_site_components.py index c03c20eba..ecbc7ea63 100644 --- a/tests/test_site_components.py +++ b/tests/test_site_components.py @@ -18,7 +18,7 @@ node and skip without it. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re @@ -32,10 +32,9 @@ import zlib import html import sys -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import list_release_pack_platforms -from common import list_release_pack_platforms # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] REPO_ROOT = Path(__file__).resolve().parents[1] diff --git a/tests/test_site_console_folders.py b/tests/test_site_console_folders.py index 8a207d6e7..766b3bdf0 100644 --- a/tests/test_site_console_folders.py +++ b/tests/test_site_console_folders.py @@ -12,7 +12,7 @@ three samples committed under "FBAlpha 2012" and four release assets under from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re diff --git a/tests/test_site_content_data.py b/tests/test_site_content_data.py index 0f0b684e2..35c637069 100644 --- a/tests/test_site_content_data.py +++ b/tests/test_site_content_data.py @@ -8,24 +8,22 @@ needs no Python change, and a mistake stops the build with its name. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import re import shutil -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site +import siteguides +from siteguides import GUIDES, GuideError, load_guides -import generate_site # noqa: E402 -import siteguides # noqa: E402 -from siteguides import GUIDES, GuideError, load_guides # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent GUIDES_FILE = REPO_ROOT / "platforms" / "_guides.yml" WIKI = REPO_ROOT / "wiki" diff --git a/tests/test_site_copy.py b/tests/test_site_copy.py index dfd08dac5..fdf9b4739 100644 --- a/tests/test_site_copy.py +++ b/tests/test_site_copy.py @@ -12,7 +12,7 @@ print the measures of every page held here. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re import statistics @@ -21,9 +21,7 @@ import unittest from dataclasses import dataclass, field from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT)) -from tests import sitepages # noqa: E402 +from tests import sitepages DOCS = sitepages.CONTENT diff --git a/tests/test_site_cores.py b/tests/test_site_cores.py index d6891bcfe..f22a75477 100644 --- a/tests/test_site_cores.py +++ b/tests/test_site_cores.py @@ -7,24 +7,22 @@ where its pack is built from 321. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import generate_site # noqa: E402 -from common import ( # noqa: E402 +import generate_site +from common import ( list_registered_platforms, load_emulator_profiles, load_platform_config, resolve_platform_cores, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + class SiteCoreCounts(unittest.TestCase): def test_each_platform_count_is_the_resolved_set(self): diff --git a/tests/test_site_css.py b/tests/test_site_css.py index e9dde975b..66ffaf87d 100644 --- a/tests/test_site_css.py +++ b/tests/test_site_css.py @@ -25,7 +25,7 @@ crumb separator free to end a line alone. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re import unittest diff --git a/tests/test_site_demo.py b/tests/test_site_demo.py index 2184dc3dc..fd0f21467 100644 --- a/tests/test_site_demo.py +++ b/tests/test_site_demo.py @@ -11,21 +11,19 @@ terminal recording under the others. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re import struct -import sys import unittest from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import generate_readme +import make_demo +import sitestarlight -import generate_readme # noqa: E402 -import make_demo # noqa: E402 -import sitestarlight # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent DEMO = ROOT / "docs_assets" / "demo" COMPONENT = ROOT / "website" / "src" / "components" / "InstallDemo.astro" diff --git a/tests/test_site_density_cards.py b/tests/test_site_density_cards.py index cf8ebfea6..54910aaab 100644 --- a/tests/test_site_density_cards.py +++ b/tests/test_site_density_cards.py @@ -10,20 +10,18 @@ sits in closed folds, every fact still on the page. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import types import unittest from html.parser import HTMLParser from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site as gs +import sitemarkup as markup -import generate_site as gs # noqa: E402 -import sitemarkup as markup # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] DIST = REPO_ROOT / "website" / "dist" SITE_TS = REPO_ROOT / "website" / "src" / "scripts" / "site.ts" diff --git a/tests/test_site_emulator_page.py b/tests/test_site_emulator_page.py index f7e49ea5e..f80d9d577 100644 --- a/tests/test_site_emulator_page.py +++ b/tests/test_site_emulator_page.py @@ -5,16 +5,14 @@ No network and no database: pages are rendered from small profiles. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site as gs -import generate_site as gs # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] EMPTY_DB = {"files": {}, "indexes": {"by_name": {}}} diff --git a/tests/test_site_emulators.py b/tests/test_site_emulators.py index daa07519e..ff5713eab 100644 --- a/tests/test_site_emulators.py +++ b/tests/test_site_emulators.py @@ -27,10 +27,9 @@ Linux, Windows and Android commands, for MAME4droid an Android-only app. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path import yaml @@ -38,12 +37,11 @@ import tempfile import importlib.util import json -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site as gs +import siterender +import validate_site -import generate_site as gs # noqa: E402 -import siterender # noqa: E402 -import validate_site # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] EMPTY_DB = {"files": {}, "indexes": {"by_name": {}}} diff --git a/tests/test_site_entry.py b/tests/test_site_entry.py index e4ecde35a..8d64da2c4 100644 --- a/tests/test_site_entry.py +++ b/tests/test_site_entry.py @@ -32,28 +32,25 @@ Linux handheld rows sent the reader to a menu. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re -import sys import unittest from datetime import datetime, timezone from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -sys.path.insert(0, str(REPO_ROOT)) +import generate_readme +import generate_site +import release_record +import siteguides +import sitemarkup +from common import load_platform_config, load_platform_registry +from tests import sitepages -import generate_readme # noqa: E402 -import generate_site # noqa: E402 -import release_record # noqa: E402 -import siteguides # noqa: E402 -import sitemarkup # noqa: E402 -from common import load_platform_config, load_platform_registry # noqa: E402 -from tests import sitepages # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] REGISTRY = load_platform_registry(str(REPO_ROOT / "platforms")) diff --git a/tests/test_site_entry_tables.py b/tests/test_site_entry_tables.py index 807aefd03..73b7d1bbb 100644 --- a/tests/test_site_entry_tables.py +++ b/tests/test_site_entry_tables.py @@ -10,22 +10,20 @@ every name and hash back. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from html.parser import HTMLParser from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site as gs +import siteentries +import validate_site -import generate_site as gs # noqa: E402 -import siteentries # noqa: E402 -import validate_site # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] EMPTY_DB = {"files": {}, "indexes": {"by_name": {}}} DIST = REPO_ROOT / "website" / "dist" diff --git a/tests/test_site_exports.py b/tests/test_site_exports.py index 45ee451e7..352bf7000 100644 --- a/tests/test_site_exports.py +++ b/tests/test_site_exports.py @@ -2,13 +2,12 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json import os import sqlite3 -import sys import tempfile import unittest from unittest import mock @@ -16,10 +15,7 @@ from pathlib import Path import yaml -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) - -from generate_site import ( # noqa: E402 +from generate_site import ( _admonition_body, _browser_title, _forge_sources, @@ -28,6 +24,8 @@ from generate_site import ( # noqa: E402 generate_data_exports, ) +ROOT = Path(__file__).resolve().parent.parent + class SiteReferenceContracts(unittest.TestCase): def setUp(self) -> None: diff --git a/tests/test_site_freshness.py b/tests/test_site_freshness.py index e76cb8e61..8a617b426 100644 --- a/tests/test_site_freshness.py +++ b/tests/test_site_freshness.py @@ -6,20 +6,18 @@ the pages whose words changed for IndexNow.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import tempfile import unittest from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import indexnow +import siteagents +import site_markdown -import indexnow # noqa: E402 -import siteagents # noqa: E402 -import site_markdown # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent STAMP = {"commit": "0123456789abcdef0123456789abcdef01234567", "date": "2026-11-09T08:00:00+01:00"} # The two parts a built Starlight page gives the copy: its title and its content. diff --git a/tests/test_site_funnel.py b/tests/test_site_funnel.py index 3ebef94c9..4002fb458 100644 --- a/tests/test_site_funnel.py +++ b/tests/test_site_funnel.py @@ -7,22 +7,20 @@ reader two levels deeper without saying so. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import re -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site +from tests import sitepages +from common import list_registered_platforms, load_platform_config, load_platform_registry +from siteguides import DEVICE_GROUPS, GROUP_ANCHORS, GUIDES -import generate_site # noqa: E402 -from tests import sitepages # noqa: E402 -from common import list_registered_platforms, load_platform_config, load_platform_registry # noqa: E402 -from siteguides import DEVICE_GROUPS, GROUP_ANCHORS, GUIDES # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent DOCS = sitepages.CONTENT ORDER = list(generate_site.LEVELS) diff --git a/tests/test_site_handheld.py b/tests/test_site_handheld.py index bf06f3bfa..970f8c6fb 100644 --- a/tests/test_site_handheld.py +++ b/tests/test_site_handheld.py @@ -9,24 +9,22 @@ starts it. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib import re import shutil -import sys import tempfile import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import build_port +import common +import sitehandheld -import build_port # noqa: E402 -import common # noqa: E402 -import sitehandheld # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] PLATFORMS = str(REPO_ROOT / "platforms") diff --git a/tests/test_site_images.py b/tests/test_site_images.py index a0f54a8c9..bb137f000 100644 --- a/tests/test_site_images.py +++ b/tests/test_site_images.py @@ -8,20 +8,18 @@ CDN. These tests hold the replacements in place. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re -import sys import tempfile import unittest import xml.etree.ElementTree as ET from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import sitediagrams -import sitediagrams # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent SVG = "{http://www.w3.org/2000/svg}" diff --git a/tests/test_site_inputs.py b/tests/test_site_inputs.py index d262070bc..36a8a3a59 100644 --- a/tests/test_site_inputs.py +++ b/tests/test_site_inputs.py @@ -9,23 +9,21 @@ directory, so a get/ page said "No ZIP" for a setup the API marked as released. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import json import os import shutil -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site +import sitediagrams +import siteinputs -import generate_site # noqa: E402 -import sitediagrams # noqa: E402 -import siteinputs # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] SHA1 = "0123456789ab" + "c" * 28 diff --git a/tests/test_site_insights.py b/tests/test_site_insights.py index 66285710b..3aebf8fae 100644 --- a/tests/test_site_insights.py +++ b/tests/test_site_insights.py @@ -1,14 +1,10 @@ """The readings of scripts/site_insights.py, on synthetic figures.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import datetime as dt -import sys import unittest -from pathlib import Path - -sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) import site_insights as si diff --git a/tests/test_site_integration.py b/tests/test_site_integration.py index d49486354..86ffefe94 100644 --- a/tests/test_site_integration.py +++ b/tests/test_site_integration.py @@ -9,12 +9,11 @@ Node's compile cache into /tmp. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import glob import json import re -import sys import tempfile import unittest from pathlib import Path @@ -22,13 +21,12 @@ from unittest import mock import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import check_freshness +import generate_site as gs +import sitediagrams +import siterender -import check_freshness # noqa: E402 -import generate_site as gs # noqa: E402 -import sitediagrams # noqa: E402 -import siterender # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] DIST = REPO_ROOT / "website" / "dist" diff --git a/tests/test_site_nav.py b/tests/test_site_nav.py index 1b0c829ed..63c10aae8 100644 --- a/tests/test_site_nav.py +++ b/tests/test_site_nav.py @@ -21,12 +21,11 @@ are built, the pages and the site. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re import struct -import sys import tempfile import unittest from html.parser import HTMLParser @@ -34,17 +33,18 @@ from pathlib import Path import ast from html import unescape -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import generate_site # noqa: E402 -import sitestarlight # noqa: E402 -from common import ( # noqa: E402 +import generate_site +import sitestarlight +from common import ( list_registered_platforms, load_platform_config, load_platform_registry, ) +from siteguides import DEVICE_GROUPS + +REPO_ROOT = Path(__file__).resolve().parents[1] + DIST = REPO_ROOT / "website" / "dist" ROUTE = REPO_ROOT / "website" / "src" / "routeData.ts" TAB_ROOTS = {"/retrobios/", "/retrobios/platforms/", "/retrobios/explore/", @@ -72,8 +72,6 @@ def _targets(value: object) -> set[str]: def _present(nav: list) -> set[str]: return {t for t in _targets(nav) if not t.startswith("http")} -from siteguides import DEVICE_GROUPS # noqa: E402 - def _index_anchors(markdown: str) -> set[str]: """The heading ids a generated page carries once written.""" diff --git a/tests/test_site_page_text.py b/tests/test_site_page_text.py index e7f0d3bb9..b430050ed 100644 --- a/tests/test_site_page_text.py +++ b/tests/test_site_page_text.py @@ -12,24 +12,22 @@ styles, and hold the page to one reading of each thing it says. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re import shutil import subprocess -import sys import unittest from html.parser import HTMLParser from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import sitediagrams +import siteentries +import sitesteps +from siteguides import TERMINALS -import sitediagrams # noqa: E402 -import siteentries # noqa: E402 -import sitesteps # noqa: E402 -from siteguides import TERMINALS # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent WEBSITE = ROOT / "website" DOCS = WEBSITE / "src" / "content" / "docs" diff --git a/tests/test_site_picker.py b/tests/test_site_picker.py index 1f733d118..6667665d7 100644 --- a/tests/test_site_picker.py +++ b/tests/test_site_picker.py @@ -9,19 +9,17 @@ list the page shows is not what the command it prints installs. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import importlib.util import json import random import re -import sys import tempfile import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) _spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py") install = importlib.util.module_from_spec(_spec) diff --git a/tests/test_site_platform_density.py b/tests/test_site_platform_density.py index 100ff4c34..5f6090566 100644 --- a/tests/test_site_platform_density.py +++ b/tests/test_site_platform_density.py @@ -10,19 +10,17 @@ role of each reference named by one word that a legend defines once. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import html import re -import sys import unittest from html.parser import HTMLParser from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site -import generate_site # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] _SKIPPED = frozenset({"script", "style", "template"}) _VOID = frozenset({"area", "base", "br", "col", "embed", "hr", "img", "input", diff --git a/tests/test_site_platform_hashes.py b/tests/test_site_platform_hashes.py index bee30587a..21d5b7950 100644 --- a/tests/test_site_platform_hashes.py +++ b/tests/test_site_platform_hashes.py @@ -8,18 +8,13 @@ checking a dump against the page was told the wrong hash. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from unittest import mock -from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import siterender # noqa: E402 -from generate_site import _render_platform_systems # noqa: E402 +import siterender +from generate_site import _render_platform_systems A, B, C = "a" * 32, "b" * 32, "c" * 32 diff --git a/tests/test_site_privacy.py b/tests/test_site_privacy.py index d23b8c31c..9315572fb 100644 --- a/tests/test_site_privacy.py +++ b/tests/test_site_privacy.py @@ -6,7 +6,7 @@ page looking different. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re import unittest diff --git a/tests/test_site_pronouns.py b/tests/test_site_pronouns.py index 1914d30f8..4eb75e1aa 100644 --- a/tests/test_site_pronouns.py +++ b/tests/test_site_pronouns.py @@ -9,7 +9,7 @@ are not prose. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import html import re @@ -189,7 +189,6 @@ class SitePronouns(unittest.TestCase): def test_release_notes(self): """The release page is public text too. Rendered from the committed record, and once more with a pack in parts, its own paragraph.""" - sys.path.insert(0, str(ROOT / "scripts")) import release_notes import release_record diff --git a/tests/test_site_reference.py b/tests/test_site_reference.py index 41dc63616..9250cb1c1 100644 --- a/tests/test_site_reference.py +++ b/tests/test_site_reference.py @@ -31,7 +31,7 @@ it has not been generated. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import csv import io @@ -51,25 +51,24 @@ import zipfile import runpy import urllib.error -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import generate_site # noqa: E402 -import sitewanted # noqa: E402 -import siterender # noqa: E402 -from common import ( # noqa: E402 +import generate_site +import sitewanted +import siterender +from common import ( list_registered_platforms, load_emulator_profiles, load_platform_config, list_release_pack_platforms, ) -from exporter.baseline import HASH_FIELDS, _hash_values # noqa: E402 -from exporter.candidates import EntryCategories # noqa: E402 -from sitesources import launcher_ref_markdown, list_source # noqa: E402 -import check_platform_folder # noqa: E402 -import sitesources # noqa: E402 -import release_record # noqa: E402 -import upstream # noqa: E402 +from exporter.baseline import HASH_FIELDS, _hash_values +from exporter.candidates import EntryCategories +from sitesources import launcher_ref_markdown, list_source +import check_platform_folder +import sitesources +import release_record +import upstream + +REPO_ROOT = Path(__file__).resolve().parents[1] PLATFORMS = str(REPO_ROOT / "platforms") @@ -522,7 +521,9 @@ class AFolderCheckAgreesWithTheVerifier(unittest.TestCase): (root / "plain.bin").write_bytes(b"plain") (root / "wrong.bin").write_bytes(b"not it") (root / "nohash.bin").write_bytes(b"x") - md5 = lambda data: hashlib.md5(data).hexdigest() # noqa: E731 + def md5(data: bytes) -> str: + return hashlib.md5(data).hexdigest() + contract = {"verification_mode": "md5", "systems": {"s": {"files": [ {"name": "bbcb.zip", "destination": "bbcb.zip", "md5": md5(member), "zipped_file": "basic1.rom"}, diff --git a/tests/test_site_render.py b/tests/test_site_render.py index df77d0b02..c16a5c0f7 100644 --- a/tests/test_site_render.py +++ b/tests/test_site_render.py @@ -2,9 +2,8 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import unittest from pathlib import Path @@ -12,10 +11,9 @@ from unittest import mock import yaml -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import siterender -import siterender # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class IconsComeFromTheLocalCopies(unittest.TestCase): diff --git a/tests/test_site_search.py b/tests/test_site_search.py index bf82b050f..7662fbe19 100644 --- a/tests/test_site_search.py +++ b/tests/test_site_search.py @@ -19,11 +19,10 @@ built, the site. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import re -import sys import tempfile import unittest from pathlib import Path @@ -31,15 +30,14 @@ import yaml import json from html.parser import HTMLParser -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site as gs +import sitestarlight +import validate_site +import generate_site +from common import list_registered_platforms, load_emulator_profiles +from tests.test_site_nav import ANCHORS, _nav, _present -import generate_site as gs # noqa: E402 -import sitestarlight # noqa: E402 -import validate_site # noqa: E402 -import generate_site # noqa: E402 -from common import list_registered_platforms, load_emulator_profiles # noqa: E402 -from tests.test_site_nav import ANCHORS, _nav, _present # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] TOOLS = REPO_ROOT / "website" / "tools" diff --git a/tests/test_site_steps.py b/tests/test_site_steps.py index 0e5f6715b..9f15996d6 100644 --- a/tests/test_site_steps.py +++ b/tests/test_site_steps.py @@ -9,20 +9,18 @@ and the words never disagree. And it draws in the theme's colours. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest import xml.etree.ElementTree as ET from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import sitediagrams +import sitesteps +from siteguides import TERMINALS -import sitediagrams # noqa: E402 -import sitesteps # noqa: E402 -from siteguides import TERMINALS # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent SVG = "{http://www.w3.org/2000/svg}" DIST = ROOT / "website" / "dist" diff --git a/tests/test_site_system_links.py b/tests/test_site_system_links.py index c9b132c01..4e2c195c7 100644 --- a/tests/test_site_system_links.py +++ b/tests/test_site_system_links.py @@ -11,17 +11,15 @@ Reads the repository: skips when the database is absent. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site as gs -import generate_site as gs # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class LinksFollowContent(unittest.TestCase): diff --git a/tests/test_site_system_names.py b/tests/test_site_system_names.py index 170c12f9d..823767a0f 100644 --- a/tests/test_site_system_names.py +++ b/tests/test_site_system_names.py @@ -10,23 +10,21 @@ console folders, so the ids to name are the platforms' and the profiles'. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import siterender # noqa: E402 -from common import ( # noqa: E402 +import siterender +from common import ( list_registered_platforms, load_emulator_profiles, load_platform_config, ) -from generate_site import _group_by_manufacturer # noqa: E402 +from generate_site import _group_by_manufacturer + +REPO_ROOT = Path(__file__).resolve().parents[1] def _profile_system_ids(profiles: dict[str, dict]) -> set[str]: diff --git a/tests/test_site_system_sections.py b/tests/test_site_system_sections.py index df5a09e6c..90c9879b0 100644 --- a/tests/test_site_system_sections.py +++ b/tests/test_site_system_sections.py @@ -14,19 +14,17 @@ Reads the repository: skips when the database is absent. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import os -import sys import unittest from collections.abc import Iterable from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import siterender -import siterender # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] # Ids whose files the collection holds and that lead to no section. UNLINKED: dict[str, str] = { diff --git a/tests/test_site_systems.py b/tests/test_site_systems.py index 26e20f2c5..415d34c45 100644 --- a/tests/test_site_systems.py +++ b/tests/test_site_systems.py @@ -30,10 +30,9 @@ three times before the first file. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import types import unittest from pathlib import Path @@ -41,14 +40,13 @@ from unittest import mock import zipfile import json -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site as gs +import siterender +from cross_reference import FileConsumers +import make_og_cards +from sitestarlight import toc_slug -import generate_site as gs # noqa: E402 -import siterender # noqa: E402 -from cross_reference import FileConsumers # noqa: E402 -import make_og_cards # noqa: E402 -from sitestarlight import toc_slug # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] DIST = REPO_ROOT / "website" / "dist" diff --git a/tests/test_site_validation.py b/tests/test_site_validation.py index 92e3f70bd..0589e1dfc 100644 --- a/tests/test_site_validation.py +++ b/tests/test_site_validation.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re @@ -11,12 +11,11 @@ import tempfile import unittest from pathlib import Path +from validate_site import validate_site + ROOT = Path(__file__).resolve().parent.parent TMP_ROOT = ROOT / "tmp" / "tests" TMP_ROOT.mkdir(parents=True, exist_ok=True) -sys.path.insert(0, str(ROOT / "scripts")) - -from validate_site import validate_site # noqa: E402 def _page(title: str, description: str, body: str = "") -> str: diff --git a/tests/test_site_wanted.py b/tests/test_site_wanted.py index 824d4a960..ba575c7d9 100644 --- a/tests/test_site_wanted.py +++ b/tests/test_site_wanted.py @@ -11,29 +11,27 @@ would have its upload flagged by the same project. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import json import os import shutil import subprocess -import sys import tempfile import unittest import re import zlib from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_site +import sitewanted +import validate_pr +import yaml +from common import load_database +from tests.test_site_pronouns import pronouns -import generate_site # noqa: E402 -import sitewanted # noqa: E402 -import validate_pr # noqa: E402 -import yaml # noqa: E402 -from common import load_database # noqa: E402 -from tests.test_site_pronouns import pronouns # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent WEBSITE = REPO_ROOT / "website" WANTED_TS = WEBSITE / "src" / "scripts" / "wanted.ts" diff --git a/tests/test_site_weight.py b/tests/test_site_weight.py index 810998a69..027a6a5af 100644 --- a/tests/test_site_weight.py +++ b/tests/test_site_weight.py @@ -9,20 +9,15 @@ is looked up by content, an emulator card's anchor sits on its row. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest -from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import generate_site # noqa: E402 -import sitestarlight # noqa: E402 -import siterender # noqa: E402 -import sitemarkup as markup # noqa: E402 -from cross_reference import FileConsumers # noqa: E402 +import generate_site +import sitestarlight +import siterender +import sitemarkup as markup +from cross_reference import FileConsumers def _file(name: str, index: int, console: str, maker: str = "Maker") -> dict: diff --git a/tests/test_site_wiki.py b/tests/test_site_wiki.py index f1106bbc1..96424b72d 100644 --- a/tests/test_site_wiki.py +++ b/tests/test_site_wiki.py @@ -31,26 +31,23 @@ setup guides or the generator that writes the page a link opens. """ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import fnmatch import json import re -import sys import unittest from pathlib import Path import yaml import importlib.util -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) -sys.path.insert(0, str(REPO_ROOT)) +import sitediagrams +from siteguides import INSTALL_SH +from tests import sitepages +import build_port +from check_release import SUMS, Asset, compare_release -import sitediagrams # noqa: E402 -from siteguides import INSTALL_SH # noqa: E402 -from tests import sitepages # noqa: E402 -import build_port # noqa: E402 -from check_release import SUMS, Asset, compare_release # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] WIKI = REPO_ROOT / "wiki" diff --git a/tests/test_site_write.py b/tests/test_site_write.py index fc8cc2e5e..95107969a 100644 --- a/tests/test_site_write.py +++ b/tests/test_site_write.py @@ -11,17 +11,13 @@ delete on the critical path and is why these tests exist. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import sitewrite # noqa: E402 +import sitewrite BODY = "# Title\n\nSome prose.\n\n*Generated on 2026-01-01T00:00:00Z*\n" FRONT = ( diff --git a/tests/test_slot.py b/tests/test_slot.py index 65819a4ae..904a15308 100644 --- a/tests/test_slot.py +++ b/tests/test_slot.py @@ -2,14 +2,11 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import unittest -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - import slot diff --git a/tests/test_slots.py b/tests/test_slots.py index 45f5ea70b..686726316 100644 --- a/tests/test_slots.py +++ b/tests/test_slots.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import re @@ -12,8 +12,6 @@ import tempfile import unittest from pathlib import Path -sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) - import slots from slots import Claim, Conflict, arbitrate, format_decision diff --git a/tests/test_slots_shipped_file.py b/tests/test_slots_shipped_file.py index 2b6dc03d3..06ffc3751 100644 --- a/tests/test_slots_shipped_file.py +++ b/tests/test_slots_shipped_file.py @@ -11,20 +11,18 @@ Reads the repository: skips when the database or the files are absent. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import copy import hashlib import os -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import load_database, load_platform_config +import slots -from common import load_database, load_platform_config # noqa: E402 -import slots # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] MAME_ADAM = "bios/Arcade/MAME/adam_fdc.zip" MSX_DISK = "bios/Microsoft/MSX/DISK.ROM" diff --git a/tests/test_source_ref_targets.py b/tests/test_source_ref_targets.py index 5bf8eeee3..c16edb9e5 100644 --- a/tests/test_source_ref_targets.py +++ b/tests/test_source_ref_targets.py @@ -12,20 +12,18 @@ mirror pages its tree, and read as one page it could not confirm a path. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import sitesources +import upstream +from common import load_emulator_profiles +from sourceref import ref_role, source_ref_values, split_source_ref -import sitesources # noqa: E402 -import upstream # noqa: E402 -from common import load_emulator_profiles # noqa: E402 -from sourceref import ref_role, source_ref_values, split_source_ref # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] PROFILES = ("trident", "future-pinball-fploader", "pce-emu", "uqm", "nesoid", "ryujinx", "stonesoup") diff --git a/tests/test_split_extras.py b/tests/test_split_extras.py index 08690f001..fbbf5f840 100644 --- a/tests/test_split_extras.py +++ b/tests/test_split_extras.py @@ -7,10 +7,9 @@ and in no part (4507 of RetroArch's 5430). from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import tempfile import unittest import zipfile @@ -18,11 +17,10 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import build_zip_contents_index, compute_hashes, load_emulator_profiles +from generate_pack import PackRecord, generate_pack, generate_split_packs -from common import build_zip_contents_index, compute_hashes, load_emulator_profiles # noqa: E402 -from generate_pack import PackRecord, generate_pack, generate_split_packs # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class SplitPartsCoverTheExtras(unittest.TestCase): diff --git a/tests/test_split_names.py b/tests/test_split_names.py index 98751f575..7550a7156 100644 --- a/tests/test_split_names.py +++ b/tests/test_split_names.py @@ -10,22 +10,18 @@ SHA256SUMS.txt. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import common # noqa: E402 -from common import build_zip_contents_index, compute_hashes # noqa: E402 -from generate_pack import generate_split_packs # noqa: E402 +import common +from common import build_zip_contents_index, compute_hashes +from generate_pack import generate_split_packs class SplitPartNames(unittest.TestCase): diff --git a/tests/test_split_pack.py b/tests/test_split_pack.py index 6d2d0a144..24df4a7c4 100644 --- a/tests/test_split_pack.py +++ b/tests/test_split_pack.py @@ -14,7 +14,7 @@ parts extracted into one folder are the pack. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io @@ -27,12 +27,11 @@ import unittest import zipfile from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_pack as builder +from artifacts import artifact_lock +import split_pack -import generate_pack as builder # noqa: E402 -from artifacts import artifact_lock # noqa: E402 -import split_pack # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent LIMIT = 4096 diff --git a/tests/test_standalone_links.py b/tests/test_standalone_links.py index d16c62489..db0f10a41 100644 --- a/tests/test_standalone_links.py +++ b/tests/test_standalone_links.py @@ -12,17 +12,13 @@ naomi.zip took the place of MAME's. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import textwrap import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import ( # noqa: E402 +from common import ( entry_launch_systems, load_emulator_profiles, load_platform_config, @@ -32,7 +28,7 @@ from common import ( # noqa: E402 standalone_set, system_file_index, ) -from launchers import ( # noqa: E402 +from launchers import ( SEARCHED_FILES, bound_path, handed_directories, @@ -40,6 +36,8 @@ from launchers import ( # noqa: E402 standalone_bindings, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + def link(emulator: str, search_dir: str, passes_to: str, **fields: object) -> dict: return { diff --git a/tests/test_standalone_mode.py b/tests/test_standalone_mode.py index 82d5d22b5..db8afc062 100644 --- a/tests/test_standalone_mode.py +++ b/tests/test_standalone_mode.py @@ -10,19 +10,17 @@ standalone_cores dropped them from its pack. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests 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 -from cross_reference import cross_reference # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent DUAL_PROFILE = { "emulator": "Dual", diff --git a/tests/test_standalone_probe.py b/tests/test_standalone_probe.py index c9eda2181..48d7cdcc5 100644 --- a/tests/test_standalone_probe.py +++ b/tests/test_standalone_probe.py @@ -3,19 +3,17 @@ framebuffer reader, the settings it writes and the oracle it judges with.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import struct -import sys import tempfile import unittest from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import core_probe as cp +import standalone_probe as sp -import core_probe as cp # noqa: E402 -import standalone_probe as sp # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent def xwd(width: int, height: int, pixels: bytes, ncolors: int = 0, pad: int = 0) -> bytes: diff --git a/tests/test_system_ids.py b/tests/test_system_ids.py index 48736036f..add96cec6 100644 --- a/tests/test_system_ids.py +++ b/tests/test_system_ids.py @@ -9,17 +9,15 @@ channelf.zip and SNES DSP sets to colecovision/. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import SYSTEM_ALIASES, _norm_system_id, load_emulator_profiles +from packextras import _names_content, _slug_for -from common import SYSTEM_ALIASES, _norm_system_id, load_emulator_profiles # noqa: E402 -from packextras import _names_content, _slug_for # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class ProfilesSpellEachMachineOnce(unittest.TestCase): diff --git a/tests/test_system_pack_extras.py b/tests/test_system_pack_extras.py index c9cc3b5d0..698423f51 100644 --- a/tests/test_system_pack_extras.py +++ b/tests/test_system_pack_extras.py @@ -7,16 +7,14 @@ names, while the split packs, built per system, carried them. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from generate_pack import _extras_for_systems -from generate_pack import _extras_for_systems # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class SystemExtras(unittest.TestCase): diff --git a/tests/test_system_pack_parity.py b/tests/test_system_pack_parity.py index 7bdad8fb4..7a669d51b 100644 --- a/tests/test_system_pack_parity.py +++ b/tests/test_system_pack_parity.py @@ -10,7 +10,7 @@ or trees and credited a profile's file at a path holding another profile's. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re diff --git a/tests/test_system_selection.py b/tests/test_system_selection.py index 4ffff0d77..ce0a7bc59 100644 --- a/tests/test_system_selection.py +++ b/tests/test_system_selection.py @@ -10,7 +10,7 @@ libretro pack. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import re @@ -20,12 +20,11 @@ import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_pack as builder +from tests.scratchtree import scratch_checkout, snapshot -import common # noqa: E402 -import generate_pack as builder # noqa: E402 -from tests.scratchtree import scratch_checkout, snapshot # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class SpellingsAgree(unittest.TestCase): diff --git a/tests/test_target_names.py b/tests/test_target_names.py index 2b9a2408a..714650cf7 100644 --- a/tests/test_target_names.py +++ b/tests/test_target_names.py @@ -7,7 +7,7 @@ and `--verify-packs --target nx` looked for a pack nobody had built. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import subprocess import sys @@ -15,10 +15,9 @@ import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import canonical_target_name -from common import canonical_target_name # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class EveryBuildbotCoreIsNamed(unittest.TestCase): diff --git a/tests/test_target_scrapers.py b/tests/test_target_scrapers.py index 9b74162f4..275d16e75 100644 --- a/tests/test_target_scrapers.py +++ b/tests/test_target_scrapers.py @@ -8,26 +8,24 @@ packs built for it shrank without an error. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import os -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)) - -from scripts.scraper.targets import ( # noqa: E402 +from scripts.scraper.targets import ( batocera_targets_scraper, emudeck_targets_scraper, retroarch_targets_scraper, retropie_targets_scraper, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + def _refuse(*_args, **_kwargs): raise urllib.error.HTTPError("https://api.github.com/x", 403, "rate limited", {}, None) diff --git a/tests/test_target_systems.py b/tests/test_target_systems.py index ecb7adc6c..105688938 100644 --- a/tests/test_target_systems.py +++ b/tests/test_target_systems.py @@ -9,16 +9,11 @@ builder still shipped its ROMs as ep128emu extras. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest -from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import filter_systems_by_target # noqa: E402 +from common import filter_systems_by_target PROFILES = { "ep128emu_core": { diff --git a/tests/test_target_verify.py b/tests/test_target_verify.py index 6ca012fcf..5897a91de 100644 --- a/tests/test_target_verify.py +++ b/tests/test_target_verify.py @@ -10,7 +10,7 @@ out of a targeted --all run, and the check refuses it as the build does. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import sys @@ -20,11 +20,10 @@ import tempfile import unittest 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 +REPO_ROOT = Path(__file__).resolve().parent.parent class CheckReadsTheTargetLikeTheBuild(unittest.TestCase): diff --git a/tests/test_tool_messages.py b/tests/test_tool_messages.py index c3f3f8f14..c2e5d8eff 100644 --- a/tests/test_tool_messages.py +++ b/tests/test_tool_messages.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io @@ -15,14 +15,13 @@ import unittest from pathlib import Path from unittest import mock -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import diff_truth +import pipeline +import truth +import verify -import common # noqa: E402 -import diff_truth # noqa: E402 -import pipeline # noqa: E402 -import truth # noqa: E402 -import verify # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class ABuildbotNameSelectsItsProfile(unittest.TestCase): diff --git a/tests/test_torrentzip.py b/tests/test_torrentzip.py index 6ae98e73d..88dc41b57 100644 --- a/tests/test_torrentzip.py +++ b/tests/test_torrentzip.py @@ -1,7 +1,7 @@ """Tests for the TorrentZip builder against real MAME romsets.""" from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os @@ -10,16 +10,15 @@ import tempfile import unittest import zipfile -REPO_ROOT = os.path.join(os.path.dirname(__file__), "..") -sys.path.insert(0, os.path.join(REPO_ROOT, "scripts")) - -from torrentzip import ( # noqa: E402 +from torrentzip import ( build_torrentzip, identify_romset, is_torrentzip, rebuild_torrentzip, ) +REPO_ROOT = os.path.join(os.path.dirname(__file__), "..") + class TorrentZipTest(unittest.TestCase): """The format is deterministic: same members always give the same bytes.""" diff --git a/tests/test_truth_data_dir_readers.py b/tests/test_truth_data_dir_readers.py index 26818c367..89f0dbbc1 100644 --- a/tests/test_truth_data_dir_readers.py +++ b/tests/test_truth_data_dir_readers.py @@ -9,21 +9,18 @@ revision, and hash_conflict did not see LRPS2's value. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) -sys.path.insert(0, str(REPO_ROOT / "scripts" / "exporter")) +from exporter.baseline import checked_hashes +from truth import generate_platform_truth -from exporter.baseline import checked_hashes # noqa: E402 -from truth import generate_platform_truth # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent GAME_INDEX = "pcsx2/resources/GameIndex.yaml" DECLARED = b"the revision armsx2 declares" diff --git a/tests/test_truth_diff.py b/tests/test_truth_diff.py index dcce0f7b3..7ff5008c8 100644 --- a/tests/test_truth_diff.py +++ b/tests/test_truth_diff.py @@ -9,20 +9,16 @@ discrepancy that does not exist. Content decides, as everywhere else here. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import pathlib import subprocess import sys import tempfile import unittest -from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from exporter.baseline import pair_entries # noqa: E402 -from truth import ( # noqa: E402 +from exporter.baseline import pair_entries +from truth import ( _diff_system, _merge_file_into_system, generate_platform_truth, diff --git a/tests/test_truth_layout.py b/tests/test_truth_layout.py index 31f076c8e..abce37dfb 100644 --- a/tests/test_truth_layout.py +++ b/tests/test_truth_layout.py @@ -8,7 +8,7 @@ out on RetroBat, EmuDeck and RetroDECK. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import os @@ -18,10 +18,9 @@ import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from truth import generate_platform_truth -from truth import generate_platform_truth # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] def _names(truth: dict) -> set[str]: diff --git a/tests/test_twin_declaration_status.py b/tests/test_twin_declaration_status.py index 1cbb92c67..6f0c2c8d2 100644 --- a/tests/test_twin_declaration_status.py +++ b/tests/test_twin_declaration_status.py @@ -9,26 +9,24 @@ refusal read first left "excluded" behind the file the second one ships. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import hashlib import io import os -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_db +import generate_pack as builder +from verify import Status, verify_platform -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -from verify import Status, verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PAYLOAD = b"a console firmware" SHA1 = hashlib.sha1(PAYLOAD).hexdigest() diff --git a/tests/test_twin_declarations.py b/tests/test_twin_declarations.py index 9ab464d93..ca1892bb0 100644 --- a/tests/test_twin_declarations.py +++ b/tests/test_twin_declarations.py @@ -9,21 +9,17 @@ frontend hashes bios/disk.rom for xroar and finds the PC-88 ROM. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -import common # noqa: E402 -import generate_db # noqa: E402 -from verify import verify_platform # noqa: E402 +import common +import generate_db +from verify import verify_platform class TwinDeclarations(unittest.TestCase): diff --git a/tests/test_undeclared_dedup.py b/tests/test_undeclared_dedup.py index 9fc2c12bf..98238585a 100644 --- a/tests/test_undeclared_dedup.py +++ b/tests/test_undeclared_dedup.py @@ -9,14 +9,9 @@ dropped from the pack. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest -from pathlib import Path - -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class StandaloneFallsBackOnPath(unittest.TestCase): diff --git a/tests/test_unplaced_extras.py b/tests/test_unplaced_extras.py index cea234522..7ec9848c2 100644 --- a/tests/test_unplaced_extras.py +++ b/tests/test_unplaced_extras.py @@ -8,25 +8,23 @@ listed them neither in files nor in omitted_files. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_db +import generate_pack as builder +from packextras import platform_region_groups +from verify import verify_platform -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -from packextras import platform_region_groups # noqa: E402 -from verify import verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PROFILE = """\ emulator: Dosbox diff --git a/tests/test_upstream.py b/tests/test_upstream.py index ae7e444f1..4868870d1 100644 --- a/tests/test_upstream.py +++ b/tests/test_upstream.py @@ -2,12 +2,11 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import http.client import os -import sys import tempfile import socket import unittest @@ -16,8 +15,6 @@ import urllib.error import urllib.request from pathlib import Path -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "scripts")) - import upstream from upstream import make_repo, parse_repo, raw_url diff --git a/tests/test_upstream_index.py b/tests/test_upstream_index.py index a765dea57..2cd623fe5 100644 --- a/tests/test_upstream_index.py +++ b/tests/test_upstream_index.py @@ -8,22 +8,20 @@ and a RetroArch target pack lost LRPS2's files. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from common import ( # noqa: E402 +from common import ( preferred_profile, resolve_platform_cores, upstream_profile_index, ) +REPO_ROOT = Path(__file__).resolve().parents[1] + PROFILES = { "lrps2": {"type": "libretro", "cores": ["lrps2", "pcsx2"]}, "pcsx2": {"type": "standalone", "cores": ["pcsx2"]}, diff --git a/tests/test_validate_pr.py b/tests/test_validate_pr.py index a4f2f5592..30c2fd39f 100644 --- a/tests/test_validate_pr.py +++ b/tests/test_validate_pr.py @@ -8,7 +8,7 @@ it is an untrusted-input boundary with nothing behind it. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import os import sys @@ -16,10 +16,9 @@ import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import validate_pr -import validate_pr # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent EMPTY_HASHES: dict = {"sha1": set(), "md5": set(), "names": set()} diff --git a/tests/test_validate_pr_flow.py b/tests/test_validate_pr_flow.py index fb1d8e3b9..803a53326 100644 --- a/tests/test_validate_pr_flow.py +++ b/tests/test_validate_pr_flow.py @@ -7,7 +7,7 @@ cannot hold has to be an action the contributor can take. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import os @@ -20,10 +20,9 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import validate_pr -import validate_pr # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent WORKFLOW = REPO_ROOT / ".github" / "workflows" / "validate.yml" SAME_REPO = "github.event.pull_request.head.repo.full_name == github.repository" diff --git a/tests/test_validate_pr_hashes.py b/tests/test_validate_pr_hashes.py index 110613039..c0f11c3a7 100644 --- a/tests/test_validate_pr_hashes.py +++ b/tests/test_validate_pr_hashes.py @@ -8,16 +8,14 @@ were lost the same way. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests -import sys import unittest from pathlib import Path import yaml REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class EveryAcceptedRevisionIsKnown(unittest.TestCase): diff --git a/tests/test_validated_choice.py b/tests/test_validated_choice.py index 26bda65e5..3dc48ade9 100644 --- a/tests/test_validated_choice.py +++ b/tests/test_validated_choice.py @@ -8,24 +8,22 @@ across 14 destinations on six platforms. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import hashlib -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) - -from validation import ( # noqa: E402 +from validation import ( _build_validation_index, destination_owners, validated_choice, ) +REPO_ROOT = Path(__file__).resolve().parent.parent + class ValidatedChoice(unittest.TestCase): def test_a_rejected_file_gives_way_to_an_accepted_variant(self): diff --git a/tests/test_validation_scope.py b/tests/test_validation_scope.py index 31a313db6..d74d8b8bc 100644 --- a/tests/test_validation_scope.py +++ b/tests/test_validation_scope.py @@ -8,7 +8,7 @@ test fails if either hands the index the whole profile set again. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re import unittest @@ -57,10 +57,8 @@ class ContentFoundLabelsTakeTheirRegionSlot(unittest.TestCase): def test_an_alternative_dump_passes_under_the_label(self): import hashlib - import sys import tempfile - sys.path.insert(0, str(REPO_ROOT / "scripts")) from validation import _build_validation_index, check_file_validation with tempfile.TemporaryDirectory() as tmp: @@ -94,12 +92,10 @@ class GearcolecoWarnsOnAnUnknownRevision(unittest.TestCase): 928-935 at be1a3716): another OS-7 revision of 8 KiB runs.""" def test_another_revision_passes(self): - import sys import tempfile import yaml - sys.path.insert(0, str(REPO_ROOT / "scripts")) from validation import _build_validation_index, check_file_validation profile = yaml.safe_load( diff --git a/tests/test_variant_choice.py b/tests/test_variant_choice.py index 48a187652..f171e75b1 100644 --- a/tests/test_variant_choice.py +++ b/tests/test_variant_choice.py @@ -9,7 +9,7 @@ never swapped in. Both sides now read find_validated_variant. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os @@ -20,10 +20,9 @@ import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from validation import find_validated_variant -from validation import find_validated_variant # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parents[1] class FindValidatedVariant(unittest.TestCase): diff --git a/tests/test_variant_identity.py b/tests/test_variant_identity.py index 1af95d7a1..ca8e7e595 100644 --- a/tests/test_variant_identity.py +++ b/tests/test_variant_identity.py @@ -9,7 +9,7 @@ database. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import re diff --git a/tests/test_verify_all_dir.py b/tests/test_verify_all_dir.py index 815816cd7..001d5a0d7 100644 --- a/tests/test_verify_all_dir.py +++ b/tests/test_verify_all_dir.py @@ -7,7 +7,7 @@ the run, and one registered only in the copy was never checked. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import json import subprocess diff --git a/tests/test_verify_data_dir_notice.py b/tests/test_verify_data_dir_notice.py index 9d2b2d08d..fa73b0559 100644 --- a/tests/test_verify_data_dir_notice.py +++ b/tests/test_verify_data_dir_notice.py @@ -9,21 +9,19 @@ verify --emulator already named its uncached trees. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import io import os -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import generate_db +from verify import print_platform_result, verify_platform -import generate_db # noqa: E402 -from verify import print_platform_result, verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class UncachedDataDirectoryNotice(unittest.TestCase): diff --git a/tests/test_verify_emulator_evidence.py b/tests/test_verify_emulator_evidence.py index 85a35c219..9ffd4b990 100644 --- a/tests/test_verify_emulator_evidence.py +++ b/tests/test_verify_emulator_evidence.py @@ -14,19 +14,17 @@ the other by flagging the divergence. This report agreed with neither. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest from pathlib import Path -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import verify -import verify # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent def _db(path: Path, name: str) -> dict: diff --git a/tests/test_verify_listing.py b/tests/test_verify_listing.py index 19f42d1bc..8522fa708 100644 --- a/tests/test_verify_listing.py +++ b/tests/test_verify_listing.py @@ -2,7 +2,7 @@ from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import subprocess import sys @@ -57,7 +57,6 @@ class VerifyRefusesWhatAModeDoesNotRead(unittest.TestCase): self.assertIn(flag, result.stderr) def test_emulator_mode_reads_the_given_platforms_dir(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify seen: list[str] = [] @@ -90,7 +89,6 @@ class VerifyAppliesWhatItAccepts(unittest.TestCase): class EmulatorPackReadsThePlatformsDir(unittest.TestCase): def test_the_registry_comes_from_the_given_dir(self): - sys.path.insert(0, str(REPO_ROOT / "scripts")) import generate_pack seen: list[str] = [] @@ -119,7 +117,6 @@ class CoreArchivesAreCounted(unittest.TestCase): import contextlib import io - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify result = {"undeclared_files": [ @@ -138,7 +135,6 @@ class ExistenceReportsWhatThePackReports(unittest.TestCase): """30 RetroArch entries printed DISCREPANCY in the pack, nothing in verify.""" import tempfile - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: @@ -154,7 +150,6 @@ class ExistenceReportsWhatThePackReports(unittest.TestCase): def test_the_file_found_is_named(self): """RetroArch, Lakka and RetroPie pages showed no "Served by" line: existence mode returned no path, where the hash modes return one.""" - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify found = verify.verify_entry_existence({"name": "a.bin"}, "bios/X/Y/a.bin") @@ -198,7 +193,6 @@ class EveryGapCountedIsNamed(unittest.TestCase): import contextlib import io - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify result = {"undeclared_files": [ @@ -225,7 +219,6 @@ class BundledGameDataIsNotMissing(unittest.TestCase): import contextlib import io - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify result = {"undeclared_files": [ @@ -251,7 +244,6 @@ class TheBundledLineSaysWhatItLeavesOut(unittest.TestCase): import contextlib import io - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify result = {"undeclared_files": [ @@ -287,7 +279,6 @@ class TheCheckLineSaysWhatItIs(unittest.TestCase): import contextlib import io - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify entry = {"name": "FBASIC30.ROM", "emulator": "XM7", "checks": ["size"]} @@ -309,7 +300,6 @@ class CoreCopiesWithoutAGapEntryAreCounted(unittest.TestCase): import contextlib import io - sys.path.insert(0, str(REPO_ROOT / "scripts")) import verify for packed, expected in (({"bios": 6, "game_data": 0}, "Core files: 6 in pack"), diff --git a/tests/test_verify_pack_choice.py b/tests/test_verify_pack_choice.py index 96c6e2d22..b87bee433 100644 --- a/tests/test_verify_pack_choice.py +++ b/tests/test_verify_pack_choice.py @@ -8,19 +8,17 @@ regional one. A pack built with --source truth answered SKIP and exit 0. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import argparse import json import os -import sys import tempfile import unittest from pathlib import Path from unittest import mock REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) def _ok_result() -> tuple: diff --git a/tests/test_verify_release_asset.py b/tests/test_verify_release_asset.py index d4cc4ac16..10d06d733 100644 --- a/tests/test_verify_release_asset.py +++ b/tests/test_verify_release_asset.py @@ -11,11 +11,10 @@ counts the file missing as before. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib import os -import sys import tempfile import unittest import zipfile @@ -24,14 +23,13 @@ from unittest import mock import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +import common +import generate_db +import generate_pack as builder +import packresolve +from verify import Status, verify_emulator, verify_platform -import common # noqa: E402 -import generate_db # noqa: E402 -import generate_pack as builder # noqa: E402 -import packresolve # noqa: E402 -from verify import Status, verify_emulator, verify_platform # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent PAYLOAD = b"a firmware image the repository does not commit" SHA1 = hashlib.sha1(PAYLOAD).hexdigest() diff --git a/tests/test_version_basis.py b/tests/test_version_basis.py index 00ff87a6f..44f8cca33 100644 --- a/tests/test_version_basis.py +++ b/tests/test_version_basis.py @@ -8,7 +8,7 @@ to a basis, and hold a pin advance to reading the version again. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import contextlib import copy @@ -23,14 +23,13 @@ from unittest import mock import yaml -ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(ROOT / "scripts")) +import profile_sync +import upstream +import version_basis +from common import load_emulator_profiles +from profile_sync import ProfileReport, bump_commit -import profile_sync # noqa: E402 -import upstream # noqa: E402 -import version_basis # noqa: E402 -from common import load_emulator_profiles # noqa: E402 -from profile_sync import ProfileReport, bump_commit # noqa: E402 +ROOT = Path(__file__).resolve().parent.parent FIXTURE = ROOT / "tests" / "fixtures" / "version_basis.json" diff --git a/tests/test_which_pack.py b/tests/test_which_pack.py index ed83509df..668386bbe 100644 --- a/tests/test_which_pack.py +++ b/tests/test_which_pack.py @@ -6,15 +6,10 @@ published and carries 3916 files the RetroArch one does not. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import re -import sys import unittest -from pathlib import Path - -REPO_ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(REPO_ROOT / "scripts")) class WhichPackRows(unittest.TestCase): diff --git a/tests/test_workflow_paths.py b/tests/test_workflow_paths.py index b3b9daeda..a3a18ffb3 100644 --- a/tests/test_workflow_paths.py +++ b/tests/test_workflow_paths.py @@ -7,12 +7,11 @@ until some unrelated file moved. from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import ast import fnmatch import re -import sys import unittest from pathlib import Path @@ -276,7 +275,6 @@ class DocumentedSteps(unittest.TestCase): def test_the_release_page_names_every_installed_package(self): """The page listed pyyaml and mkdocs and left out jsonschema: a maintainer following it could not run the contract check.""" - sys.path.insert(0, str(SCRIPTS)) from check_freshness import parse_pip_pins workflow = (REPO_ROOT / ".github/workflows/deploy-site.yml").read_text(encoding="utf-8") diff --git a/tests/test_zipped_member.py b/tests/test_zipped_member.py index 9f7c144e8..5028dd3f3 100644 --- a/tests/test_zipped_member.py +++ b/tests/test_zipped_member.py @@ -6,10 +6,9 @@ level1.rom went out as OK where verify said "not found inside ZIP". from __future__ import annotations -import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache +import tests import hashlib -import sys import tempfile import unittest import zipfile @@ -17,11 +16,10 @@ from pathlib import Path import yaml -REPO_ROOT = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(REPO_ROOT / "scripts")) +from common import build_zip_contents_index +from generate_pack import generate_pack -from common import build_zip_contents_index # noqa: E402 -from generate_pack import generate_pack # noqa: E402 +REPO_ROOT = Path(__file__).resolve().parent.parent class ZippedMemberIsChecked(unittest.TestCase):