diff --git a/tests/__init__.py b/tests/__init__.py index eb38760b6..011708b83 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -13,8 +13,10 @@ temporary directory instead of naming the missing parent. from __future__ import annotations import os +import shutil import sys import tempfile +import unittest from pathlib import Path os.environ.setdefault("RETROBIOS_OFFLINE", "1") @@ -53,3 +55,11 @@ os.environ["GIT_CEILING_DIRECTORIES"] = str(_SCRATCH) # The installer's cache (the games index, what reading a card found) is the # suite's own: a run never reads nor fills the one of the person running it. os.environ.setdefault("RETROBIOS_CACHE", str(_SCRATCH / "cache")) + + +def scratch_dir(test: unittest.TestCase) -> Path: + """A fresh directory under this module's scratch folder, removed after + the test.""" + path = Path(tempfile.mkdtemp()) + test.addCleanup(shutil.rmtree, path, True) + return path diff --git a/tests/scratchtree.py b/tests/scratchtree.py index 93ec3fdae..d3854893e 100644 --- a/tests/scratchtree.py +++ b/tests/scratchtree.py @@ -31,7 +31,7 @@ LINKED = ("bios", "data") @cache def scratch_checkout() -> Path: """The copy, built once per test process and removed at its exit.""" - root = Path(tempfile.mkdtemp(prefix="checkout-", dir=REPO_ROOT / "tmp" / "tests")) + root = Path(tempfile.mkdtemp(prefix="checkout-")) # A detached worktree with nothing checked out: the scripts that read # HEAD (the site's bootstrap pin) find this commit. subprocess.run( diff --git a/tests/test_adler32_resolution.py b/tests/test_adler32_resolution.py index 1d1968d3d..2207bfbaf 100644 --- a/tests/test_adler32_resolution.py +++ b/tests/test_adler32_resolution.py @@ -27,7 +27,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class TheAcceptedChecksumWins(unittest.TestCase): def setUp(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) self.old = root / "bios/Sys/GC/dsp_rom.bin" self.good = root / "bios/.variants/dsp_rom.bin.good" @@ -73,7 +73,7 @@ class TheTwoRomsFormAPairTheCodeTakes(unittest.TestCase): plus official coef, which its known_roms table refuses.""" def setUp(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) held = { ("dsp_rom.bin", root / "bios/Sys/GC/dsp_rom.bin"): b"\x01\x02" * 8, diff --git a/tests/test_agnostic_substitute.py b/tests/test_agnostic_substitute.py index 318ae6de2..fd6b84054 100644 --- a/tests/test_agnostic_substitute.py +++ b/tests/test_agnostic_substitute.py @@ -22,7 +22,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class AgnosticSubstitute(unittest.TestCase): def test_only_the_platform_cores_answer(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: held = Path(tmp) / "ps2" / "scph39001.bin" held.parent.mkdir() held.write_bytes(b"x" * 16) diff --git a/tests/test_arcade_parents.py b/tests/test_arcade_parents.py index 144128b14..457798210 100644 --- a/tests/test_arcade_parents.py +++ b/tests/test_arcade_parents.py @@ -15,8 +15,6 @@ from scripts.scraper import arcade_parent_importer as api from scripts.scraper import listxml 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" @@ -114,7 +112,7 @@ class OfflineImport(unittest.TestCase): """import_profile reads the cache only, and two runs write the same bytes.""" def setUp(self) -> None: - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.cache = Path(self.temp.name) dat = self.cache / "repo" / "libretro" / "mame2010-libretro" / COMMIT / "metadata" dat.mkdir(parents=True) @@ -256,7 +254,7 @@ class DriverSource(unittest.TestCase): the DATs those repositories carry contradict it.""" def setUp(self) -> None: - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.cache = Path(self.temp.name) slug = "libretro/mame2003-libretro" tarball = self.cache / "src" / slug / f"{COMMIT}.tar.gz" @@ -417,7 +415,7 @@ class CommittedIndex(unittest.TestCase): import validate_schemas self.assertEqual(validate_schemas._arcade_pin_errors(), []) - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) (root / "games" / "arcade").mkdir(parents=True) (root / "emulators").mkdir() diff --git a/tests/test_archive_build.py b/tests/test_archive_build.py index b5f789a96..b5cd519a5 100644 --- a/tests/test_archive_build.py +++ b/tests/test_archive_build.py @@ -24,8 +24,6 @@ from romrecipes import ledger from core.torrentzip import build_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" * 50 ROM_B = b"second rom payload" * 40 @@ -112,7 +110,7 @@ class Fixture(unittest.TestCase): """A small collection: a loose ROM, a TorrentZip set, a plain ZIP.""" def setUp(self): - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.root = Path(self.temp.name) bios = self.root / "bios" bios.mkdir() diff --git a/tests/test_archive_choice.py b/tests/test_archive_choice.py index ecb11ce15..fd25b31f3 100644 --- a/tests/test_archive_choice.py +++ b/tests/test_archive_choice.py @@ -187,7 +187,7 @@ class TheArchiveHoldingTheCoreMembers(unittest.TestCase): start a Neo Geo CD game.""" def setUp(self): - directory = tempfile.mkdtemp(dir=REPO_ROOT / "tmp") + directory = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, directory, True) root = Path(directory) self.roms = {"neocd.bin": b"bios" * 8, "000-lo.lo": b"zoom" * 8} @@ -358,7 +358,7 @@ class AnArchiveHashedByItsMembers(unittest.TestCase): archive's name: Recalbox cannot open it and reports the BIOS red.""" def setUp(self): - directory = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + directory = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, directory, True) rom = b"bios" * 8 raw = directory / "bios/neocd.bin" @@ -408,7 +408,7 @@ class AnArchiveRankedByWhatItHolds(unittest.TestCase): unrelated duplicate was deleted and the index order flipped.""" def setUp(self): - directory = tempfile.mkdtemp(dir=REPO_ROOT / "tmp") + directory = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, directory, True) self.root = Path(directory) self.roms = {f"epr-213{n}.ic27": bytes([n]) * 16 for n in (29, 30, 31, 32)} @@ -529,8 +529,7 @@ class ALooseEntryNamingItsArchive(unittest.TestCase): from packs.emulatorcheck import verify_emulator emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) @@ -579,8 +578,7 @@ class AnotherEmulatorsOwnSet(unittest.TestCase): copy.""" def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) diff --git a/tests/test_artifact_lock.py b/tests/test_artifact_lock.py index b93eab002..3adb3273a 100644 --- a/tests/test_artifact_lock.py +++ b/tests/test_artifact_lock.py @@ -8,6 +8,7 @@ ZIPs, which surfaces as BadZipFile far from its cause. from __future__ import annotations import tests +from tests import scratch_dir import os import subprocess @@ -31,22 +32,9 @@ from unittest import mock REPO_ROOT = Path(__file__).resolve().parent.parent -def _tempdir(test: unittest.TestCase) -> str: - """A scratch directory under the repository's tmp/, removed after the test. - - The system temp directory is a RAM disk here, and directories left by - every run piled up on it. - """ - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - path = tempfile.mkdtemp(dir=str(scratch)) - test.addCleanup(shutil.rmtree, path, True) - return path - - class ArtifactLockTest(unittest.TestCase): def setUp(self): - self.dir = _tempdir(self) + self.dir = str(scratch_dir(self)) def test_writer_excludes_writer(self): with artifact_lock(self.dir), self.assertRaises(ArtifactLockBusy), artifact_lock(self.dir): @@ -96,7 +84,7 @@ class ArtifactLockTest(unittest.TestCase): pass def test_separate_directories_do_not_contend(self): - other = _tempdir(self) + other = str(scratch_dir(self)) with artifact_lock(self.dir), artifact_lock(other): pass @@ -110,7 +98,7 @@ class PackLockCliTest(unittest.TestCase): """generate_pack and pipeline must refuse a directory held elsewhere.""" def setUp(self): - self.dir = _tempdir(self) + self.dir = str(scratch_dir(self)) def _run(self, argv: list[str]) -> subprocess.CompletedProcess: # In a copy: a pipeline that missed the lock regenerated @@ -235,7 +223,7 @@ class PipelineHoldsItsFixedOutputs(unittest.TestCase): install/, README.md and docs/: only the output directory was locked.""" def test_a_second_pipeline_is_refused_whatever_its_output_dir(self): - scratch = _tempdir(self) + scratch = str(scratch_dir(self)) checkout = scratch_checkout() with hold_repository_outputs(str(checkout)): proc = subprocess.run( @@ -260,7 +248,7 @@ class TheSuiteTakesTheRepositoryHoldInItsScratch(unittest.TestCase): a generator writing database.json, failed on the busy lock.""" def test_the_hold_is_taken_where_the_variable_says(self): - scratch = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + scratch = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, scratch, True) moved = scratch / "repository-lock" with mock.patch.dict(os.environ, {artifacts.REPOSITORY_LOCK_ENV: str(moved)}), \ @@ -273,7 +261,7 @@ class TheSuiteTakesTheRepositoryHoldInItsScratch(unittest.TestCase): pass def test_another_directory_keeps_its_own_lock(self): - out = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + out = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, out, True) with mock.patch.dict(os.environ, {artifacts.REPOSITORY_LOCK_ENV: str(out / "x")}), \ artifacts.artifact_lock(str(out)): @@ -324,14 +312,14 @@ class StandaloneWritersHonourTheRepositoryHold(unittest.TestCase): def test_a_step_the_pipeline_spawns_passes(self): """A pipeline holds the root and its --output-dir, and its steps write both: the environment names the two, os.pathsep apart.""" - self.scratch = _tempdir(self) + self.scratch = str(scratch_dir(self)) with hold_repository_outputs(str(REPO_ROOT)), publish_hold(str(REPO_ROOT)), \ hold_artifact_lock(self.scratch): proc = self._child(str(REPO_ROOT / "install" / "games"), dict(os.environ)) self.assertEqual(proc.returncode, 0, proc.stderr) def test_a_scratch_output_takes_nothing(self): - self.scratch = _tempdir(self) + self.scratch = str(scratch_dir(self)) env = {k: v for k, v in os.environ.items() if k != "RETROBIOS_HELD_ARTIFACT_DIR"} with hold_repository_outputs(str(REPO_ROOT)): proc = self._child(os.path.join(self.scratch, "database.json"), env) @@ -344,7 +332,7 @@ class HeldLockTest(unittest.TestCase): check reported every platform SKIP and passed.""" def setUp(self): - self.dir = _tempdir(self) + self.dir = str(scratch_dir(self)) def _child_locks(self, env: dict) -> subprocess.CompletedProcess: code = ( @@ -396,7 +384,7 @@ class SiteGenerationHoldsDocs(unittest.TestCase): the same tree. That run then died on os.replace or lost pages.""" def test_a_second_run_is_refused_before_it_writes(self): - docs = _tempdir(self) + docs = str(scratch_dir(self)) marker = Path(docs) / "platforms" / ".retroarch.md.k2j3.tmp" marker.parent.mkdir() marker.write_text("scratch of another run") diff --git a/tests/test_atomic_artifacts.py b/tests/test_atomic_artifacts.py index 2f0eb0b75..b43258067 100644 --- a/tests/test_atomic_artifacts.py +++ b/tests/test_atomic_artifacts.py @@ -148,7 +148,7 @@ class TheNativeIndexKeepsEveryPlatform(unittest.TestCase): from exporter.originals import SOURCES_INDEX, fetch - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) index = root / SOURCES_INDEX @@ -338,7 +338,7 @@ class ATerminatedBuildLeavesNoScratch(unittest.TestCase): if not hasattr(signal, "SIGTERM") or os.name != "posix": self.skipTest("POSIX signals") - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: pack = Path(tmp) / "Demo_BIOS_Pack.zip" child = subprocess.Popen( [sys.executable, "-c", self.CHILD, str(pack)], cwd=REPO_ROOT, diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 9d1d0c9a5..3ce3b2704 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -40,8 +40,6 @@ from scripts.packs.targets import generate_target_manifests 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) class ReadmeRegressions(unittest.TestCase): @@ -233,7 +231,7 @@ class AModuleRunAloneHasItsScratchDirectory(unittest.TestCase): fresh clone raised FileNotFoundError. The test package creates it.""" def test_importing_the_package_creates_tmp(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: clone = Path(directory) (clone / "tests").mkdir() (clone / "tests" / "__init__.py").write_bytes( @@ -628,7 +626,7 @@ class APackIsSwappedInWhole(unittest.TestCase): import tempfile (ROOT / "tmp").mkdir(exist_ok=True) - directory = Path(tempfile.mkdtemp(dir=ROOT / "tmp")) + directory = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, directory, True) return directory @@ -835,7 +833,7 @@ class ADamagedArchiveIsNotPacked(unittest.TestCase): from packs.archive import DamagedArchiveError, add_zip_to_pack - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: source = Path(directory) / "set.zip" with zipfile.ZipFile(source, "w", zipfile.ZIP_STORED) as zf: zf.writestr("rom.bin", b"A" * 64) @@ -861,7 +859,7 @@ class APackedArchiveKeepsItsBytes(unittest.TestCase): from packs.archive import add_zip_to_pack - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: source = Path(directory) / "set.zip" with zipfile.ZipFile(source, "w", zipfile.ZIP_DEFLATED) as zf: zf.writestr(zipfile.ZipInfo("rom.bin", (1999, 1, 2, 3, 4, 5)), b"rom" * 40) @@ -949,7 +947,7 @@ class AutoFetchReadsListsAndPlacesWithoutClobbering(unittest.TestCase): def test_the_review_folder_is_used_and_nothing_is_overwritten(self): from scripts.acquire import fetch as acquire_fetch - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: bios = Path(directory) for folder in ("Nintendo/SNES", "Nintendo/N64", "Nintendo/Nintendo 64DD"): (bios / folder).mkdir(parents=True) @@ -1427,7 +1425,7 @@ class ResolverRegressions(unittest.TestCase): } def test_hash_identity_wins_over_wrong_destination_hint(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) wrong = root / "wrong" / "firmware.bin" correct = root / "correct" / "firmware.bin" @@ -1449,7 +1447,7 @@ class ResolverRegressions(unittest.TestCase): self.assertEqual(status, "sha1_exact") def test_name_cannot_mask_a_declared_hash_mismatch(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "firmware.bin" path.write_bytes(b"wrong") db = self._database({"firmware.bin": path}) @@ -1480,7 +1478,7 @@ class OneBaselineVerdict(unittest.TestCase): from scripts.resolve.validation import baseline_verdict entry = {"name": "dragon32.zip", "zipped_file": "d32.rom", "md5": ""} - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: path = self._archive(Path(directory), "other.rom") status, refusal = baseline_verdict(entry, path, "name_exact", "md5") self.assertEqual(refusal, "d32.rom not found inside ZIP") @@ -1499,7 +1497,7 @@ class OneBaselineVerdict(unittest.TestCase): from scripts.packs.integrity import _intentional_hash_exclusion entry = {"name": "dragon32.zip", "zipped_file": "d32.rom", "md5": ""} - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: path = self._archive(Path(directory), "other.rom") sha1 = hashlib.sha1(Path(path).read_bytes()).hexdigest() db = {"files": {sha1: {"path": path, "name": "dragon32.zip", "sha1": sha1}}, @@ -1521,7 +1519,7 @@ class OneBaselineVerdict(unittest.TestCase): from scripts.core.hashing import md5_composite from scripts.resolve.validation import baseline_verdict, digest_verdict - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: loose = Path(directory) / "abc.bin" loose.write_bytes(b"abc") md5 = hashlib.md5(b"abc").hexdigest() @@ -1551,7 +1549,7 @@ class OneBaselineVerdict(unittest.TestCase): from scripts.core.hashing import md5_composite from scripts.resolve.validation import digest_verdict - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: archive = self._archive(Path(directory), "rom.bin") raw = hashlib.md5(Path(archive).read_bytes()).hexdigest() members = md5_composite(archive) @@ -1615,7 +1613,7 @@ class OneBaselineVerdict(unittest.TestCase): from resolve import packfiles as packresolve from scripts.packs.coverage import _resolve_for_platform - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: cached = Path(directory) / "BIG.PUP" cached.write_bytes(b"large firmware") sha1 = hashlib.sha1(cached.read_bytes()).hexdigest() @@ -1635,7 +1633,7 @@ class OneBaselineVerdict(unittest.TestCase): class PackExclusionRegressions(unittest.TestCase): def test_slug_platform_core_requirement_uses_the_generated_destination(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) platforms = root / "platforms" platforms.mkdir() @@ -1763,7 +1761,7 @@ class PackExclusionRegressions(unittest.TestCase): def test_hash_platform_accounts_for_an_unsafe_exclusion(self): """A platform that reads the bytes would reject the local payload.""" - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) database, platforms = self._mismatch_fixture(root, "md5") pack = root / "pack.zip" @@ -1787,7 +1785,7 @@ class PackExclusionRegressions(unittest.TestCase): An upstream hash the local dump contradicts must not remove a file the frontend would have loaded, so its absence stays a conformance error. """ - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) database, platforms = self._mismatch_fixture(root, "existence") pack = root / "pack.zip" @@ -1806,7 +1804,7 @@ class PackExclusionRegressions(unittest.TestCase): self.assertEqual(result[8], 0) def test_unexplained_missing_file_still_fails_conformance(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) platforms = root / "platforms" platforms.mkdir() @@ -1927,7 +1925,7 @@ class RegionRegressions(unittest.TestCase): identified by its path (Dolphin's three IPL.bin) was never checked.""" import hashlib - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: previous = os.getcwd() os.chdir(directory) self.addCleanup(os.chdir, previous) @@ -1960,7 +1958,7 @@ class ArchiveSecurityRegressions(unittest.TestCase): return directory / name def test_member_count_limit_is_enforced(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) archive = self._zip_path(root) with zipfile.ZipFile(archive, "w") as handle: @@ -1973,7 +1971,7 @@ class ArchiveSecurityRegressions(unittest.TestCase): """Every member came out 0600, the mode of its temporary file: the pico8 and vox launchers the RetroDECK pack keeps 0755 lost their execute bit once download.py extracted them.""" - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) archive = self._zip_path(root) program = zipfile.ZipInfo("pico8") @@ -1994,7 +1992,7 @@ class ArchiveSecurityRegressions(unittest.TestCase): self.assertEqual((root / "out" / "bios.bin").stat().st_mode & 0o777, 0o644) def test_symlink_member_is_rejected(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) archive = self._zip_path(root) link = zipfile.ZipInfo("link") @@ -2011,7 +2009,7 @@ class ArchiveSecurityRegressions(unittest.TestCase): download.py feeds third-party archives to this function, so a legal Windows path must extract into a subdirectory instead of failing. """ - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) archive = self._zip_path(root) with zipfile.ZipFile(archive, "w") as handle: @@ -2021,7 +2019,7 @@ class ArchiveSecurityRegressions(unittest.TestCase): self.assertEqual((out / "sub" / "rom.bin").read_bytes(), b"payload") def test_windows_separator_cannot_smuggle_traversal(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) archive = self._zip_path(root) with zipfile.ZipFile(archive, "w") as handle: @@ -2031,7 +2029,7 @@ class ArchiveSecurityRegressions(unittest.TestCase): def test_high_ratio_method_is_bounded_by_size_not_ratio(self): """bzip2 legitimately exceeds the DEFLATE ceiling.""" - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) archive = self._zip_path(root) with zipfile.ZipFile(archive, "w", zipfile.ZIP_BZIP2) as handle: @@ -2041,7 +2039,7 @@ class ArchiveSecurityRegressions(unittest.TestCase): self.assertEqual((out / "zeros.bin").stat().st_size, 4_000_000) def test_compression_ratio_limit_is_enforced(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) archive = self._zip_path(root) with zipfile.ZipFile(archive, "w", zipfile.ZIP_DEFLATED) as handle: @@ -2165,7 +2163,7 @@ class InstallerBoundaryRegressions(unittest.TestCase): """ import validate_schemas - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: dist = Path(directory) broken = { "schema_version": 1, @@ -2207,7 +2205,7 @@ class InstallerBoundaryRegressions(unittest.TestCase): document, scope.pack_systems(install_list, targets)) self.assertIn("install_list", document) self.assertIn("targets", document) - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: dist = Path(directory) with zipfile.ZipFile(dist / "Pack.zip", "w") as archive: archive.writestr("manifest.json", json.dumps(document)) @@ -2241,7 +2239,7 @@ class InstallerBoundaryRegressions(unittest.TestCase): class TargetManifestRegressions(unittest.TestCase): def test_yaml_scalar_core_is_rejected_instead_of_leaking_to_json(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) source = root / "source" output = root / "output" @@ -2281,7 +2279,7 @@ class CheckoutCompletenessRegressions(unittest.TestCase): def test_restore_matches_assets_by_content_not_by_name(self): from scripts.release.restore import restore - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) cache = root / "cache" cache.mkdir() @@ -2316,7 +2314,7 @@ class CheckoutCompletenessRegressions(unittest.TestCase): from scripts.release.restore import gitignored_paths - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: missing = str(Path(directory) / "absent") with self.assertRaises(FileNotFoundError): gitignored_paths(missing) @@ -2335,7 +2333,7 @@ class CheckoutCompletenessRegressions(unittest.TestCase): database pins to the old ones.""" from scripts.release import restore as release_restore - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) cache = root / "cache" cache.mkdir() @@ -2370,7 +2368,7 @@ class CheckoutCompletenessRegressions(unittest.TestCase): def test_restore_leaves_tracked_paths_alone(self): from scripts.release.restore import restore - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) cache = root / "cache" cache.mkdir() @@ -2398,7 +2396,7 @@ class CheckoutCompletenessRegressions(unittest.TestCase): gitignored file absent: the early return ran before the check.""" from scripts.release.restore import restore - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) (root / ".gitignore").write_text("bios/big.bin\n", encoding="utf-8") (root / "database.json").write_text( @@ -2473,7 +2471,7 @@ class ManifestVersionIsThePlatformsOwn(unittest.TestCase): def test_an_unversioned_child_has_no_version(self): from scripts.model.platforms import load_platform_config - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: Path(tmp, "parent.yml").write_text("platform: P\nversion: '2.0'\nsystems: {}\n") Path(tmp, "child.yml").write_text("inherits: parent\nplatform: C\n") self.assertNotIn("version", load_platform_config("child", tmp)) @@ -2687,7 +2685,7 @@ class ReleaseAssetCriterion(unittest.TestCase): def test_a_large_committed_file_is_served_by_the_repository(self): from scripts.packs import manifestentry - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = self._repo(directory, "bios/elsewhere.bin") big = Path(root, "bios", "big.avi") big.parent.mkdir() @@ -2704,7 +2702,7 @@ class ReleaseAssetCriterion(unittest.TestCase): # name while the manifest gave install.py the spaced one, a 404. from scripts.packs import manifestentry - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = self._repo(directory, "bios/MAME/MAME 0.174 Arcade XML.dat") target = Path(root, "bios", "MAME", "MAME 0.174 Arcade XML.dat") target.parent.mkdir(parents=True) @@ -2721,7 +2719,7 @@ class ReleaseAssetCriterion(unittest.TestCase): def test_a_gitignored_file_is_served_by_the_release_whatever_its_size(self): from scripts.packs import manifestentry - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = self._repo(directory, "bios/small.zip") small = Path(root, "bios", "small.zip") small.parent.mkdir() @@ -2882,7 +2880,7 @@ class OneRefreshPerOnlineRun(unittest.TestCase): # A scratch output directory: step 4 purges the ZIPs of the one it # is given, and this run must never touch dist/. - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as out, \ + with tempfile.TemporaryDirectory() as out, \ mock.patch.object(pipeline, "run", record), \ mock.patch.object( sys, "argv", ["pipeline.py", "--skip-docs", "--output-dir", out] @@ -3210,7 +3208,7 @@ class ACheckThatCannotAnswerDoesNotPass(unittest.TestCase): """ def test_naming_a_platform_with_no_pack_is_not_a_pass(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: named = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--platform", "retroarch", "--verify-packs", "--output-dir", directory], @@ -3236,7 +3234,7 @@ class ACheckThatCannotAnswerDoesNotPass(unittest.TestCase): def test_an_unsatisfiable_declared_path_is_reported(self): from scripts.release.restore import restore - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) cache = root / "cache" cache.mkdir() @@ -3487,7 +3485,7 @@ class ARegionDroppedExtraBlocksNothing(unittest.TestCase): from scripts.packs import extras as packextras - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: other = Path(directory) / "FOO.ROM" other.write_bytes(b"other bytes") first = Path(directory) / "foo.rom" @@ -3541,7 +3539,7 @@ class AnotherEmulatorsTreeProvesNothing(unittest.TestCase): def test_neither_the_full_tail_nor_the_name_lands_in_a_foreign_tree(self): from scripts.resolve.localfile import resolve_local_file - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) # The collection's layout, read relative to its root. previous = os.getcwd() @@ -3628,7 +3626,7 @@ class ANameWithItsDirectoryIsTheDestination(unittest.TestCase): from scripts.resolve.localfile import resolve_local_file - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) previous = os.getcwd() os.chdir(root) @@ -3661,7 +3659,7 @@ class AnUnreadableDatabaseStopsTheScan(unittest.TestCase): from scripts import generate_db - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "database.json" path.write_text("<<<<<<< HEAD\n{}\n") with mock.patch.object(generate_db, "_load_gitignored_large_files", @@ -3684,7 +3682,7 @@ class TheZipIndexCacheKnowsItsInputs(unittest.TestCase): def test_the_bound_and_the_sha1_are_part_of_the_key(self): from scripts.core import ziptools - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "a.zip" with zipfile.ZipFile(path, "w") as archive: archive.writestr("big.bin", b"x" * 4096) @@ -3715,7 +3713,7 @@ class GeneratedModelsAreWrittenWhole(unittest.TestCase): def test_an_unreadable_clone_map_stops_the_run(self): from scripts import dedup - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) bios = root / "bios" # A device clone: two archive names, the same ROMs, in MAME's tree. @@ -3740,7 +3738,7 @@ class APackNoteBesideItsSlotIsANote(unittest.TestCase): def test_a_nested_note_is_not_hashed_against_the_collection(self): from scripts.packs.integrity import verify_pack - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "Pack.zip" with zipfile.ZipFile(path, "w") as archive: archive.writestr("games/keen6/INSTRUCTIONS_egagraph.ck6.txt", "File needed") @@ -3811,7 +3809,7 @@ class TheDatabaseCacheIsWrittenWhole(unittest.TestCase): from scripts import generate_db - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: path = os.path.join(directory, "cache", "db_cache.json") generate_db.save_cache(path, {"a": 1}) with mock.patch.object(json, "dumps", side_effect=TypeError("miscomputed")), \ @@ -3929,7 +3927,7 @@ class HashMergeBackupsAreNotSources(unittest.TestCase): except ImportError as exc: self.skipTest(f"validate_schemas needs jsonschema: {exc}") - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: (Path(directory) / "mame.old.yml").write_text("emulator: [\n") self.assertEqual( _validate_yaml_directory(Path(directory), "emulator.schema.json"), [] @@ -3953,7 +3951,7 @@ class AnUnreadableArchiveIsSaidOutLoud(unittest.TestCase): def test_the_resolver_names_the_archive(self): from resolve import localfile - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: broken = Path(tmp) / "neogeo.zip" broken.write_bytes(b"PK\x03\x04 truncated") sha1 = hashlib.sha1(broken.read_bytes()).hexdigest() @@ -4043,7 +4041,7 @@ class ADataDirectoryIsWalkedOnce(unittest.TestCase): def test_two_lookups_share_one_walk_and_keep_its_order(self): from resolve.datadirs import forget_data_dir_index, resolve_in_data_dirs - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "cache" (cache / "a").mkdir(parents=True) (cache / "b").mkdir() @@ -4104,7 +4102,7 @@ class AnAcceptedVersionIsNoCoreDiscrepancy(unittest.TestCase): def test_a_sibling_version_matches(self): from scripts.packs.platformpack import _matches_an_alternative - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: held = Path(tmp) / "NWINTER.GRP" held.write_bytes(b"demo") profile = json.loads(json.dumps(self.PROFILE)) @@ -4115,7 +4113,7 @@ class AnAcceptedVersionIsNoCoreDiscrepancy(unittest.TestCase): def test_a_copy_no_entry_declares_still_disagrees(self): from scripts.packs.platformpack import _matches_an_alternative - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: held = Path(tmp) / "NWINTER.GRP" held.write_bytes(b"other") profile = json.loads(json.dumps(self.PROFILE)) @@ -4134,7 +4132,7 @@ class ADataDirectoryCopyPassesTheNameChecks(unittest.TestCase): was returned without either check.""" def setUp(self): - self.tmp = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(lambda: __import__("shutil").rmtree(self.tmp, True)) cache = self.tmp / "cache" cache.mkdir() @@ -4164,7 +4162,7 @@ class AMameCloneNameIsANameStep(unittest.TestCase): parent set.""" def setUp(self): - self.tmp = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(lambda: __import__("shutil").rmtree(self.tmp, True)) bios = self.tmp / "bios" / "Arcade" bios.mkdir(parents=True) @@ -4307,7 +4305,7 @@ class VerifyStrictAppliesInEveryMode(unittest.TestCase): def setUpClass(cls): if not (ROOT / "database.json").exists(): raise unittest.SkipTest("database.json is not built") - cls.dir = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + cls.dir = Path(tempfile.mkdtemp()) (cls.dir / "fakeemu.yml").write_text( "emulator: FakeEmu\ntype: libretro\nsystems: [zz-console]\nfiles:\n" " - name: does_not_exist_strict.bin\n required: true\n" @@ -4377,7 +4375,7 @@ class ASameNamedMemberIsNotTheFile(unittest.TestCase): def test_a_declared_hash_decides_a_member_or_data_hit(self): from scripts.packs import crossref - tmp = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + tmp = Path(tempfile.mkdtemp()) self.addCleanup(lambda: __import__("shutil").rmtree(tmp, True)) (tmp / "data").mkdir() (tmp / "data" / "font.ttf").write_bytes(b"DATA FONT") @@ -4404,7 +4402,7 @@ class AnEmptyTargetIsNotEveryCore(unittest.TestCase): from scripts.model.targets import load_target_config from scripts.packs.targets import generate_target_manifests - tmp = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + tmp = Path(tempfile.mkdtemp()) self.addCleanup(lambda: __import__("shutil").rmtree(tmp, True)) targets = tmp / "platforms" / "targets" targets.mkdir(parents=True) @@ -4431,7 +4429,7 @@ class ADataDirectoryIsHeldWhileRead(unittest.TestCase): died on FileNotFoundError, or shipped bytes nobody had verified.""" def setUp(self): - self.tmp = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(lambda: __import__("shutil").rmtree(self.tmp, True)) def test_the_index_follows_a_swapped_tree(self): @@ -4509,8 +4507,8 @@ class EachRootReadsItsOwnRegistry(unittest.TestCase): def test_two_roots_in_one_process(self): from scripts.packs import manifestentry - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as a, \ - tempfile.TemporaryDirectory(dir=TMP_ROOT) as b: + with tempfile.TemporaryDirectory() as a, \ + tempfile.TemporaryDirectory() as b: Path(a, ".gitignore").write_text("bios/one.bin\n") Path(b, ".gitignore").write_text("bios/two.bin\n") self.assertTrue(manifestentry._is_release_asset(str(Path(a, "bios/one.bin")), a)) @@ -5013,7 +5011,7 @@ class AManifestHashesAFileOnce(unittest.TestCase): def test_verified_hashes_are_reused(self): from scripts.packs import manifestentry - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: path = Path(tmp, "a.bin") path.write_bytes(b"abc") sha1 = hashlib.sha1(b"abc").hexdigest() @@ -5041,7 +5039,7 @@ class AZipMemberIsHashedOnce(unittest.TestCase): def test_repeated_questions_read_the_archive_once(self): from scripts.core import ziptools - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: archive = Path(tmp, "set.zip") with zipfile.ZipFile(archive, "w") as zf: zf.writestr("ROM.bin", b"abc") @@ -5088,7 +5086,7 @@ class TargetListsReadThePinnedRelease(unittest.TestCase): def test_the_revision_comes_from_the_platform_yaml(self): from scripts.scraper.targets import BaseTargetScraper - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: for name, source, tag in ( ("a", "https://raw.githubusercontent.com/o/r/batocera-43.1/x/y", "batocera-43.1"), ("b", "https://gitlab.com/recalbox/recalbox/-/raw/10.1.1/a/b.xml", "10.1.1"), @@ -5167,7 +5165,7 @@ class ATreeNobodyHoldsIsMissingNotAnAsset(unittest.TestCase): (None, "not_found"), ) self.assertIsNone(largefiles.fetch_large_file("caesar3/", offline=True)) - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: Path(tmp, "sub").mkdir() self.assertIsNone(largefiles._fetch_asset("sub", tmp, "", "", offline=True)) @@ -5521,7 +5519,7 @@ class BundledFilesAreNotToSource(unittest.TestCase): from model.profiles import installed_data_refs - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: Path(tmp, "dolphin.yml").write_text(_yaml.safe_dump({ "emulator": "Dolphin", "type": "libretro", "files": [], "data_directories": [{"ref": "dolphin-sys", "installed_on": ["lakka"]}]})) @@ -5865,7 +5863,7 @@ class SitemapDatesComeFromThePage(unittest.TestCase): saved = dict(sitegen_descriptions.PAGE_DATA) self.addCleanup(lambda: (sitegen_descriptions.PAGE_DATA.clear(), sitegen_descriptions.PAGE_DATA.update(saved))) - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: docs = Path(tmp) (docs / "emulators").mkdir() (docs / "emulators" / "dated.md").write_text("# Dated\n\nA page with its own date.\n") @@ -6007,7 +6005,7 @@ class ZippedFileMd5IsParsedOnce(unittest.TestCase): from scripts.resolve.validation import inner_rom_check from scripts.packs.verdicts import verify_entry_md5 - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: archive = Path(directory, "x.zip") with zf_mod.ZipFile(archive, "w") as zf: zf.writestr("rom.bin", b"rom") @@ -6140,7 +6138,7 @@ class AProfilePathIsTheEmulatorsNotOurs(unittest.TestCase): except ImportError as exc: self.skipTest(f"validate_schemas needs jsonschema: {exc}") - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: emulators = Path(directory) / "emulators" emulators.mkdir() (emulators / "x.yml").write_text( @@ -6229,7 +6227,7 @@ class ANamedPackThatIsAbsentFails(unittest.TestCase): "SKIP" and exited 1: a skip label on a failure, and no next step.""" def test_the_line_says_fail_and_how_to_build(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: result = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--platform", "retroarch", "--verify-packs", "--output-dir", directory], @@ -6243,7 +6241,7 @@ class ANamedPackThatIsAbsentFails(unittest.TestCase): def test_all_with_no_pack_is_a_failure(self): """--all on a mistyped or purged directory skipped every platform and exited 0, a passed integrity check that checked nothing.""" - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: result = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--all", "--verify-packs", "--output-dir", directory], @@ -6383,7 +6381,7 @@ class TheRepairCommandWritesTheFileNamed(unittest.TestCase): def test_the_command_names_the_path(self): from scripts.model.database import DatabaseUnreadable, load_database - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: target = str(Path(directory) / "nosuch.json") with self.assertRaises(DatabaseUnreadable) as caught: load_database(target) @@ -6398,7 +6396,7 @@ class TheRepairCommandWritesTheFileNamed(unittest.TestCase): collection into a second file named after the typo.""" from scripts.model.database import DatabaseUnreadable, load_database - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: (Path(directory) / "database.json").write_text("{}") typo = Path(directory) / "databse.json" with self.assertRaises(DatabaseUnreadable) as caught: @@ -6420,7 +6418,7 @@ class VerifyPacksRefusesWhatItCannotDo(unittest.TestCase): ["--verify-packs", "--platform", "retroarch", "--one-per-slot"], ) for extra in cases: - with self.subTest(args=extra), tempfile.TemporaryDirectory(dir=TMP_ROOT) as out: + with self.subTest(args=extra), tempfile.TemporaryDirectory() as out: result = subprocess.run( [sys.executable, "scripts/generate_pack.py", *extra, "--output-dir", out], cwd=ROOT, capture_output=True, text=True, timeout=300, @@ -6716,7 +6714,7 @@ class ThePackCheckAppliesTheFrontendRule(unittest.TestCase): "sha1": hashlib.sha1(payload).hexdigest(), "size": len(payload), } - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: pack = Path(tmp) / "p.zip" with zipfile.ZipFile(pack, "w") as zf: zf.writestr("bios/x.bin", payload) @@ -6735,7 +6733,7 @@ class ABrokenRegistryIsNotAnEmptyOne(unittest.TestCase): def test_both_raise(self): from scripts.model.registry import list_registered_platforms - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: with self.assertRaises(FileNotFoundError): list_registered_platforms(tmp) Path(tmp, "_registry.yml").write_text( @@ -7103,7 +7101,7 @@ class WhatOnlyAnInstallProvidesIsListed(unittest.TestCase): import bundled_only - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp, \ + with tempfile.TemporaryDirectory() as tmp, \ mock.patch.object(bundled_only, "list_registered_platforms", return_value=[]): def entry(sha1, name): path = Path(tmp, name) @@ -7137,7 +7135,7 @@ class WhatOnlyAnInstallProvidesIsListed(unittest.TestCase): import bundled_only - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: for name in ("dir1/a.bmp", "dir2/a.bmp", "dir2/b.bmp"): Path(tmp, name).parent.mkdir(exist_ok=True) Path(tmp, name).write_bytes(b"same" if "a.bmp" in name else b"diff") @@ -7213,7 +7211,7 @@ class RequiredOnlyReachesDataDirectories(unittest.TestCase): from scripts.packs import datatrees from scripts.packs.archive import Placed - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: for key in ("needed", "optional"): Path(tmp, key).mkdir() Path(tmp, key, f"{key}.bin").write_bytes(b"x") @@ -7288,7 +7286,7 @@ class InstallerJsonKindsNeverOverwriteEachOther(unittest.TestCase): file every installer downloads, with a target table, exit 0.""" def _run(self, *flags: str, held: str) -> tuple: - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: target = Path(tmp, "retroarch.json") before = (ROOT / held).read_text(encoding="utf-8") target.write_text(before, encoding="utf-8") @@ -7327,7 +7325,7 @@ class PlatformSystemTypoGetsTheClosestNames(unittest.TestCase): from scripts.packs import platformpack out = io.StringIO() - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp, \ + with tempfile.TemporaryDirectory() as tmp, \ contextlib.redirect_stdout(out): result = platformpack.generate_pack( "retroarch", str(ROOT / "platforms"), {"files": {}, "indexes": {}}, @@ -7362,7 +7360,7 @@ class HashInputNamesWhatItAccepts(unittest.TestCase): with self.subTest(raw=raw), self.assertRaises(ValueError) as ctx: parse_hash_input(raw) self.assertIn("SHA-256 (64)", str(ctx.exception)) - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: listing = Path(tmp, "hashes.txt") listing.write_text("# list\n490f666e1afb15b7362b406ed1cea246 a.bin\nb.bin\n") with self.assertRaises(ValueError) as ctx: @@ -7465,7 +7463,7 @@ class ToolsRunFromAnyDirectory(unittest.TestCase): self.assertIn("sony-playstation", proc.stdout) def test_a_typed_path_is_read_from_where_it_was_typed(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: proc = self._run( Path(tmp), str(ROOT / "scripts" / "generate_pack.py"), "--manifest-targets", "--output-dir", "lists", @@ -7658,7 +7656,7 @@ class AnUnknownSystemIsRefusedBeforeAnyWork(unittest.TestCase): output lock and refreshed every data directory, then ended on a WARNING.""" def test_refused_before_the_lock_and_the_refresh(self): - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: out = Path(tmp) / "never" with mock.patch.dict(os.environ, {"RETROBIOS_OFFLINE": ""}): proc = subprocess.run( diff --git a/tests/test_autorun.py b/tests/test_autorun.py index 22e364916..4771971ad 100644 --- a/tests/test_autorun.py +++ b/tests/test_autorun.py @@ -46,7 +46,7 @@ _config_dir: Path | None = None def setUpModule() -> None: global _config_dir - _config_dir = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests")) + _config_dir = Path(tempfile.mkdtemp()) config = _config_dir / "gitconfig" config.write_text( "[user]\n\tname = Test\n\temail = test@example.invalid\n" @@ -97,7 +97,7 @@ class FakeHost(runner.Host): class Scratch(unittest.TestCase): def setUp(self) -> None: - self.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests")) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.tmp, True) def context(self, jobs: dict, **kwargs) -> runner.Context: diff --git a/tests/test_batocera_md5_list.py b/tests/test_batocera_md5_list.py index 89ef6e7b0..3f1841456 100644 --- a/tests/test_batocera_md5_list.py +++ b/tests/test_batocera_md5_list.py @@ -172,8 +172,7 @@ class BatoceraExportRoundTrip(unittest.TestCase): class VerifyAcceptsAnyListedMd5(unittest.TestCase): def setUp(self) -> None: - scratch = REPO_ROOT / "tmp" - self.tmp = tempfile.TemporaryDirectory(dir=scratch if scratch.is_dir() else None) + self.tmp = tempfile.TemporaryDirectory() self.addCleanup(self.tmp.cleanup) self.root = Path(self.tmp.name) @@ -398,8 +397,7 @@ class SeveralAcceptedMd5BecomeAList(unittest.TestCase): exec(compile(produced, "batocera-systems", "exec"), namespace) item = namespace["systems"]["psx"]["biosFiles"][0] self.assertEqual(item["md5"], [C, SECOND]) - scratch = REPO_ROOT / "tmp" - with tempfile.TemporaryDirectory(dir=scratch if scratch.is_dir() else None) as tmp: + with tempfile.TemporaryDirectory() as tmp: (Path(tmp) / "bios").mkdir() systems = {"psx": {"name": "PSX", "biosFiles": [item]}} for payload, missing in ( diff --git a/tests/test_campaign.py b/tests/test_campaign.py index b871d8cdd..f36613bdd 100644 --- a/tests/test_campaign.py +++ b/tests/test_campaign.py @@ -47,7 +47,6 @@ from model import measurements as mr REPO_ROOT = Path(__file__).resolve().parent.parent -TMP = REPO_ROOT / "tmp" / "tests" PROFILE = """\ emulator: Fake @@ -391,8 +390,7 @@ def screen(base: int) -> str: class Workspace(unittest.TestCase): def setUp(self) -> None: - TMP.mkdir(parents=True, exist_ok=True) - self.tmp = Path(tempfile.mkdtemp(dir=TMP)) + self.tmp = Path(tempfile.mkdtemp()) self.root = self.tmp / "repo" (self.root / "emulators").mkdir(parents=True) subprocess.run(["git", "init", "-q", str(self.root)], check=True) @@ -556,7 +554,7 @@ class ChildEnvironment(unittest.TestCase): host = FakeHost() host.run = lambda argv, **kw: (seen.append(kw.get("env")), subprocess.CompletedProcess([], 0, '{"id": "x"}', ""))[1] - with tempfile.TemporaryDirectory(dir=TMP) as tmp: + with tempfile.TemporaryDirectory() as tmp: paths = probes_host.Paths(root=Path(tmp), home=Path(tmp) / "h", content=Path(tmp) / "c", db=Path(tmp) / "db.json", content_file=probes_host.CONTENT_FILE) c = probes_campaign.Campaign(paths, probes_host.Settings(echo=False), host, lock_path=Path(tmp) / "l") @@ -615,8 +613,7 @@ class BuildIsolation(unittest.TestCase): SUB = "https://example.invalid/team/sub.git" def setUp(self) -> None: - TMP.mkdir(parents=True, exist_ok=True) - self.tmp = Path(tempfile.mkdtemp(dir=TMP)) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.tmp, True) self.pwned = self.tmp / "PWNED" sub = self.repo("sub", {"sub.c": "int x;\n"}) @@ -722,8 +719,7 @@ class BuildIsolation(unittest.TestCase): class BuiltCore(unittest.TestCase): def setUp(self) -> None: - TMP.mkdir(parents=True, exist_ok=True) - self.tree = Path(tempfile.mkdtemp(dir=TMP)) + self.tree = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.tree, True) self.secret = self.tree.parent / f"{self.tree.name}-host-file" self.secret.write_text("host secret") @@ -1068,8 +1064,7 @@ class FakeCorePasses(Workspace): _prefix, isolation = core_probe.sandbox_argv([Path(tempfile.gettempdir())]) if isolation != core_probe.SANDBOX: raise unittest.SkipTest(f"no sandbox here ({isolation}): install bubblewrap") - TMP.mkdir(parents=True, exist_ok=True) - cls.build = Path(tempfile.mkdtemp(dir=TMP)) + cls.build = Path(tempfile.mkdtemp()) source = cls.build / "fake.c" source.write_text(FAKE_CORE, encoding="utf-8") # The core sees no variable of the host, so its behaviour is compiled in. diff --git a/tests/test_case_insensitive_platforms.py b/tests/test_case_insensitive_platforms.py index 38175eb83..8dab55f15 100644 --- a/tests/test_case_insensitive_platforms.py +++ b/tests/test_case_insensitive_platforms.py @@ -47,7 +47,7 @@ class ThePackReadmeNamesTheSpellingsItLeavesOut(unittest.TestCase): from model.platforms import _platform_config_cache from model.profiles import emulator_profiles_cache import generate_db - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) previous = os.getcwd() os.chdir(tmp.name) diff --git a/tests/test_casefold_cache.py b/tests/test_casefold_cache.py index 269cd36fa..1fbbd1090 100644 --- a/tests/test_casefold_cache.py +++ b/tests/test_casefold_cache.py @@ -35,7 +35,7 @@ class APrimaryUnderAnotherCasing(unittest.TestCase): import shutil import tempfile - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.files: dict = {} self.by_name: dict = {} diff --git a/tests/test_check_freshness.py b/tests/test_check_freshness.py index 993ab54fd..43d615558 100644 --- a/tests/test_check_freshness.py +++ b/tests/test_check_freshness.py @@ -670,7 +670,7 @@ class RepositoryWiringTests(unittest.TestCase): import tempfile from pathlib import Path as _Path - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: targets = _Path(tmp) / "targets" targets.mkdir() (targets / "solo.yml").write_text( @@ -688,7 +688,7 @@ class RepositoryWiringTests(unittest.TestCase): scraped = sorted(cf._target_scrapers()) self.assertTrue(scraped) platform = scraped[0] - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: targets = _Path(tmp) / "targets" targets.mkdir() (targets / f"{platform}.yml").write_text( diff --git a/tests/test_contributing_text.py b/tests/test_contributing_text.py index 039e741da..37a776b3c 100644 --- a/tests/test_contributing_text.py +++ b/tests/test_contributing_text.py @@ -179,9 +179,7 @@ class OneFileThroughTheBrowser(unittest.TestCase): from resolve import review - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: (Path(directory) / "bios").mkdir() (Path(directory) / "bios" / "boot.rom").write_bytes(b"boot") from core.hashing import compute_hashes diff --git a/tests/test_core_file_fills_declaration.py b/tests/test_core_file_fills_declaration.py index 8417b0738..4bc02d485 100644 --- a/tests/test_core_file_fills_declaration.py +++ b/tests/test_core_file_fills_declaration.py @@ -35,8 +35,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class ACoreFileFillsAFreeDeclaration(unittest.TestCase): def setUp(self): emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) bios = self.root / "bios" / "Maker" / "Console" bios.mkdir(parents=True) @@ -105,7 +104,7 @@ class AFileDeclaredUnderAnotherName(unittest.TestCase): def test_the_report_lists_what_the_builder_packs(self): emulator_profiles_cache.clear() - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) bios = root / "bios" / "Apple" / "IIgs" bios.mkdir(parents=True) @@ -155,7 +154,7 @@ class AMissingDataDirectoryFailsTheRun(unittest.TestCase): from packs import datatrees from packs import platformpack - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) (root / "platforms").mkdir() (root / "emulators").mkdir() @@ -197,7 +196,7 @@ class AFileNobodyHoldsIsAnOmission(unittest.TestCase): from packs.manifest import generate_manifest emulator_profiles_cache.clear() - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) for folder in ("platforms", "emulators", "bios"): (root / folder).mkdir() @@ -238,7 +237,7 @@ class AMemberNameIsNotALooseFile(unittest.TestCase): from packs import crossref emulator_profiles_cache.clear() - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) (root / "platforms").mkdir() (root / "emulators").mkdir() @@ -272,7 +271,7 @@ class TwoDeclarationsOfOnePath(unittest.TestCase): def _run(self, first: str, second: str, spelling: str): emulator_profiles_cache.clear() - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) bios = root / "bios" / "Maker" / "Console" bios.mkdir(parents=True) @@ -323,7 +322,7 @@ class ANamelessWhitelistEntry(unittest.TestCase): def test_the_pack_counts_what_verify_counts(self): emulator_profiles_cache.clear() - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) bios = root / "bios" / "Sony" / "PlayStation" bios.mkdir(parents=True) diff --git a/tests/test_core_probe.py b/tests/test_core_probe.py index 46866b7b2..797743ebd 100644 --- a/tests/test_core_probe.py +++ b/tests/test_core_probe.py @@ -160,7 +160,7 @@ class ParsingTests(unittest.TestCase): def test_elf_comment(self) -> None: self.assertIsInstance(core_probe.elf_comment(Path(sys.executable).resolve()), list) - with tempfile.NamedTemporaryFile(dir=REPO_ROOT / "tmp" / "tests") as handle: + with tempfile.NamedTemporaryFile() as handle: handle.write(b"not an elf") handle.flush() self.assertEqual(core_probe.elf_comment(Path(handle.name)), []) @@ -178,7 +178,7 @@ class ParsingTests(unittest.TestCase): self.assertFalse(core_probe.uniform_frame(b"\x00\x00\x00\x00\x00\x00\x00\x01", 4)) def test_cue_tracks(self) -> None: - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as tmp: + with tempfile.TemporaryDirectory() as tmp: cue = Path(tmp, "d.cue") cue.write_text('FILE "a b.bin" BINARY\n TRACK 01 MODE2/2352\nFILE c.bin BINARY\n', encoding="utf-8") @@ -477,7 +477,7 @@ class FakeCoreTests(unittest.TestCase): @classmethod def setUpClass(cls) -> None: - cls.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests")) + cls.tmp = Path(tempfile.mkdtemp()) source = cls.tmp / "fake.c" source.write_text(FAKE_CORE, encoding="utf-8") cls.core = cls.tmp / "fake_libretro.so" @@ -739,7 +739,7 @@ class Sandbox(unittest.TestCase): def setUp(self) -> None: if not core_probe.sandbox_argv([])[0]: self.skipTest("no working bwrap on this host") - self.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests")) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.tmp, True) self.out = self.tmp / "out" self.inputs = self.tmp / "inputs" diff --git a/tests/test_core_size_refusal.py b/tests/test_core_size_refusal.py index cf9fc894e..59e022769 100644 --- a/tests/test_core_size_refusal.py +++ b/tests/test_core_size_refusal.py @@ -65,7 +65,7 @@ class _Collection(unittest.TestCase): payload = b"" def setUp(self): - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self._cwd = os.getcwd() os.chdir(self._tmp.name) for d in ("emulators", "platforms", "bios/Apple"): diff --git a/tests/test_coverage_cache.py b/tests/test_coverage_cache.py index 36f5a27f4..fa9a00903 100644 --- a/tests/test_coverage_cache.py +++ b/tests/test_coverage_cache.py @@ -24,7 +24,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent class CoverageCache(unittest.TestCase): def setUp(self) -> None: - self.work = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests")) + self.work = Path(tempfile.mkdtemp()) self.platforms = self.work / "platforms" self.platforms.mkdir() (self.platforms / "alpha.yml").write_text("platform: Alpha\n") diff --git a/tests/test_cross_reference_sources.py b/tests/test_cross_reference_sources.py index 8b88478ed..24f2dc867 100644 --- a/tests/test_cross_reference_sources.py +++ b/tests/test_cross_reference_sources.py @@ -75,7 +75,7 @@ class GapReportSources(unittest.TestCase): self.assertIn("0 missing (need to be sourced)", text) def test_a_directory_does_not_stand_for_a_file(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: (Path(tmp) / "bios" / "cpcemu" / "ROM").mkdir(parents=True) names = build_supplemental_index(str(Path(tmp) / "data"), str(Path(tmp) / "bios")) self.assertIsNone(entry_source({"name": "ROM"}, _index(data_names=names))) diff --git a/tests/test_data_dir_refs.py b/tests/test_data_dir_refs.py index ab46633d4..e885528ae 100644 --- a/tests/test_data_dir_refs.py +++ b/tests/test_data_dir_refs.py @@ -36,7 +36,7 @@ class EachSourceIsParsedOnce(unittest.TestCase): import validate_schemas except ImportError as exc: self.skipTest(f"validate_schemas needs jsonschema: {exc}") - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) (root / "emulators").mkdir() (root / "platforms").mkdir() diff --git a/tests/test_db_aliases.py b/tests/test_db_aliases.py index 229d2a327..535ba3bcf 100644 --- a/tests/test_db_aliases.py +++ b/tests/test_db_aliases.py @@ -32,7 +32,7 @@ class AliasesNeedAnUnambiguousName(unittest.TestCase): def _aliases(self, files: dict) -> dict: stub = types.ModuleType("scraper.coreinfo_scraper") stub.Scraper = _NoCoreInfo - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -91,7 +91,7 @@ class NoNetworkInTheBuild(unittest.TestCase): self.assertNotIn("urllib.request", source) def test_hash_proven_entry_registers_its_own_name(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -109,7 +109,7 @@ class NoNetworkInTheBuild(unittest.TestCase): class AcceptedRevisionLists(unittest.TestCase): def test_a_list_of_sha1_names_every_held_revision(self): """A profile accepting several revisions writes sha1 as a list.""" - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -130,7 +130,7 @@ class AcceptedRevisionLists(unittest.TestCase): class CrossNamingStaysInItsProfile(unittest.TestCase): def test_an_alias_naming_a_sibling_entry_is_not_indexed(self): """dosbox-x aliases MT32_CONTROL.ROM and CM32L_CONTROL.ROM to each other.""" - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -160,9 +160,7 @@ class AnUnreadableSourceStopsTheRun(unittest.TestCase): import generate_db - tmp_root = Path(__file__).resolve().parents[1] / "tmp" - tmp_root.mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=tmp_root)) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) @@ -181,7 +179,7 @@ class DrasticNamesTheDSDumps(unittest.TestCase): its own three names.""" def _aliases(self, files: dict) -> dict: - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -226,7 +224,7 @@ class AliasesFollowContentNotPrimaryCopy(unittest.TestCase): def _aliases(self, primary: str, copy: str) -> dict: files = {"s": {"name": primary, "path": f"bios/N64DD/{primary}", "md5": "m"}} copies = {"s": [{"name": copy, "path": f"bios/N64DD/{copy}"}]} - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -253,7 +251,7 @@ class AliasesFollowContentNotPrimaryCopy(unittest.TestCase): "b": {"name": "Satellaview_BS-X.sfc", "path": "bios/SNES/x.sfc", "md5": "m2"}, } copies = {"b": [{"name": "BS-X.bin", "path": "bios/Satellaview/BS-X.bin"}]} - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -283,7 +281,7 @@ class TheSmsBiosKeepsItsNames(unittest.TestCase): "kiosk": {"name": "bios_U.sms", "path": "bios/Sega/MS/.variants/bios_U.sms.ee2c29ba", "md5": "mk"}, } - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -303,7 +301,7 @@ class TheSmsBiosKeepsItsNames(unittest.TestCase): "v13": {"name": "SMS_us_1.3.sms", "path": "bios/Sega/MS/SMS_us_1.3.sms", "md5": "m13"}, "other": {"name": "bios_U.sms", "path": "bios/Sega/MS/bios_U.sms", "md5": "mo"}, } - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: previous = os.getcwd() os.chdir(tmp) try: @@ -319,7 +317,7 @@ class TheSmsBiosKeepsItsNames(unittest.TestCase): self.assertEqual(aliases, {}) def test_a_copy_under_its_machine_is_the_path_over_an_emulator_tree(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: bios = Path(tmp) / "bios" for rel in ("Other/zesarux/sms.rom", "Sega/Master System/SMS_us_1.3.sms"): (bios / rel).parent.mkdir(parents=True, exist_ok=True) diff --git a/tests/test_declared_names.py b/tests/test_declared_names.py index 797a62ae3..5b1dea909 100644 --- a/tests/test_declared_names.py +++ b/tests/test_declared_names.py @@ -26,7 +26,7 @@ class FlatDeclaredSet(unittest.TestCase): SYSTEM_ALIASES joined them.""" import tempfile - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: platforms = Path(tmp) (platforms / "fx.yml").write_text( "platform: Fx\nverification_mode: existence\nsystems:\n" diff --git a/tests/test_derivations.py b/tests/test_derivations.py index 165919123..7c6c2375e 100644 --- a/tests/test_derivations.py +++ b/tests/test_derivations.py @@ -36,7 +36,7 @@ def _wanted(data: bytes) -> dict: class HeldDumpsAnswerCatalogEntries(unittest.TestCase): def setUp(self): - self.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.tmp, True) def test_combine_agrees_with_zlib(self): @@ -74,7 +74,7 @@ class ARomsetMemberIsASource(unittest.TestCase): def test_members_derive_and_concatenate(self): import zipfile - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) chip, low, high = os.urandom(64), os.urandom(32), os.urandom(32) archive = root / "set.zip" @@ -111,7 +111,7 @@ class OneContentIsTransformedOnce(unittest.TestCase): def test_a_repeated_chip_is_transformed_once_and_keeps_its_first_path(self): import zipfile - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) chip = os.urandom(64) files = {} diff --git a/tests/test_deterministic_zip.py b/tests/test_deterministic_zip.py index 9f0578a91..5ca3c4817 100644 --- a/tests/test_deterministic_zip.py +++ b/tests/test_deterministic_zip.py @@ -266,7 +266,7 @@ class ManifestInjectionIsAtomic(unittest.TestCase): from scripts.packs import finalize - with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as d: + with tempfile.TemporaryDirectory() as d: pack = Path(d) / "Pack.zip" with zipfile.ZipFile(pack, "w", zipfile.ZIP_DEFLATED) as zf: for i in range(20): diff --git a/tests/test_doc_pages.py b/tests/test_doc_pages.py index d715fde1a..3fcee1dd5 100644 --- a/tests/test_doc_pages.py +++ b/tests/test_doc_pages.py @@ -2098,7 +2098,7 @@ class LandingAChangeNamesTheCommitRules(unittest.TestCase): import tempfile block = re.search(r"```bash\n(.*?)```", self._landing(), re.S).group(1) - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as scratch: + with tempfile.TemporaryDirectory() as scratch: clone = Path(scratch) (clone / ".git" / "hooks").mkdir(parents=True) (clone / "scripts").mkdir() diff --git a/tests/test_download.py b/tests/test_download.py index 7844ab98e..42742ab54 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -10,6 +10,7 @@ checksum of each layout and the staging location. from __future__ import annotations import tests +from tests import scratch_dir import contextlib import functools @@ -60,19 +61,6 @@ RELEASE_ASSETS = [ ] -def _tempdir(test: unittest.TestCase) -> str: - """A scratch directory under the repository's tmp/, removed after the test. - - The system temp directory is a RAM disk here, and directories left by - every run piled up on it. - """ - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - path = tempfile.mkdtemp(dir=str(scratch)) - test.addCleanup(shutil.rmtree, path, True) - return path - - def _closed_port() -> int: """A loopback port nothing listens on, so connecting is refused at once.""" with socket.socket() as sock: @@ -252,7 +240,7 @@ class TestPackGrouping(unittest.TestCase): class TestJoinVolumes(unittest.TestCase): def test_joined_volumes_reproduce_the_archive(self): - tmp = Path(_tempdir(self)) + tmp = scratch_dir(self) archive = tmp / "pack.zip" with zipfile.ZipFile(archive, "w") as zf: zf.writestr("bios/scph5501.bin", b"\x01\x02" * 5000) @@ -301,7 +289,7 @@ class TestStagingIsolation(unittest.TestCase): """Two downloads into one BIOS folder must not share a staging directory.""" def setUp(self): - self.dest = Path(_tempdir(self)) + self.dest = scratch_dir(self) self.addCleanup(shutil.rmtree, self.dest, True) def test_two_runs_stage_in_separate_directories(self): @@ -336,9 +324,7 @@ class ReleaseServer: volumes: int, zip_parts: bool = False, ): - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=str(scratch))) + self.root = Path(tempfile.mkdtemp()) (self.root / "assets").mkdir() archive = self.root / "assets" / pack_name with zipfile.ZipFile(archive, "w", zipfile.ZIP_DEFLATED) as zf: @@ -434,10 +420,10 @@ class DownloaderCase(unittest.TestCase): self.pack_name, self.payload, self.volumes, self.zip_parts ) self.addCleanup(self.server.close) - self.dest = Path(_tempdir(self)) / "bios" + self.dest = scratch_dir(self) / "bios" # A pack is gigabytes: staging it in the system temp directory fills # the RAM disk that /tmp is on the appliances these packs target. - self.tmpdir = Path(_tempdir(self)) + self.tmpdir = scratch_dir(self) def env(self) -> dict[str, str]: env = dict(os.environ) @@ -612,7 +598,7 @@ class TestDownloadShell(DownloaderCase): """unzip -o unlinks a file and writes the new one under its final name: a run killed mid-file left a partial BIOS where a valid one was. Extraction now writes beside the folder and renames.""" - shim = Path(_tempdir(self)) + shim = scratch_dir(self) (shim / "unzip").write_text( "#!/bin/sh\n" 'for target; do :; done\n' @@ -641,7 +627,7 @@ class TestDownloadShell(DownloaderCase): def test_two_runs_into_one_folder_both_finish(self): """Both runs staged in `/.retrobios-download` and the second emptied it while the first was still writing its parts.""" - shim = Path(_tempdir(self)) + shim = scratch_dir(self) real = shutil.which("curl") (shim / "curl").write_text( "#!/bin/sh\n" @@ -753,7 +739,7 @@ class TheShellDownloaderSendsTheToken(unittest.TestCase): one succeeded. A curl stand-in records what each call carries.""" def _calls(self, **env: str) -> str: - scratch = Path(_tempdir(self)) + scratch = scratch_dir(self) log = scratch / "calls.log" fake = scratch / "curl" fake.write_text( diff --git a/tests/test_e2e.py b/tests/test_e2e.py index fa14c6232..da28afb85 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -6823,9 +6823,7 @@ class OneOfASearchList(unittest.TestCase): from model.profiles import emulator_profiles_cache emulator_profiles_cache.clear() - repo = Path(__file__).resolve().parent.parent - (repo / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=repo / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) previous = os.getcwd() os.chdir(self.root) @@ -7090,9 +7088,7 @@ class AnArchiveIsAMemberOfASet(unittest.TestCase): from model.profiles import emulator_profiles_cache emulator_profiles_cache.clear() - repo = Path(__file__).resolve().parent.parent - (repo / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=repo / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) diff --git a/tests/test_emulator_pack_counts.py b/tests/test_emulator_pack_counts.py index 7cda60780..75a67ad89 100644 --- a/tests/test_emulator_pack_counts.py +++ b/tests/test_emulator_pack_counts.py @@ -40,11 +40,8 @@ class PackAndReportAgree(unittest.TestCase): def test_each_emulator_pack_counts_as_verify_does(self): if not (REPO_ROOT / "database.json").is_file(): self.skipTest("database.json is not built") - (REPO_ROOT / "tmp").mkdir(exist_ok=True) for emulator in CASES: - with self.subTest(emulator=emulator), tempfile.TemporaryDirectory( - dir=REPO_ROOT / "tmp" - ) as out: + with self.subTest(emulator=emulator), tempfile.TemporaryDirectory() as out: pack = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--emulator", emulator, "--offline", "--output-dir", out], @@ -85,8 +82,7 @@ class APlaceholderIsAnsweredByEvidence(unittest.TestCase): from packs.emulatorcheck import verify_emulator emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index e3cca753c..4f84ff82b 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -930,7 +930,7 @@ class AStaleTruthIsRefused(unittest.TestCase): from exporter.native import load_inputs, StaleTruth root = Path(__file__).resolve().parents[1] - truth_dir = Path(tempfile.mkdtemp(dir=root / "tmp")) + truth_dir = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, truth_dir, True) (truth_dir / "retropie.yml").write_text("platform: retropie\nsystems: {}\n") with self.assertRaises(StaleTruth): diff --git a/tests/test_export_native_layer.py b/tests/test_export_native_layer.py index 896c3304e..630752f51 100644 --- a/tests/test_export_native_layer.py +++ b/tests/test_export_native_layer.py @@ -77,7 +77,7 @@ class TheTruthDiffReadsTheSameLayer(unittest.TestCase): import json import subprocess - with tempfile.TemporaryDirectory(dir=str(REPO_ROOT / "tmp")) as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) (root / "demo.yml").write_text( "platform: Demo\nsystems:\n" diff --git a/tests/test_export_report.py b/tests/test_export_report.py index 4e2bd4385..eafc6a0fc 100644 --- a/tests/test_export_report.py +++ b/tests/test_export_report.py @@ -39,7 +39,7 @@ def _report(platform: str, files: list[str], **changes: object) -> dict: class ExportReportIsWrittenAndRead(unittest.TestCase): def test_report_round_trips_through_the_page_loader(self): - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as scratch: + with tempfile.TemporaryDirectory() as scratch: report = _report("recalbox", ["es_bios.xml"]) write_report(Path(scratch) / "recalbox.json", report) (Path(scratch) / "recalbox").mkdir() @@ -48,7 +48,7 @@ class ExportReportIsWrittenAndRead(unittest.TestCase): def test_a_report_goes_into_a_directory_not_yet_made(self): """RetroPie with nothing left to correct writes no file, so its output directory was never made and the report crashed --all.""" - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as scratch: + with tempfile.TemporaryDirectory() as scratch: target = Path(scratch) / "fresh" / "retropie.json" write_report(target, _report("retropie", [])) self.assertTrue(target.exists()) @@ -216,7 +216,7 @@ class TheRunReportStatesWhatTheFileCarries(unittest.TestCase): "md5": "a" * 32}, ]}}} doubled = {"destination": "a.bin", "declarations": []} - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as scratch, \ + with tempfile.TemporaryDirectory() as scratch, \ mock.patch.object(native, "load_inputs", return_value=(truth, scraped)), \ mock.patch.object(native, "unpinned", return_value=[]), \ @@ -589,7 +589,7 @@ class ADestinationDeclaredTwiceIsNamed(unittest.TestCase): def setUp(self): import hashlib - self._tmp = tempfile.TemporaryDirectory(dir=ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() root = Path(self._tmp.name) files, by_md5, by_name = {}, {}, {} self.md5 = {} diff --git a/tests/test_exporters.py b/tests/test_exporters.py index ed2ce4def..2cc9ae8c4 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -617,7 +617,7 @@ class ExporterRegistry(unittest.TestCase): import export_native - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as directory: + with tempfile.TemporaryDirectory() as directory: platforms = Path(directory) (platforms / "_registry.yml").write_text( "platforms:\n cardonly:\n native_list: none\n unwritten: {}\n", @@ -690,7 +690,7 @@ class ExporterRegistry(unittest.TestCase): def test_an_export_without_its_original_writes_nothing(self): from exporter.native import export_platform - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: output = Path(tmp) / "out" ok, messages = export_platform( "retroarch", discover_exporters()["retroarch"], @@ -1583,7 +1583,7 @@ class AnExportIsWrittenAsItsBytes(unittest.TestCase): from exporter.native import _write_produced - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) _write_produced(root, { "FirmwareDatabase.cs": "a\r\nb\r\n", @@ -1612,7 +1612,7 @@ class AnExportWithoutTruthIsRefused(unittest.TestCase): from exporter.native import export_platform exporter = discover_exporters()["batocera"] - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: output = Path(tmp) / "out" published = output / "batocera" / "batocera-systems" published.parent.mkdir(parents=True) @@ -1643,7 +1643,7 @@ class AnInvalidExportIsNotWritten(unittest.TestCase): self.skipTest("upstream cache not populated") exporter = discover_exporters()["romm"] config = native_layer(load_platform_config("romm", str(REPO_ROOT / "platforms"))) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: output = Path(tmp) / "out" published = output / "romm" / "known_bios_files.json" published.parent.mkdir(parents=True) @@ -2020,7 +2020,7 @@ class MisterDatabaseComesBackAsWritten(unittest.TestCase): def test_bytes_are_written_untouched(self): from exporter.native import _write_produced - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: _write_produced(Path(tmp), {"a.zip": b"PK\x03\x04\xff"}, {}) self.assertEqual((Path(tmp) / "a.zip").read_bytes(), b"PK\x03\x04\xff") diff --git a/tests/test_finalize_pack_names.py b/tests/test_finalize_pack_names.py index b37bcff40..bdbcc456f 100644 --- a/tests/test_finalize_pack_names.py +++ b/tests/test_finalize_pack_names.py @@ -26,7 +26,7 @@ class FinalizeByExactName(unittest.TestCase): previous = os.getcwd() os.chdir(REPO_ROOT) self.addCleanup(os.chdir, previous) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: with zipfile.ZipFile(Path(tmp) / "MiSTer_FPGA_Custom_BIOS_Pack.zip", "w") as zf: zf.writestr("README.txt", "custom") ok = verify_and_finalize_packs(tmp, {"files": {}, "indexes": {}}) @@ -42,7 +42,7 @@ class APackFromAnotherRunIsLeftAlone(unittest.TestCase): import json import subprocess - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: def build(platform: str) -> str: proc = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--platform", platform, diff --git a/tests/test_foreign_tree_names.py b/tests/test_foreign_tree_names.py index 396b991ce..072c4f253 100644 --- a/tests/test_foreign_tree_names.py +++ b/tests/test_foreign_tree_names.py @@ -25,8 +25,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class ForeignTreeNames(unittest.TestCase): def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) # The collection's paths are relative to the repository root. self.addCleanup(os.chdir, os.getcwd()) diff --git a/tests/test_frontend_digest.py b/tests/test_frontend_digest.py index e0ecf4cb8..78d729c04 100644 --- a/tests/test_frontend_digest.py +++ b/tests/test_frontend_digest.py @@ -29,8 +29,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class FrontendDigestDecides(unittest.TestCase): def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self.tmp = tempfile.TemporaryDirectory() self.addCleanup(self.tmp.cleanup) root = Path(self.tmp.name) self.bios = root / "bios" diff --git a/tests/test_game_catalogs.py b/tests/test_game_catalogs.py index e9bc31819..55debd26d 100644 --- a/tests/test_game_catalogs.py +++ b/tests/test_game_catalogs.py @@ -15,8 +15,6 @@ from model.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" try: @@ -56,7 +54,7 @@ class RegionTags(unittest.TestCase): class FixtureImport(unittest.TestCase): def setUp(self) -> None: - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.out = Path(self.temp.name) def tearDown(self) -> None: @@ -193,7 +191,7 @@ class CommittedCatalogs(unittest.TestCase): self.assertEqual(importer.dump_catalog(doc), path.read_text()) def test_fixture_output_matches_the_schema(self) -> None: - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: out = Path(directory) for source in ("no-intro", "redump"): self.assertEqual(run_import(source, out).returncode, 0) diff --git a/tests/test_games_index.py b/tests/test_games_index.py index 359d67e52..4b275c23a 100644 --- a/tests/test_games_index.py +++ b/tests/test_games_index.py @@ -20,8 +20,6 @@ import generate_games_index as gi from model.romfolders import SystemResolver, load_setups ROOT = Path(__file__).resolve().parent.parent -TMP_ROOT = ROOT / "tmp" / "tests" -TMP_ROOT.mkdir(parents=True, exist_ok=True) SETUP = """\ setup: fixture @@ -72,7 +70,7 @@ ARCADE = {"profile": "mame", "bios": {"neogeo": ["mslug"]}} class GamesIndexFixture(unittest.TestCase): def setUp(self) -> None: - self.tmp = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + self.tmp = Path(tempfile.mkdtemp()) (self.tmp / "romfolders").mkdir() (self.tmp / "romfolders" / "fixture.yml").write_text(SETUP, encoding="utf-8") (self.tmp / "install").mkdir() diff --git a/tests/test_handheld_launchers.py b/tests/test_handheld_launchers.py index 56ec8f069..8f54013e7 100644 --- a/tests/test_handheld_launchers.py +++ b/tests/test_handheld_launchers.py @@ -11,6 +11,7 @@ the pad reaching the console, a compositor covering it) is not exercised. from __future__ import annotations import tests +from tests import scratch_dir import contextlib import hashlib @@ -24,7 +25,6 @@ import signal import struct import subprocess import sys -import tempfile import termios import time import unittest @@ -74,14 +74,6 @@ INTERFACE_KEYS = { GPTOKEYB_NAMES = set(SEQUENCES) | {"backspace", '\\"'} -def _tempdir(test: unittest.TestCase) -> Path: - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - path = Path(tempfile.mkdtemp(dir=str(scratch))) - test.addCleanup(shutil.rmtree, path, True) - return path - - def read_gptk(path: Path) -> dict[str, list[str]]: """key -> values, as gptokeyb's parseConfigFile reads `key = value`.""" mapping: dict[str, list[str]] = {} @@ -282,7 +274,7 @@ class TheArchives(unittest.TestCase): } def setUp(self): - self.out = _tempdir(self) + self.out = scratch_dir(self) def test_every_release_archive_is_built(self): self.assertEqual(set(port.ARCHIVES), set(self.LAYOUT)) @@ -364,7 +356,7 @@ class TheArchives(unittest.TestCase): self.assertEqual(zf.read(f"{folder}/packs.txt").decode(), expected) def test_an_unpinned_installer_is_refused(self): - root = _tempdir(self) + root = scratch_dir(self) for name in ("install.py", "install.sh", "LICENSE", "NOTICE"): shutil.copy(REPO_ROOT / name, root / name) shutil.copytree(PORTS, root / "ports") @@ -694,7 +686,7 @@ class Device: def __init__(self, test: unittest.TestCase, **env: str): self.test = test - self.root = _tempdir(test) + self.root = scratch_dir(test) self.state = self.root / "state" self.state.mkdir() # Registered before every other cleanup, so it runs after them. @@ -1568,7 +1560,9 @@ class TheBatoceraPort(unittest.TestCase): socket_dir.mkdir() import socket as _socket sock = _socket.socket(_socket.AF_UNIX) - sock.bind(str(socket_dir / "X0")) + # A socket address holds 108 bytes, fewer than a scratch folder can. + with contextlib.chdir(socket_dir): + sock.bind("X0") self.addCleanup(sock.close) cookie = device.root / "Xauthority" cookie.write_text("") diff --git a/tests/test_hash_merge.py b/tests/test_hash_merge.py index a61854106..3fc3f02de 100644 --- a/tests/test_hash_merge.py +++ b/tests/test_hash_merge.py @@ -841,7 +841,7 @@ class WritersPutTheValuesOnDisk(unittest.TestCase): fixtures use the layout the profiles use (entries indented two).""" def setUp(self): - self.dir = Path(tempfile.mkdtemp(dir=Path(__file__).resolve().parents[1] / "tmp")) + self.dir = Path(tempfile.mkdtemp()) self.addCleanup(lambda: __import__("shutil").rmtree(self.dir, True)) def test_fbneo_writes_a_changed_crc32(self): diff --git a/tests/test_hashing.py b/tests/test_hashing.py index 7bee821ad..179c83ced 100644 --- a/tests/test_hashing.py +++ b/tests/test_hashing.py @@ -24,7 +24,7 @@ class HashesAreReadOncePerContent(unittest.TestCase): per platform and entry, in one process.""" def setUp(self): - self.dir = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.dir = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.dir, True) self.file = self.dir / "rom.bin" self.file.write_bytes(b"a" * 64) @@ -52,7 +52,7 @@ class OneDigestLoopForFilesAndStreams(unittest.TestCase): DATA = bytes(range(256)) * 600 # over two 64 KiB reads def setUp(self): - self.dir = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.dir = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.dir, True) self.file = self.dir / "rom.bin" self.file.write_bytes(self.DATA) diff --git a/tests/test_install.py b/tests/test_install.py index a9c5e075a..69adc5cf2 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -2,6 +2,7 @@ from __future__ import annotations import tests +from tests import scratch_dir import argparse import contextlib @@ -47,19 +48,6 @@ PIN_ADVICE = "install.py changed: python scripts/pin_installer.py rewrites both setUpModule, tearDownModule = module_guard("test_install") -def _tempdir(test: unittest.TestCase) -> str: - """A scratch directory under the repository's tmp/, removed after the test. - - The system temp directory is a RAM disk here, and directories left by - every run piled up on it. - """ - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - path = tempfile.mkdtemp(dir=str(scratch)) - test.addCleanup(shutil.rmtree, path, True) - return path - - def _parenthesized_withs(tokens: list) -> list[str]: import tokenize @@ -424,7 +412,7 @@ class TestFreeSpaceGuard(unittest.TestCase): """The run refuses before writing when the volume cannot hold it.""" def setUp(self): - self.root = Path(_tempdir(self)) + self.root = scratch_dir(self) self.real = install.shutil.disk_usage def tearDown(self): @@ -565,11 +553,11 @@ class AMissingDestIsSaid(unittest.TestCase): return out.getvalue(), code def test_an_existing_folder_says_nothing(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) self.assertEqual(self._call(root, True), ("", None)) def test_a_deep_missing_path_is_asked_and_no_is_the_default(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) dest = root / "retroarh" / "system" out, code = self._call(dest, True, "") self.assertEqual(code, 2) @@ -584,7 +572,7 @@ class AMissingDestIsSaid(unittest.TestCase): self.assertFalse((root / "a").exists()) def test_one_missing_level_or_no_terminal_is_said_not_asked(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) # A "no" that was asked would stop the run with 2. Said with # --verbose: the folder is made, and the run names it. install.OUTPUT.verbose = False @@ -614,7 +602,7 @@ class ADestThatIsAFileIsNamed(unittest.TestCase): stdin=subprocess.DEVNULL) def test_the_file_is_named_and_sudo_is_not_offered(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) (root / "scph5501.bin").write_bytes(b"x") for dest, words in ( (root / "scph5501.bin", f"{root / 'scph5501.bin'} is a file, not a folder"), @@ -642,7 +630,7 @@ class SaveFilesAListHoldsNoneOfAreNotPromised(unittest.TestCase): def test_the_reason_is_said_and_no_option_is_offered(self): manifest = json.loads((REPO_ROOT / "install" / "retropie.json").read_text()) self.assertIsNone(manifest.get("save_directory")) - root = Path(_tempdir(self)) + root = scratch_dir(self) env = dict(os.environ, RETROBIOS_OS="linux") for extra in ([], ["--save-dir", str(root / "saves")]): with self.subTest(extra=extra): @@ -749,7 +737,7 @@ class TestAndroidDetection(unittest.TestCase): self.assertEqual(install.detect_os(), "android") def test_default_directory_found_without_a_config(self): - storage = Path(_tempdir(self)) + storage = scratch_dir(self) (storage / "RetroArch" / "system").mkdir(parents=True) os.environ["EXTERNAL_STORAGE"] = str(storage) self.assertEqual( @@ -759,7 +747,7 @@ class TestAndroidDetection(unittest.TestCase): shutil.rmtree(storage) def test_config_default_resolves_against_the_retroarch_root(self): - storage = Path(_tempdir(self)) + storage = scratch_dir(self) files = storage / "Android" / "data" / "com.retroarch.aarch64" / "files" files.mkdir(parents=True) (files / "retroarch.cfg").write_text( @@ -773,7 +761,7 @@ class TestAndroidDetection(unittest.TestCase): shutil.rmtree(storage) def test_custom_system_directory_wins(self): - storage = Path(_tempdir(self)) + storage = scratch_dir(self) files = storage / "Android" / "data" / "com.retroarch" / "files" files.mkdir(parents=True) custom = storage / "Emulation" / "bios" @@ -783,13 +771,13 @@ class TestAndroidDetection(unittest.TestCase): shutil.rmtree(storage) def test_nothing_found_on_a_bare_device(self): - storage = Path(_tempdir(self)) + storage = scratch_dir(self) os.environ["EXTERNAL_STORAGE"] = str(storage) self.assertEqual(install._detect_android(), []) shutil.rmtree(storage) def test_detect_platforms_routes_android(self): - storage = Path(_tempdir(self)) + storage = scratch_dir(self) (storage / "RetroArch" / "system").mkdir(parents=True) os.environ["EXTERNAL_STORAGE"] = str(storage) self.assertEqual( @@ -803,7 +791,7 @@ class TestAndroidDetection(unittest.TestCase): self.assertIn("/storage/emulated/0/RetroArch/system", hint) def test_named_platform_falls_back_to_shared_storage(self): - storage = Path(_tempdir(self)) + storage = scratch_dir(self) os.environ["EXTERNAL_STORAGE"] = str(storage) self.assertEqual( install._default_dest("android", "retroarch"), @@ -825,7 +813,7 @@ class TestLaunchboxDetection(unittest.TestCase): """LaunchBox references its emulators in Data/Emulators.xml.""" def _make_launchbox(self, app_path: str, title: str = "Retroarch"): - root = Path(_tempdir(self)) + root = scratch_dir(self) data = root / "LaunchBox" / "Data" data.mkdir(parents=True) xml = data / "Emulators.xml" @@ -850,7 +838,7 @@ class TestLaunchboxDetection(unittest.TestCase): ) def test_absolute_application_path(self): - emu_dir = Path(_tempdir(self)) / "RetroArch" + emu_dir = scratch_dir(self) / "RetroArch" emu_dir.mkdir(parents=True) root, xml = self._make_launchbox(str(emu_dir / "retroarch.exe")) self.assertEqual( @@ -866,7 +854,7 @@ class TestLaunchboxDetection(unittest.TestCase): self.assertIsNone(install._launchbox_retroarch_system_dir(xml)) def test_stale_entry_before_installed_one(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) data = root / "LaunchBox" / "Data" data.mkdir(parents=True) ra_dir = root / "LaunchBox" / "Emulators" / "RetroArch" @@ -893,7 +881,7 @@ class TestLaunchboxDetection(unittest.TestCase): self.assertIsNone( install._launchbox_retroarch_system_dir(Path("/nonexistent/Emulators.xml")) ) - root = Path(_tempdir(self)) + root = scratch_dir(self) bad = root / "Emulators.xml" bad.write_text("not xml at all <<<") self.assertIsNone(install._launchbox_retroarch_system_dir(bad)) @@ -903,7 +891,7 @@ class TestRetroarchPathExpansion(unittest.TestCase): """RetroArch abbreviates paths with '~' and ':' in its config.""" def _cfg(self, value: str) -> Path: - app_dir = Path(_tempdir(self)) + app_dir = scratch_dir(self) (app_dir / "retroarch.cfg").write_text(f'system_directory = "{value}"\n') return app_dir @@ -930,7 +918,7 @@ class TestRetroarchPathExpansion(unittest.TestCase): def test_application_dir_overrides_config_dir(self): app_dir = self._cfg(":\\system") - elsewhere = Path(_tempdir(self)) + elsewhere = scratch_dir(self) self.assertEqual( install._parse_retroarch_system_dir( app_dir / "retroarch.cfg", elsewhere @@ -939,7 +927,7 @@ class TestRetroarchPathExpansion(unittest.TestCase): ) def test_absolute_path_untouched(self): - target = Path(_tempdir(self)) / "bios" + target = scratch_dir(self) / "bios" app_dir = self._cfg(str(target)) self.assertEqual( install._parse_retroarch_system_dir(app_dir / "retroarch.cfg"), target @@ -958,7 +946,7 @@ class TestLaunchboxRoot(unittest.TestCase): def test_shortcut_target_is_read(self): # Byte layout of the shortcut a real install writes - lnk = Path(_tempdir(self)) / "LaunchBox.lnk" + lnk = scratch_dir(self) / "LaunchBox.lnk" lnk.write_bytes( b"L\x00\x00\x00\x01\x14\x02\x00\x00\x00\x00\x00\xc0\x00\x00\x00" b"\x00\x00\x00\x46" + b"\x00" * 8 @@ -971,15 +959,15 @@ class TestLaunchboxRoot(unittest.TestCase): ) def test_shortcut_without_target_is_ignored(self): - lnk = Path(_tempdir(self)) / "LaunchBox.lnk" + lnk = scratch_dir(self) / "LaunchBox.lnk" lnk.write_bytes(b"L\x00\x00\x00 no target here ") self.assertIsNone(install._lnk_target(lnk, "LaunchBox.exe")) def test_shortcut_pointing_elsewhere_falls_back(self): # A stale shortcut must not win over a real installation - userprofile = Path(_tempdir(self)) + userprofile = scratch_dir(self) root = self._make_root(userprofile / "LaunchBox") - appdata = Path(_tempdir(self)) + appdata = scratch_dir(self) lnk_dir = ( appdata / "Microsoft" / "Windows" / "Start Menu" / "Programs" / "LaunchBox" ) @@ -992,9 +980,9 @@ class TestLaunchboxRoot(unittest.TestCase): self.assertEqual(install.launchbox_root("windows"), root) def test_falls_back_to_userprofile(self): - userprofile = Path(_tempdir(self)) + userprofile = scratch_dir(self) root = self._make_root(userprofile / "LaunchBox") - env = {"APPDATA": str(Path(_tempdir(self))), "USERPROFILE": str(userprofile)} + env = {"APPDATA": str(scratch_dir(self)), "USERPROFILE": str(userprofile)} with unittest.mock.patch.dict(os.environ, env): self.assertEqual(install.launchbox_root("windows"), root) @@ -1003,8 +991,8 @@ class TestLaunchboxRoot(unittest.TestCase): def test_nothing_installed(self): env = { - "APPDATA": str(Path(_tempdir(self))), - "USERPROFILE": str(Path(_tempdir(self))), + "APPDATA": str(scratch_dir(self)), + "USERPROFILE": str(scratch_dir(self)), } with unittest.mock.patch.dict(os.environ, env): self.assertIsNone(install.launchbox_root("windows")) @@ -1014,7 +1002,7 @@ class TestLaunchboxBiosDirs(unittest.TestCase): """LaunchBox computes where each emulator it manages keeps its BIOS.""" def _make(self, entries: list[tuple[str, str]]) -> Path: - root = Path(_tempdir(self)) / "LaunchBox" + root = scratch_dir(self) / "LaunchBox" (root / "Data").mkdir(parents=True) body = "".join( " \n" @@ -1042,7 +1030,7 @@ class TestLaunchboxBiosDirs(unittest.TestCase): def test_pcsx2_portable_absolute_bios(self): root = self._make([("PCSX2", "Emulators\\PCSX2\\pcsx2.exe")]) emu = root / "Emulators" / "PCSX2" - elsewhere = Path(_tempdir(self)) / "ps2bios" + elsewhere = scratch_dir(self) / "ps2bios" (emu / "portable.ini").write_text("") (emu / "inis").mkdir() (emu / "inis" / "PCSX2.ini").write_text(f"Bios = {elsewhere}\n") @@ -1064,7 +1052,7 @@ class TestLaunchboxBiosDirs(unittest.TestCase): def test_pcsx2_without_config_uses_documents(self): root = self._make([("PCSX2", "Emulators\\PCSX2\\pcsx2.exe")]) - userprofile = Path(_tempdir(self)) + userprofile = scratch_dir(self) with unittest.mock.patch.dict(os.environ, {"USERPROFILE": str(userprofile)}): self.assertEqual( install.launchbox_bios_dirs(root)["pcsx2"], @@ -1074,13 +1062,13 @@ class TestLaunchboxBiosDirs(unittest.TestCase): def test_xemu_defaults_to_bios_folder(self): root = self._make([("Xemu", "Emulators\\Xemu\\xemu.exe")]) emu = root / "Emulators" / "Xemu" - with unittest.mock.patch.dict(os.environ, {"APPDATA": str(Path(_tempdir(self)))}): + with unittest.mock.patch.dict(os.environ, {"APPDATA": str(scratch_dir(self))}): self.assertEqual(install.launchbox_bios_dirs(root)["xemu"], emu / "bios") def test_xemu_honours_configured_bootrom(self): root = self._make([("Xemu", "Emulators\\Xemu\\xemu.exe")]) emu = root / "Emulators" / "Xemu" - configured = Path(_tempdir(self)) / "xbox" + configured = scratch_dir(self) / "xbox" configured.mkdir() (configured / "mcpx_1.0.bin").write_text("x") (emu / "xemu.toml").write_text( @@ -1105,7 +1093,7 @@ class TestLaunchboxBiosDirs(unittest.TestCase): self.assertEqual(install.launchbox_bios_dirs(root), {}) def test_doctype_is_rejected(self): - root = Path(_tempdir(self)) / "LaunchBox" + root = scratch_dir(self) / "LaunchBox" (root / "Data").mkdir(parents=True) (root / "Data" / "Emulators.xml").write_text( "]>\n\n" @@ -1133,9 +1121,9 @@ class TestStandaloneCopiesExtraDirs(unittest.TestCase): } def test_pattern_entry_copies_into_extra_dir(self): - bios = Path(_tempdir(self)) + bios = scratch_dir(self) (bios / "ps2-0230a.bin").write_text("rom") - extra = Path(_tempdir(self)) / "bios" + extra = scratch_dir(self) / "bios" extra.mkdir() copied, _, _ = install.do_standalone_copies( self._manifest(), bios, "windows", {"pcsx2": extra} @@ -1144,10 +1132,10 @@ class TestStandaloneCopiesExtraDirs(unittest.TestCase): self.assertTrue((extra / "ps2-0230a.bin").exists()) def test_file_entry_keeps_its_subdirectory(self): - bios = Path(_tempdir(self)) + bios = scratch_dir(self) (bios / "GC" / "USA").mkdir(parents=True) (bios / "GC" / "USA" / "IPL.bin").write_text("ipl") - user = Path(_tempdir(self)) / "User" + user = scratch_dir(self) / "User" (user / "GC" / "USA").mkdir(parents=True) copied, _, _ = install.do_standalone_copies( self._manifest(), bios, "windows", {"dolphin": user} @@ -1156,7 +1144,7 @@ class TestStandaloneCopiesExtraDirs(unittest.TestCase): self.assertTrue((user / "GC" / "USA" / "IPL.bin").exists()) def test_no_extra_dirs_is_unchanged(self): - bios = Path(_tempdir(self)) + bios = scratch_dir(self) (bios / "ps2-0230a.bin").write_text("rom") self.assertEqual( install.do_standalone_copies(self._manifest(), bios, "windows"), (0, 0, 0) @@ -1171,9 +1159,9 @@ class StandaloneFolderClosedToThisUser(unittest.TestCase): after the install, and the run stopped with code 1.""" def setUp(self) -> None: - self.bios = Path(_tempdir(self)) + self.bios = scratch_dir(self) (self.bios / "IPL.bin").write_text("ipl") - self.app = Path(_tempdir(self)) / "org.dolphinemu.dolphinemu" + self.app = scratch_dir(self) / "org.dolphinemu.dolphinemu" (self.app / "files" / "GC" / "USA").mkdir(parents=True) self.app.chmod(0) self.addCleanup(self.app.chmod, 0o755) @@ -1207,9 +1195,9 @@ class StandaloneCopiesReadWhereThePackPutTheFile(unittest.TestCase): the registry's path, found nothing and copied nothing to Azahar.""" def _copy(self, entry: dict) -> tuple[Path, tuple[int, int, int]]: - bios = Path(_tempdir(self)) + bios = scratch_dir(self) (bios / "aes_keys.txt").write_text("keys") - sysdata = Path(_tempdir(self)) / "sysdata" + sysdata = scratch_dir(self) / "sysdata" sysdata.mkdir() manifest = {"standalone_copies": [ {**entry, "emulator": "azahar", "targets": {"linux": [str(sysdata)]}}, @@ -1458,7 +1446,7 @@ class DetectionFollowsTheRegistry(unittest.TestCase): ) def _home(self) -> Path: - home = Path(_tempdir(self)) + home = scratch_dir(self) patcher = unittest.mock.patch.dict(os.environ, {"HOME": str(home), "USERPROFILE": str(home)}) patcher.start() self.addCleanup(patcher.stop) @@ -1563,7 +1551,7 @@ class RetroArchIsFoundWhereWindowsInstallsPutIt(unittest.TestCase): return folder def test_program_files_win64(self): - program_files = Path(_tempdir(self)) + program_files = scratch_dir(self) self._env(program_files) found = self._exe(program_files / "RetroArch-Win64") self.assertIn(found, install._windows_retroarch_dirs()) @@ -1571,17 +1559,17 @@ class RetroArchIsFoundWhereWindowsInstallsPutIt(unittest.TestCase): def test_a_scoop_install(self): # `scoop install retroarch` puts it under ~/scoop/apps/retroarch/current, # which none of the searched folders covered. - program_files = Path(_tempdir(self)) + program_files = scratch_dir(self) self._env(program_files) - home = Path(_tempdir(self)) + home = scratch_dir(self) found = self._exe(home / "scoop" / "apps" / "retroarch" / "current") with unittest.mock.patch.dict(os.environ, {"USERPROFILE": str(home)}): os.environ.pop("SCOOP", None) self.assertIn(found, install._windows_retroarch_dirs()) def test_a_steam_library_on_another_drive(self): - program_files = Path(_tempdir(self)) - library = Path(_tempdir(self)) + program_files = scratch_dir(self) + library = scratch_dir(self) steamapps = program_files / "Steam" / "steamapps" steamapps.mkdir(parents=True) (steamapps / "libraryfolders.vdf").write_text( @@ -1592,7 +1580,7 @@ class RetroArchIsFoundWhereWindowsInstallsPutIt(unittest.TestCase): self.assertIn(found, install._windows_retroarch_dirs()) def test_an_installed_es_de(self): - program_files = Path(_tempdir(self)) + program_files = scratch_dir(self) self._env(program_files) found = self._exe(program_files / "ES-DE" / "Emulators" / "RetroArch-Win64") self.assertIn(found, install._windows_retroarch_dirs()) @@ -1679,8 +1667,7 @@ class InstallerStaysOnPython38AndTheStdlib(unittest.TestCase): threading.Thread(target=httpd.serve_forever, daemon=True).start() self.addCleanup(httpd.server_close) self.addCleanup(httpd.shutdown) - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - home = Path(tempfile.mkdtemp(dir=str(REPO_ROOT / "tmp"))) + home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, home, True) env = { **os.environ, @@ -1927,7 +1914,7 @@ class TestLocalCheckHashing(unittest.TestCase): """A file is read once, not once per declared digest.""" def test_both_digests_come_from_one_read(self): - tmp = Path(_tempdir(self)) + tmp = scratch_dir(self) payload = b"BIOS PAYLOAD" (tmp / "boot.bin").write_bytes(payload) entry = { @@ -1952,7 +1939,7 @@ class TestLocalCheckHashing(unittest.TestCase): self.assertEqual(calls, [("sha1", "sha256")], "file must be read once") def test_a_wrong_digest_still_lands_in_mismatched(self): - tmp = Path(_tempdir(self)) + tmp = scratch_dir(self) (tmp / "boot.bin").write_bytes(b"BIOS PAYLOAD") entry = { "dest": "boot.bin", @@ -2026,10 +2013,10 @@ class TestStandaloneCopyTargetsAreUntrusted(unittest.TestCase): """A link at the name was skipped in silence and counted as "dir not found" while the folder existed: the emulator kept whatever the link pointed at. The link now gives way to the file.""" - bios = Path(_tempdir(self)) + bios = scratch_dir(self) (bios / "boot.bin").write_text("rom") - target = Path(_tempdir(self)) - outside = Path(_tempdir(self)) / "secret" + target = scratch_dir(self) + outside = scratch_dir(self) / "secret" outside.write_text("untouched") (target / "boot.bin").symlink_to(outside) @@ -2055,8 +2042,8 @@ class TestDestinationFollowsUserLinks(unittest.TestCase): """ def test_symlinked_directory_under_root_is_followed(self): - bios = Path(_tempdir(self)) - elsewhere = Path(_tempdir(self)) / "sys_modules" + bios = scratch_dir(self) + elsewhere = scratch_dir(self) / "sys_modules" elsewhere.mkdir() (bios / "shadps4").mkdir() (bios / "shadps4" / "sys_modules").symlink_to(elsewhere) @@ -2067,8 +2054,8 @@ class TestDestinationFollowsUserLinks(unittest.TestCase): self.assertEqual(dest.resolve().parent, elsewhere.resolve()) def test_check_local_survives_a_linked_directory(self): - bios = Path(_tempdir(self)) - elsewhere = Path(_tempdir(self)) / "sys_modules" + bios = scratch_dir(self) + elsewhere = scratch_dir(self) / "sys_modules" elsewhere.mkdir() (bios / "shadps4").mkdir() (bios / "shadps4" / "sys_modules").symlink_to(elsewhere) @@ -2080,7 +2067,7 @@ class TestDestinationFollowsUserLinks(unittest.TestCase): self.assertEqual((up_to_date, mismatched), ([], [])) def test_climbing_is_still_refused(self): - bios = Path(_tempdir(self)) + bios = scratch_dir(self) with self.assertRaises(ValueError): install._destination_path(bios, "../outside.bin") with self.assertRaises(ValueError): @@ -2129,7 +2116,7 @@ class TestManualPlatformPrompt(unittest.TestCase): drives and home, and failed with a card in the reader.""" def setUp(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) for patcher in (unittest.mock.patch.object(install, "_mounted_cards", return_value=[]), unittest.mock.patch.object(install, "_mount_points", return_value=frozenset()), @@ -2179,7 +2166,7 @@ class TestManualPlatformPrompt(unittest.TestCase): def test_lakka_on_a_computer_asks_for_its_card(self): """/storage/system, a folder only the Lakka machine has, was taken on a computer: Lakka keeps its BIOS on its card's STORAGE part.""" - card = Path(_tempdir(self)) + card = scratch_dir(self) (card / ".config" / "retroarch").mkdir(parents=True) (card / ".config" / "retroarch" / "retroarch.cfg").write_text( 'system_directory = "/tmp/system"\n') @@ -2216,7 +2203,7 @@ class TestManualPlatformPrompt(unittest.TestCase): def test_quotes_around_a_typed_folder_are_dropped(self): """Explorer's "Copy as path" quotes the folder: the files went into a folder named `"` under the current directory, and the run said Done.""" - root = Path(_tempdir(self)) + root = scratch_dir(self) for typed in (f'"{root}/My Card/bios"', f"'{root}/My Card/bios'", f' "{root}/My Card/bios" ', # A half-selected copy: line mode kept the quote. @@ -2243,7 +2230,7 @@ class TestManualPlatformPrompt(unittest.TestCase): def test_a_default_folder_not_there_is_not_found(self): """With nothing installed, Enter printed "Found RetroArch at" a folder that did not exist.""" - root = Path(_tempdir(self)) + root = scratch_dir(self) answers = iter(["1", ""]) out = io.StringIO() with unittest.mock.patch.object(install, "_default_dest", @@ -2274,7 +2261,7 @@ class TestSteamRetroarchDetection(unittest.TestCase): """The Steam build is a portable install under the default library.""" def test_steam_library_is_found_on_windows(self): - program_files = Path(_tempdir(self)) + program_files = scratch_dir(self) ra_dir = program_files / "Steam" / "steamapps" / "common" / "RetroArch" ra_dir.mkdir(parents=True) (ra_dir / "retroarch.cfg").write_text('system_directory = ":\\system"\n') @@ -2288,7 +2275,7 @@ class TestLaunchboxDetectionPowershell(unittest.TestCase): """install.ps1 must resolve LaunchBox's portable RetroArch on its own.""" def _run(self, entries: str, seed=None, manifest: dict | None = None): - userprofile = Path(_tempdir(self)) + userprofile = scratch_dir(self) ra_dir = userprofile / "LaunchBox" / "Emulators" / "RetroArch" ra_dir.mkdir(parents=True) data = userprofile / "LaunchBox" / "Data" @@ -2301,7 +2288,7 @@ class TestLaunchboxDetectionPowershell(unittest.TestCase): ) if seed is not None: seed(userprofile) - serve_root = Path(_tempdir(self)) + serve_root = scratch_dir(self) (serve_root / "install").mkdir() payload = dict(manifest if manifest is not None else {"files": []}) payload.setdefault("manifest_version", 2) @@ -2317,7 +2304,7 @@ class TestLaunchboxDetectionPowershell(unittest.TestCase): env = dict(os.environ) env.update( USERPROFILE=str(userprofile), - APPDATA=str(_tempdir(self)), + APPDATA=str(str(scratch_dir(self))), RETROBIOS_BASE_URL=f"http://127.0.0.1:{httpd.server_address[1]}", # A LaunchBox layout is a Windows layout: the runner is Linux. RETROBIOS_OS="wsl", @@ -2439,7 +2426,7 @@ class TestDetectFrontends(unittest.TestCase): """Frontends have no BIOS directory of their own but hint at the setup.""" def test_esde_from_home_directory(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) (home / "ES-DE").mkdir() old = os.environ.pop("ESDE_APPDATA_DIR", None) try: @@ -2449,8 +2436,8 @@ class TestDetectFrontends(unittest.TestCase): os.environ["ESDE_APPDATA_DIR"] = old def test_esde_from_env_dir(self): - home = Path(_tempdir(self)) - appdata = Path(_tempdir(self)) + home = scratch_dir(self) + appdata = scratch_dir(self) os.environ["ESDE_APPDATA_DIR"] = str(appdata) try: self.assertIn("esde", install.detect_frontends("linux", home=home)) @@ -2458,7 +2445,7 @@ class TestDetectFrontends(unittest.TestCase): del os.environ["ESDE_APPDATA_DIR"] def test_nothing_detected(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) old = os.environ.pop("ESDE_APPDATA_DIR", None) try: self.assertEqual(install.detect_frontends("linux", home=home), []) @@ -2527,7 +2514,7 @@ class TestAvailablePlatforms(unittest.TestCase): files with two syntaxes, and the failing test named no command.""" from installer_build import pins - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) for name in ("install.py", "install.sh", "install.ps1"): shutil.copy2(REPO_ROOT / name, root / name) @@ -2565,9 +2552,7 @@ class TestAvailablePlatforms(unittest.TestCase): pins.pinned_sha256("install.sh", root) def test_shell_one_liner_downloads_verifies_and_forwards_arguments(self): - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) # A piped script must not trust a same-named file in the caller's # working directory. Only a real local install.sh may use its peer. @@ -2620,9 +2605,7 @@ class TestAvailablePlatforms(unittest.TestCase): """BusyBox wget, the only one in the RomM image, refuses --https-only: with no curl the one-liner always failed and blamed the network.""" - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) fake_bin = root / "bin" fake_bin.mkdir() @@ -2662,9 +2645,7 @@ class TestAvailablePlatforms(unittest.TestCase): def test_ctrl_c_during_the_download_ends_with_130(self): """Ctrl+C while install.py downloaded: the trap cleaned up and the script went on to blame the network, with code 1.""" - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) fake_bin = root / "bin" fake_bin.mkdir() @@ -2708,7 +2689,7 @@ class TestAvailablePlatforms(unittest.TestCase): """Buster keeps python3 at 3.7: the user installs python3.8 as the advice says, and the bootstrap, trying python3 and python alone, gave the same advice again.""" - root = Path(_tempdir(self)) + root = scratch_dir(self) shutil.copy(REPO_ROOT / "install.sh", root / "install.sh") (root / "install.py").write_text("import sys\nprint('ran', sys.version_info >= (3, 8))\n") fake_bin = root / "bin" @@ -2735,9 +2716,7 @@ class TestAvailablePlatforms(unittest.TestCase): def test_a_failed_download_says_so_in_one_message(self): """Offline, the one-liner printed curl's progress table and "curl: (6) ...", then exited 6, a code the table does not list.""" - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) fake_bin = root / "bin" fake_bin.mkdir() @@ -2771,9 +2750,7 @@ class TestAvailablePlatforms(unittest.TestCase): def test_piped_one_liner_hands_the_terminal_to_the_installer(self): """curl | sh gives the installer the script as stdin, so isatty() was false and every question it asks was skipped on Linux and Mac.""" - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) probe = root / "probe.py" probe.write_text( @@ -2953,7 +2930,7 @@ class RetroArchWhereItReallyLives(unittest.TestCase): Application Support/RetroArch/config, the system folder in Documents.""" def _exe_dir(self) -> tuple[Path, dict]: - program_files = Path(_tempdir(self)) + program_files = scratch_dir(self) exe_dir = program_files / "RetroArch" exe_dir.mkdir() (exe_dir / "retroarch.exe").write_bytes(b"MZ") @@ -2967,7 +2944,7 @@ class RetroArchWhereItReallyLives(unittest.TestCase): def test_windows_appdata_config_at_default_names_the_exe_folder(self): exe_dir, env = self._exe_dir() - appdata = Path(_tempdir(self)) + appdata = scratch_dir(self) (appdata / "RetroArch").mkdir() (appdata / "RetroArch" / "retroarch.cfg").write_text('system_directory = "default"\n') env["APPDATA"] = str(appdata) @@ -2983,7 +2960,7 @@ class RetroArchWhereItReallyLives(unittest.TestCase): self.assertIn(("retroarch", Path("D:\\bios")), found) def test_macos_config_folder_and_documents_default(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) support = home / "Library" / "Application Support" / "RetroArch" (support / "config").mkdir(parents=True) (support / "config" / "retroarch.cfg").write_text('system_directory = "default"\n') @@ -3003,8 +2980,8 @@ class LinuxRetroArchFollowsXdgConfigHome(unittest.TestCase): with its own XDG layout detected nothing.""" def _env(self) -> tuple[Path, Path]: - home = Path(_tempdir(self)) - xdg = Path(_tempdir(self)) + home = scratch_dir(self) + xdg = scratch_dir(self) patcher = unittest.mock.patch.dict(os.environ, {"HOME": str(home)}, clear=True) patcher.start() self.addCleanup(patcher.stop) @@ -3047,7 +3024,7 @@ class NoPythonNamesThisSystemsCommand(unittest.TestCase): macOS has no apt.""" def _run(self, extra_env: dict, uname: str = "Linux") -> subprocess.CompletedProcess: - root = Path(_tempdir(self)) + root = scratch_dir(self) fake_bin = root / "bin" fake_bin.mkdir() for tool in ("sed", "tr", "dirname", "cat"): @@ -3083,7 +3060,7 @@ class ABootstrapPythonCanDoHttps(unittest.TestCase): was chosen over a full python, and every download then failed.""" def _bin(self) -> tuple[Path, Path]: - root = Path(_tempdir(self)) + root = scratch_dir(self) fake_bin = root / "bin" fake_bin.mkdir() for tool in ("sed", "tr", "dirname", "cat", "awk", "uname"): @@ -3142,7 +3119,7 @@ class WindowsWithoutPythonIsOfferedWinget(unittest.TestCase): and 11, could do it from the bootstrap.""" def _folder(self) -> tuple[Path, Path]: - folder = Path(_tempdir(self)) + folder = scratch_dir(self) shutil.copy(REPO_ROOT / "install.ps1", folder / "install.ps1") (folder / "install.py").write_text("print('installer ran')\n") fake_bin = folder / "bin" @@ -3187,7 +3164,7 @@ class TermuxStorageIsSetUpByTheBootstrap(unittest.TestCase): start the whole run over: the bootstrap runs it and waits for ~/storage.""" def _run(self, storage_exists: bool) -> tuple[subprocess.CompletedProcess, Path]: - root = Path(_tempdir(self)) + root = scratch_dir(self) shutil.copy(REPO_ROOT / "install.sh", root / "install.sh") (root / "install.py").write_text("print('installer ran')\n") home = root / "home" @@ -3233,7 +3210,7 @@ class APyLauncherWithoutARuntimeIsPassed(unittest.TestCase): offered a second install or gave up.""" def test_python_on_path_runs_the_installer(self): - folder = Path(_tempdir(self)) + folder = scratch_dir(self) shutil.copy(REPO_ROOT / "install.ps1", folder / "install.ps1") (folder / "install.py").write_text("print('installer ran')\n") fake_bin = folder / "bin" @@ -3255,7 +3232,7 @@ class APowerShellDownloadThatNeverAnswersEnds(unittest.TestCase): connection and never answers, the window waited forever with no line.""" def test_a_silent_server_ends_on_the_network_advice(self): - folder = Path(_tempdir(self)) + folder = scratch_dir(self) shutil.copy(REPO_ROOT / "install.ps1", folder / "install.ps1") with socket.socket() as listener: listener.bind(("127.0.0.1", 0)) @@ -3278,7 +3255,7 @@ class ThePowerShellWrapperPassesTheStatusOn(unittest.TestCase): @unittest.skipUnless(shutil.which("pwsh"), "needs PowerShell") def test_the_installer_code_comes_back_unchanged(self): - folder = Path(_tempdir(self)) + folder = scratch_dir(self) shutil.copy(REPO_ROOT / "install.ps1", folder / "install.ps1") for code in (0, 1, 2, 130): with self.subTest(code=code): @@ -3299,7 +3276,7 @@ class ThePowerShellWrapperPassesEveryArgument(unittest.TestCase): @unittest.skipUnless(shutil.which("pwsh"), "needs PowerShell") def test_short_flags_reach_the_installer(self): - folder = Path(_tempdir(self)) + folder = scratch_dir(self) shutil.copy(REPO_ROOT / "install.ps1", folder / "install.ps1") (folder / "install.py").write_text( "import json, sys\nprint(json.dumps(sys.argv[1:]))\n" @@ -3330,8 +3307,7 @@ class AnUnwritableFolderIsCodeTwo(unittest.TestCase): threading.Thread(target=httpd.serve_forever, daemon=True).start() self.addCleanup(httpd.server_close) self.addCleanup(httpd.shutdown) - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - home = Path(tempfile.mkdtemp(dir=str(REPO_ROOT / "tmp"))) + home = Path(tempfile.mkdtemp()) locked = home / "locked" locked.mkdir() locked.chmod(0o555) @@ -3404,7 +3380,7 @@ class CaseVariants(unittest.TestCase): } def test_a_kept_case_directory_is_detected(self): - directory = Path(_tempdir(self)) / "not" / "yet" + directory = scratch_dir(self) / "not" / "yet" self.assertTrue(install.keeps_case(directory)) self.assertEqual(list(Path(directory.parents[1]).iterdir()), []) @@ -3456,7 +3432,7 @@ class AnUnreadableRetroDeckConfigIsSaid(unittest.TestCase): def test_the_fallback_is_announced(self): import contextlib - home = Path(_tempdir(self)) + home = scratch_dir(self) conf = home / ".var" / "app" / "net.retrodeck.retrodeck" / "config" / "retrodeck" conf.mkdir(parents=True) (conf / "retrodeck.json").write_text("{truncated") @@ -3476,7 +3452,7 @@ class RetroDeckFoldersMovedOneByOne(unittest.TestCase): files went to /bios, a folder RetroDECK no longer reads.""" def _detect(self, paths: dict) -> tuple[Path, list]: - home = Path(_tempdir(self)) + home = scratch_dir(self) conf = home / ".var/app/net.retrodeck.retrodeck/config/retrodeck" conf.mkdir(parents=True) (conf / "retrodeck.json").write_text(json.dumps({"paths": paths})) @@ -3491,7 +3467,7 @@ class RetroDeckFoldersMovedOneByOne(unittest.TestCase): return home, [found, dests, label] def test_a_moved_bios_folder_is_followed(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) sd = home / "sd" root, (found, dests, label) = self._detect({ "rd_home_path": "", "bios_path": str(sd / "bios"), "roms_path": str(sd / "roms"), @@ -3504,7 +3480,7 @@ class RetroDeckFoldersMovedOneByOne(unittest.TestCase): self.assertIn(f"bios/ at {sd / 'bios'}", label) def test_folders_in_place_change_nothing(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) rd_home = home / "rd" _root, (found, dests, label) = self._detect({ "rd_home_path": str(rd_home), "bios_path": str(rd_home / "bios"), @@ -3537,7 +3513,7 @@ class AndroidRetroArchFolderFollowsItsBuild(unittest.TestCase): SITE_CODE = 1745000000 def _run(self, make): - root = Path(_tempdir(self)) + root = scratch_dir(self) app_data, storage = root / "data", root / "storage" app_data.mkdir() storage.mkdir() @@ -3641,7 +3617,7 @@ class AndroidRetroArchFolderFollowsItsBuild(unittest.TestCase): def test_detection_prints_the_retroarch_line(self): err = io.StringIO() - root = Path(_tempdir(self)) + root = scratch_dir(self) (root / "data" / "com.retroarch").mkdir(parents=True) with unittest.mock.patch.object(install, "ANDROID_APP_DATA", root / "data"), \ unittest.mock.patch.dict(os.environ, {"EXTERNAL_STORAGE": str(root / "s")}), \ @@ -3656,7 +3632,7 @@ class AndroidEmulatorsOutOfReachAreSaid(unittest.TestCase): were skipped without a word.""" def _lines(self, make) -> list[str]: - root = Path(_tempdir(self)) + root = scratch_dir(self) app_data, storage = root / "data", root / "storage" app_data.mkdir() make(app_data, storage) @@ -3707,7 +3683,7 @@ class ACardPreparedOnAComputerGetsItsBoard(unittest.TestCase): only without --dest, which the full-screen interface always gives.""" def setUp(self): - self.root = Path(_tempdir(self)) + self.root = scratch_dir(self) self.boot = self.root / "BATOCERA" (self.boot / "boot").mkdir(parents=True) (self.boot / "boot" / "batocera.board").write_text("bcm2711\n") @@ -3824,7 +3800,7 @@ class APlatformWithoutTargetsSaysSoOffline(unittest.TestCase): self.assertEqual(install.TARGET_PLATFORMS, published) def test_offline_says_there_are_no_targets(self): - dest = Path(_tempdir(self)) + dest = scratch_dir(self) for extra in ([], ["--manifest", str(REPO_ROOT / "install" / "misterfpga.json")]): with self.subTest(manifest=bool(extra)): proc = subprocess.run( @@ -3843,7 +3819,7 @@ class TheBoardTheSystemNamesIsTheTarget(unittest.TestCase): every board's files (8.6 GiB where bcm2711 needs 5.5).""" def test_each_source_is_read(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) arch = root / "batocera.arch" arch.write_text("bcm2711") with unittest.mock.patch.dict(install._BOARD_SOURCES, {"batocera": ("file", str(arch))}): @@ -3856,7 +3832,7 @@ class TheBoardTheSystemNamesIsTheTarget(unittest.TestCase): def test_retropie_names_its_pi_as_get_platform_does(self): """A RetroPie Pi 4 installed every target's files, 8.4 GiB where rpi4 needs 4.0: nothing read the Pi model.""" - root = Path(_tempdir(self)) + root = scratch_dir(self) (root / "proc" / "device-tree").mkdir(parents=True) cpuinfo = root / "proc" / "cpuinfo" tree = root / "proc" / "device-tree" / "compatible" @@ -4015,12 +3991,12 @@ class BizHawkIsFoundWhereItReads(unittest.TestCase): forced --platform bizhawk wrote where EmuHawk never reads.""" def test_the_data_home_variable(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) with unittest.mock.patch.dict(os.environ, {"BIZHAWK_DATA_HOME": str(home)}): self.assertEqual(install._bizhawk_unix_firmware(), home / "Firmware") def test_the_nix_data_home(self): - xdg = Path(_tempdir(self)) + xdg = scratch_dir(self) (xdg / "emuhawk-monort-2.11.1").mkdir() env = {"XDG_DATA_HOME": str(xdg), "BIZHAWK_DATA_HOME": ""} with unittest.mock.patch.dict(os.environ, env): @@ -4039,7 +4015,7 @@ class RetroArchUwpIsFound(unittest.TestCase): package's LocalState, but no rule looked under %LOCALAPPDATA%\\Packages.""" def _state(self) -> Path: - local = Path(_tempdir(self)) + local = scratch_dir(self) state = local / "Packages" / f"{install.RETROARCH_UWP_ID}_abc123" / "LocalState" state.mkdir(parents=True) patcher = unittest.mock.patch.dict(os.environ, {"LOCALAPPDATA": str(local)}) @@ -4057,7 +4033,7 @@ class RetroArchUwpIsFound(unittest.TestCase): self.assertEqual(install._retroarch_uwp_system_dir(), state / "bios") def test_nothing_installed(self): - with unittest.mock.patch.dict(os.environ, {"LOCALAPPDATA": _tempdir(self)}): + with unittest.mock.patch.dict(os.environ, {"LOCALAPPDATA": str(scratch_dir(self))}): self.assertIsNone(install._retroarch_uwp_system_dir()) @@ -4161,7 +4137,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): def test_the_archive_is_drawn_and_counted(self): """82 MB of archives came with no progress line, and the run ended on "310.5 KB downloaded", the BIOS files alone.""" - work = Path(_tempdir(self)) + work = scratch_dir(self) body = self._zip(work).read_bytes() attempts: list[int] = [] @@ -4202,7 +4178,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): """A data archive cut at 90% was deleted and fetched again from zero, on the retry and on the next run, while the run said that nothing was lost.""" - work = Path(_tempdir(self)) + work = scratch_dir(self) body = self._zip(work).read_bytes() keep = work / ".dolphin-sys.archive.part" requests: list[dict] = [] @@ -4251,7 +4227,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): self.assertEqual(requests[-1]["If-range"], '"v1"') def test_a_changed_archive_is_fetched_whole(self): - work = Path(_tempdir(self)) + work = scratch_dir(self) body = self._zip(work).read_bytes() keep = work / ".dolphin-sys.archive.part" keep.write_bytes(b"older revision") @@ -4274,7 +4250,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): self.assertEqual(path.read_bytes(), body) def test_a_tree_read_whole_leaves_no_archive(self): - work = Path(_tempdir(self)) + work = scratch_dir(self) archive = self._zip(work) bios = work / "system" bios.mkdir() @@ -4292,7 +4268,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): """Two runs into one BIOS folder shared .dolphin-sys.archive.part: the one that finished first deleted the archive the other was still writing, and the other truncated the one being read.""" - work = Path(_tempdir(self)) + work = scratch_dir(self) archive = self._zip(work) bios = work / "system" root = bios / "dolphin-emu" @@ -4317,7 +4293,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): self.assertTrue((root / ".dolphin-sys.archive.lock").exists()) def test_a_lone_run_keeps_its_archive_beside_the_tree(self): - work = Path(_tempdir(self)) + work = scratch_dir(self) archive = self._zip(work) bios = work / "system" kept: list = [] @@ -4385,7 +4361,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): self.assertEqual(install.data_fetch_bytes(entry, needed), 7) def test_verified_members_land_the_rest_are_said(self): - work = Path(_tempdir(self)) + work = scratch_dir(self) archive = self._zip(work) bios = work / "system" bios.mkdir() @@ -4416,7 +4392,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): """The buildbot rebuilt PPSSPP.zip and 49 of its 169 files were refused on every install: a nightly source holds no other bytes. RetroArch's own downloader writes what the buildbot serves.""" - work = Path(_tempdir(self)) + work = scratch_dir(self) bios = work / "system" bios.mkdir() entry = {**self._entry(), "rolling": True} @@ -4434,7 +4410,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): def test_a_rolling_file_an_earlier_run_wrote_is_in_place(self): """Its bytes are not the list's, they are what the source served and the record names: the next run neither fetches nor rewrites it.""" - work = Path(_tempdir(self)) + work = scratch_dir(self) bios = work / "system" bios.mkdir() entry = {**self._entry(), "rolling": True} @@ -4454,7 +4430,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): """No hash to hold a followed member to: its ZIP CRC-32 still is.""" import zipfile - work = Path(_tempdir(self)) + work = scratch_dir(self) archive = self._zip(work) body = bytearray(archive.read_bytes()) at = body.index(b"new bytes upstream") @@ -4472,7 +4448,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): def test_a_pack_rebuilds_a_rolling_tree_as_listed(self): """From a pack, the pack's copy is the tree: nothing newer exists.""" - work = Path(_tempdir(self)) + work = scratch_dir(self) bios = work / "system" bios.mkdir() @@ -4488,7 +4464,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): def test_a_rolling_member_past_its_cap_is_not_written(self): """A followed member is read to the size its archive declares: a source serving gigabytes where the list has 3 bytes fills no drive.""" - work = Path(_tempdir(self)) + work = scratch_dir(self) entry = {**self._entry(), "rolling": True} served: list[int] = [] @@ -4526,7 +4502,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): buffer[:] = b"x" * len(buffer) return len(buffer) - work = Path(_tempdir(self)) + work = scratch_dir(self) entry = self._entry() entry["files"] = {"Sys/GC/font.bin": {"sha1": "1" * 40, "size": 4}} @@ -4546,7 +4522,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): traceback, and a failed write left its .part beside the tree.""" import zlib - work = Path(_tempdir(self)) + work = scratch_dir(self) entry = self._entry() entry["files"] = {"Sys/GC/font.bin": {"sha1": "1" * 40, "size": 4}} for error in (zlib.error("invalid stored block lengths"), EOFError(), @@ -4572,7 +4548,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): self.assertEqual([p.name for p in work.rglob("*.part")], []) def test_offline_keeps_its_reason(self): - work = Path(_tempdir(self)) + work = scratch_dir(self) with unittest.mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}): counts = install.install_data_directory(self._entry(), work) self.assertIsInstance(counts["error"], install.OfflineReason) @@ -4581,7 +4557,7 @@ class DataDirectoriesAreInstalled(unittest.TestCase): import io as _io import tarfile - work = Path(_tempdir(self)) + work = scratch_dir(self) archive = work / "src.tar.gz" with tarfile.open(archive, "w:gz") as tf: data = b"index" @@ -4645,7 +4621,7 @@ class AChunkedCutIsADownloadFailure(unittest.TestCase): with unittest.mock.patch.object(install.urllib.request, "urlopen", lambda *a, **k: Cut()), \ unittest.mock.patch.object(install, "_retry_delay", return_value=0): - dest, ok, reason = install._download_one(entry, Path(_tempdir(self))) + dest, ok, reason = install._download_one(entry, scratch_dir(self)) self.assertFalse(ok) self.assertEqual(reason, "the connection was cut") self.assertIsInstance(reason, install.NetworkReason) @@ -4730,8 +4706,7 @@ class ACheckNamesWhatTheCollectionLacks(unittest.TestCase): threading.Thread(target=httpd.serve_forever, daemon=True).start() self.addCleanup(httpd.server_close) self.addCleanup(httpd.shutdown) - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - home = Path(tempfile.mkdtemp(dir=str(REPO_ROOT / "tmp"))) + home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, home, True) env = { **os.environ, "HOME": str(home), "RETROBIOS_OS": "linux", @@ -4760,9 +4735,9 @@ class ARefusedStandaloneCopyIsNamed(unittest.TestCase): if os.name == "nt" or os.geteuid() == 0: self.skipTest("a read-only folder needs POSIX modes and a non-root user") - bios = Path(_tempdir(self)) + bios = scratch_dir(self) (bios / "scph5501.bin").write_bytes(b"x") - target = Path(_tempdir(self)) / "pcsx2-bios" + target = scratch_dir(self) / "pcsx2-bios" target.mkdir() target.chmod(0o500) self.addCleanup(target.chmod, 0o700) @@ -4794,7 +4769,7 @@ class AFullDriveIsSaidAsOne(unittest.TestCase): on the source, and the run ended on `Run the same command again`.""" def test_the_tree_reports_the_drive(self): - work = Path(_tempdir(self)) + work = scratch_dir(self) entry = {"ref": "fbneo-cheats", "dest": "fbneo/cheats", "type": "zip", "url": "https://example.invalid/c.zip", "systems": ["arcade"], "files": {"1941r1.ini": {"sha1": "1" * 40, "size": 4}}} @@ -4821,7 +4796,7 @@ class AFullDriveIsSaidAsOne(unittest.TestCase): self.assertEqual(counts["error"], install.DRIVE_FULL) def test_the_end_names_space_not_a_retry(self): - bios = Path(_tempdir(self)) + bios = scratch_dir(self) out = io.StringIO() with contextlib.redirect_stdout(out), self.assertRaises(SystemExit) as ended: install._report_outcome([bios], 7, 0, 1, 0, False, @@ -4832,7 +4807,7 @@ class AFullDriveIsSaidAsOne(unittest.TestCase): self.assertNotIn("retry only those", text) def test_a_bios_file_on_a_full_drive_is_not_retried(self): - bios = Path(_tempdir(self)) + bios = scratch_dir(self) attempts: list = [] def urlopen(*_args, **_kwargs): @@ -4933,7 +4908,7 @@ class WindowsSeenFromWsl(unittest.TestCase): ~/bios inside the distribution, where RetroBat reads nothing.""" def setUp(self): - self.root = Path(_tempdir(self)) + self.root = scratch_dir(self) patcher = unittest.mock.patch.dict(install._WSL, {"active": True, "root": str(self.root)}) patcher.start() self.addCleanup(patcher.stop) @@ -4957,7 +4932,7 @@ class WindowsSeenFromWsl(unittest.TestCase): exe_dir = self.root / "c" / "RetroArch-Win64" exe_dir.mkdir(parents=True) (exe_dir / "retroarch.exe").write_bytes(b"MZ") - home = Path(_tempdir(self)) + home = scratch_dir(self) cleared = {name: "" for name in (*install._WINDOWS_VARIABLES, "SCOOP", "SCOOP_GLOBAL", "ProgramData")} with unittest.mock.patch.dict(os.environ, {**cleared, "HOME": str(home)}), \ @@ -4997,7 +4972,7 @@ class WindowsSeenFromWsl(unittest.TestCase): common.mkdir(parents=True) (common / "retroarch.exe").write_bytes(b"MZ") (common / "retroarch.cfg").write_text('system_directory = "default"\n') - home = Path(_tempdir(self)) + home = scratch_dir(self) cleared = {name: "" for name in (*install._WINDOWS_VARIABLES, "SCOOP", "SCOOP_GLOBAL", "ProgramData")} asked: list = [] @@ -5025,7 +5000,7 @@ class WindowsSeenFromWsl(unittest.TestCase): raise subprocess.TimeoutExpired(argv, kwargs.get("timeout", 10)) cleared = {name: "" for name in install._WINDOWS_VARIABLES} - home = Path(_tempdir(self)) + home = scratch_dir(self) err = io.StringIO() with unittest.mock.patch.dict(os.environ, {**cleared, "HOME": str(home)}), \ unittest.mock.patch.object(install.subprocess, "run", slow), \ @@ -5052,9 +5027,9 @@ class StandaloneCopiesUnderTheirOwnName(unittest.TestCase): emulator reads.""" def test_the_copy_takes_the_emulator_name(self): - bios = Path(_tempdir(self)) + bios = scratch_dir(self) (bios / "xbox_eeprom.bin").write_bytes(b"eeprom") - folder = Path(_tempdir(self)) + folder = scratch_dir(self) manifest = {"standalone_copies": [ {"file": "xbox_eeprom.bin", "as": "eeprom.bin", "targets": {"linux": [str(folder)]}}]} install._validate_manifest({**self._published(), **manifest}, "emudeck") @@ -5077,7 +5052,7 @@ class StandaloneCopiesUnderTheirOwnName(unittest.TestCase): {"file": "x.bin", "as": name, "targets": {}}]}, "emudeck") def test_cemu_alone_is_found_from_the_published_list(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) (home / ".local" / "share" / "Cemu").mkdir(parents=True) manifest = json.loads((REPO_ROOT / "install" / "retroarch.json").read_text()) with unittest.mock.patch.dict(os.environ, {"HOME": str(home)}): @@ -5159,19 +5134,19 @@ class RetroArchAppImageIsPortable(unittest.TestCase): return base def test_the_unpacked_archive_is_found(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) base = self._unpack(home) self.assertIn(("retroarch", base / "system"), self._detect(home)) def test_its_config_is_read_with_its_own_home(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) base = self._unpack(home) (base / "retroarch.cfg").write_text('system_directory = "~/bios"\n') portable = base.parent.parent self.assertIn(("retroarch", portable / "bios"), self._detect(home)) def test_a_config_folder_beside_it_wins(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) base = self._unpack(home) config = base.parent.parent.with_name("RetroArch-Linux-x86_64.AppImage.config") (config / "retroarch").mkdir(parents=True) @@ -5180,7 +5155,7 @@ class RetroArchAppImageIsPortable(unittest.TestCase): self.assertNotIn(("retroarch", base / "system"), found) def test_a_folder_without_its_appimage_is_left(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) base = self._unpack(home) (base.parent.parent.with_name("RetroArch-Linux-x86_64.AppImage")).unlink() self.assertNotIn(("retroarch", base / "system"), self._detect(home)) @@ -5192,7 +5167,7 @@ class SteamRetroArchOnMacIsPortable(unittest.TestCase): the installer took ~/Documents/RetroArch/system.""" def test_the_steam_bundle_moves_the_base(self): - home = Path(_tempdir(self)) + home = scratch_dir(self) support = home / "Library" / "Application Support" with unittest.mock.patch.dict(os.environ, {"HOME": str(home)}), \ unittest.mock.patch.object(Path, "home", return_value=home): @@ -5244,8 +5219,7 @@ class TheInstallerSaysWhatItFound(unittest.TestCase): threading.Thread(target=httpd.serve_forever, daemon=True).start() self.addCleanup(httpd.server_close) self.addCleanup(httpd.shutdown) - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.home = Path(tempfile.mkdtemp(dir=str(REPO_ROOT / "tmp"))) + self.home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.home, True) self.env = { **os.environ, "HOME": str(self.home), "RETROBIOS_OS": "linux", @@ -5380,7 +5354,7 @@ class _LoopbackRun: threading.Thread(target=httpd.serve_forever, daemon=True).start() test.addCleanup(httpd.server_close) test.addCleanup(httpd.shutdown) - self.home = Path(_tempdir(test)) + self.home = scratch_dir(test) return { **os.environ, "HOME": str(self.home), "RETROBIOS_OS": "linux", "RETROBIOS_BASE_URL": f"http://127.0.0.1:{httpd.server_address[1]}", @@ -5443,7 +5417,7 @@ class AMissingPackNamesTheOptionAndThePacksBeside(unittest.TestCase): not the pack sitting next to the name typed.""" def test_the_pack_beside_is_named(self): - folder = Path(_tempdir(self)) + folder = scratch_dir(self) (folder / "RetroArch_BIOS_Pack.zip").write_bytes(b"") with self.assertRaises(ValueError) as raised: install.PackSource._resolve([folder / "RetroArch_BIOS_Pak.zip"]) @@ -5474,7 +5448,7 @@ class AnUnknownNameIsAnEvent(unittest.TestCase): env = {key: value for key, value in os.environ.items() if key != "RETROBIOS_BASE_URL"} env[install.OFFLINE_VARIABLE] = "1" - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as dest: + with tempfile.TemporaryDirectory() as dest: proc = subprocess.run( [sys.executable, str(REPO_ROOT / "install.py"), "--dest", dest, "--check", "--events", "--no-input", *argv], @@ -5666,7 +5640,7 @@ class HintsGiveTheUsersOwnCommandBack(unittest.TestCase): def test_a_listing_hint_keeps_the_listing(self): """--list-systems with nothing detected was answered with a full install command: the listing flag gone, a --dest added.""" - home = Path(_tempdir(self)) + home = scratch_dir(self) env = {**os.environ, "HOME": str(home), "RETROBIOS_OS": "linux", "RETROBIOS_BOOTSTRAP": ""} for flag in ("--list-systems", "--list-cores", "--list-emulators", "--list-targets"): @@ -5708,13 +5682,11 @@ class HintsGiveTheUsersOwnCommandBack(unittest.TestCase): with unittest.mock.patch.object(install.shutil, "disk_usage", return_value=SimpleNamespace(free=1)), \ contextlib.redirect_stderr(err), self.assertRaises(SystemExit): - install._check_free_space(Path(_tempdir(self)), 10, "batocera") + install._check_free_space(scratch_dir(self), 10, "batocera") self.assertIn("--platform batocera --dest ", err.getvalue()) def test_the_one_liner_tells_the_installer_how_it_was_started(self): - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) probe = root / "probe.py" probe.write_text("import os\nprint('bootstrap:', os.environ.get('RETROBIOS_BOOTSTRAP'))\n") @@ -5761,9 +5733,7 @@ class AnOverrideIsNamedWhenItIsTheCause(unittest.TestCase): self.assertIn("RETROBIOS_BASE_URL is set", text) def test_a_pinned_fingerprint_is_named(self): - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) fake_bin = root / "bin" fake_bin.mkdir() @@ -5824,7 +5794,7 @@ class AQuestionLeftWithCtrlDOrCtrlCIsAStop(unittest.TestCase): import pty import time - home = Path(_tempdir(self)) + home = scratch_dir(self) master, slave = pty.openpty() # Its output on the terminal too: piped, nothing is asked, and the # test skipped on every machine. @@ -6074,7 +6044,7 @@ class DestAloneFollowsWhatIsFoundHere(unittest.TestCase): def test_a_card_system_chosen_checks_the_folder(self): """The menu offered no card system, and one chosen now reads --dest as --platform does.""" - root = Path(_tempdir(self)) + root = scratch_dir(self) answers = iter(["Onion", "retroarch"]) out = io.StringIO() with unittest.mock.patch.object(install, "detect_platforms", return_value=[]), \ @@ -6157,7 +6127,7 @@ class ACompletePartialIsHandedOffOnWindows(unittest.TestCase): return install._download_one(dict(self.ENTRY), tmp) def test_the_other_runs_copy_is_left_whole(self): - tmp = Path(_tempdir(self)) + tmp = scratch_dir(self) (tmp / ".big.bin.part").write_bytes(self.PAYLOAD) seen: list[int] = [] self.assertEqual(self._run(tmp, seen), ("big.bin", True, "")) @@ -6168,7 +6138,7 @@ class ACompletePartialIsHandedOffOnWindows(unittest.TestCase): self.assertFalse((tmp / ".big.bin.part").exists()) def test_the_rename_waits_for_the_other_run_to_let_go(self): - tmp = Path(_tempdir(self)) + tmp = scratch_dir(self) source = tmp / "copy" source.write_bytes(b"x") real_replace = os.replace @@ -6187,7 +6157,7 @@ class ACompletePartialIsHandedOffOnWindows(unittest.TestCase): self.assertEqual((tmp / "dest").read_bytes(), b"x") def test_a_copy_the_other_run_placed_counts_once_verified(self): - tmp = Path(_tempdir(self)) + tmp = scratch_dir(self) dest = tmp / "dest" dest.write_bytes(self.PAYLOAD) expected = {"sha256": self.ENTRY["sha256"]} @@ -6319,7 +6289,7 @@ class ANetworkFailureNamesTheNetwork(unittest.TestCase): "sha256": "0" * 64} with unittest.mock.patch.object(install.urllib.request, "urlopen", urlopen), \ unittest.mock.patch.object(install, "_retry_delay", return_value=0): - _dest, ok, reason = install._download_one(entry, Path(_tempdir(self))) + _dest, ok, reason = install._download_one(entry, scratch_dir(self)) self.assertFalse(ok) return reason @@ -6425,7 +6395,7 @@ class RetroBatIsFoundWhereItSaysItIs(unittest.TestCase): self.assertEqual(set(install._REGISTRY_RULES), rules) def test_the_registry_folder_wins_over_the_default(self): - folder = Path(_tempdir(self)) + folder = scratch_dir(self) with unittest.mock.patch.object(install, "_read_registry", return_value=str(folder) + "\\"): found: list = [] @@ -6433,7 +6403,7 @@ class RetroBatIsFoundWhereItSaysItIs(unittest.TestCase): self.assertEqual(found, [("retrobat", folder / "bios")]) def test_a_folder_since_removed_is_passed_over(self): - gone = Path(_tempdir(self)) / "moved" + gone = scratch_dir(self) / "moved" with unittest.mock.patch.object(install, "_read_registry", return_value=str(gone)): found: list = [] install._detect_by_registry("windows", found) @@ -6461,7 +6431,7 @@ class EmuDeckWindowsIsFoundAsItsScriptsFindIt(unittest.TestCase): forced --platform emudeck wrote into %USERPROFILE%\\Emulation\\bios.""" def _env(self) -> tuple[Path, Path]: - root = Path(_tempdir(self)) + root = scratch_dir(self) appdata, profile = root / "appdata", root / "profile" patcher = unittest.mock.patch.dict( os.environ, {"APPDATA": str(appdata), "USERPROFILE": str(profile)}) @@ -6511,7 +6481,7 @@ class EmuDeckWindowsIsFoundAsItsScriptsFindIt(unittest.TestCase): def _device(test: unittest.TestCase, files: dict[str, str], release: str = "", home: str = "/root") -> Path: """A fake root holding these files, read by the embedded rules.""" - root = Path(_tempdir(test)) + root = scratch_dir(test) if release: files = {**files, "/etc/os-release": release} for name, text in files.items(): @@ -6837,7 +6807,7 @@ class BatoceraAndKnulliByWhatTheirBuildsWrite(unittest.TestCase): def test_a_knulli_board_narrows_to_its_target(self): """KNULLI publishes a core list per board since 2026-11-05, and an H700 handheld still took every board's files (9.3 GB for 4.5).""" - arch = Path(_tempdir(self)) / "knulli.arch" + arch = scratch_dir(self) / "knulli.arch" targets = json.loads((REPO_ROOT / "install" / "targets" / "knulli.json") .read_text(encoding="utf-8")) for written, board in (("h700", "h700"), ("rk3568", "rk3566"), ("unknown", None)): @@ -6851,7 +6821,7 @@ class BatoceraAndKnulliByWhatTheirBuildsWrite(unittest.TestCase): def test_a_batocera_zen3_board_narrows_to_its_target(self): """batocera.arch says x86-64-v3 on a zen3 image, which no target list names: the run installed the files of every board.""" - arch = Path(_tempdir(self)) / "batocera.arch" + arch = scratch_dir(self) / "batocera.arch" arch.write_text("x86-64-v3") with unittest.mock.patch.dict(install._BOARD_SOURCES, {"batocera": ("file", str(arch))}): @@ -6891,7 +6861,7 @@ class RomMFirmwareFollowsItsTemplate(unittest.TestCase): ) def _romm(self, config: str | None) -> Path: - base = Path(_tempdir(self)) + base = scratch_dir(self) library = base / "library" (library / "psx" / "roms").mkdir(parents=True) if config is not None: @@ -6937,7 +6907,7 @@ class RomMFirmwareFollowsItsTemplate(unittest.TestCase): err = io.StringIO() with unittest.mock.patch.object(install, "detect_os", return_value="linux"), \ unittest.mock.patch("sys.argv", [ - "install.py", "--platform", "batocera", "--dest", _tempdir(self), + "install.py", "--platform", "batocera", "--dest", str(scratch_dir(self)), "--romm-firmware", "{platform}/bios", "--no-input"]), \ contextlib.redirect_stdout(io.StringIO()), \ contextlib.redirect_stderr(err), self.assertRaises(SystemExit) as caught: @@ -6981,7 +6951,7 @@ class _SyntheticTree: } def serve_tree(self, test: unittest.TestCase) -> dict: - root = Path(_tempdir(test)) + root = scratch_dir(test) files = [] for path, data in self.FILES.items(): (root / path).parent.mkdir(parents=True, exist_ok=True) @@ -7012,7 +6982,7 @@ class _SyntheticTree: threading.Thread(target=httpd.serve_forever, daemon=True).start() test.addCleanup(httpd.server_close) test.addCleanup(httpd.shutdown) - self.home = Path(_tempdir(test)) + self.home = scratch_dir(test) self.bios = self.home / "bios" self.bios.mkdir() (self.bios / "a.bin").write_bytes(self.FILES["bios/A/a.bin"]) @@ -7263,7 +7233,7 @@ class TheEventSchemaFileIsEventKeys(unittest.TestCase): def test_the_check_command_fails_on_a_stale_file(self): import generate_event_schema as generator - scratch = Path(_tempdir(self)) / "events.schema.json" + scratch = scratch_dir(self) / "events.schema.json" scratch.write_text("{}\n", encoding="utf-8") with contextlib.redirect_stdout(io.StringIO()), \ contextlib.redirect_stderr(io.StringIO()): @@ -7285,7 +7255,7 @@ class TheInstallerPageIsWrittenFromTheCode(unittest.TestCase): self.generator = generate_installer_doc self.doc = installerdoc - self.scratch = Path(_tempdir(self)) / "installer.md" + self.scratch = scratch_dir(self) / "installer.md" self.scratch.write_text(self.PAGE.read_text(encoding="utf-8"), encoding="utf-8") def run_generator(self, *argv: str) -> tuple[int, str]: @@ -7388,7 +7358,7 @@ class AStrippedPythonIsNamed(unittest.TestCase): self.assertIn(f"built without its {hidden} module", proc.stderr) def test_no_ssl_is_said_once_not_retried(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as dest: + with tempfile.TemporaryDirectory() as dest: proc = self._run("ssl", "--platform", "retroarch", "--dest", dest, "--check", "--no-input") self.assertEqual(proc.returncode, 1) @@ -7454,7 +7424,7 @@ class NetworkFailuresInPlainWords(unittest.TestCase): self.assertIn("SSL_CERT_FILE", text) def test_a_certificate_list_is_looked_for_where_openssl_and_systems_keep_it(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) bundle = root / "cert.pem" paths = SimpleNamespace(cafile=str(root / "none.pem"), capath=str(root / "none"), openssl_cafile=str(root / "no.pem"), @@ -7470,10 +7440,10 @@ class NetworkFailuresInPlainWords(unittest.TestCase): def test_a_file_list_out_of_reach_by_name_says_so(self): env = {**os.environ, "RETROBIOS_BASE_URL": "https://retrobios-nohost.invalid", - "HOME": _tempdir(self)} + "HOME": str(scratch_dir(self))} proc = subprocess.run( [sys.executable, str(REPO_ROOT / "install.py"), "--platform", "retroarch", - "--dest", _tempdir(self), "--check"], + "--dest", str(scratch_dir(self)), "--check"], env=env, capture_output=True, text=True, timeout=120, check=False, stdin=subprocess.DEVNULL, ) @@ -7494,7 +7464,7 @@ class AFileYouHadIsKept(unittest.TestCase): def setUp(self): install.KEPT.reset() self.addCleanup(install.KEPT.reset) - self.home = Path(_tempdir(self)) + self.home = scratch_dir(self) self.bios = self.home / "system" self.bios.mkdir() @@ -7837,7 +7807,7 @@ class TheListVersionIsComparedWithTheSystems(unittest.TestCase): self.assertIsNone(self.note("recalbox", "10.1.1")) def test_retrobat_reads_the_folder_beside_its_bios_folder(self): - root = Path(_tempdir(self)) + root = scratch_dir(self) version = root / "system" / "version.info" version.parent.mkdir() version.write_text("8.3.1.1-stable-win64") @@ -7884,7 +7854,7 @@ class TheListVersionIsComparedWithTheSystems(unittest.TestCase): "size": 4}]} scope.annotate_pack_systems(pack_list, scope.pack_systems(install_list)) self.assertEqual(pack_list["list_version"], "43.1") - pack = Path(_tempdir(self)) / "Batocera_43.1_BIOS_Pack.zip" + pack = scratch_dir(self) / "Batocera_43.1_BIOS_Pack.zip" with zipfile.ZipFile(pack, "w") as archive: archive.writestr("manifest.json", json.dumps(pack_list)) archive.writestr("a.bin", data) @@ -7913,7 +7883,7 @@ class TheListVersionIsSaidBeforeAndAfter(unittest.TestCase): DATA = b"retrobat bios" * 8 def setUp(self): - self.root = Path(_tempdir(self)) + self.root = scratch_dir(self) (self.root / "system").mkdir() (self.root / "system" / "version.info").write_text("8.2.0-stable-win64") self.bios = self.root / "bios" diff --git a/tests/test_install_app.py b/tests/test_install_app.py index 02509a143..5e87e7d86 100644 --- a/tests/test_install_app.py +++ b/tests/test_install_app.py @@ -9,6 +9,7 @@ menu) is not exercised. from __future__ import annotations import tests +from tests import scratch_dir import hashlib import io @@ -17,7 +18,6 @@ import shutil import stat import subprocess import sys -import tempfile import unittest import zipfile from pathlib import Path @@ -110,16 +110,9 @@ class AppRepository(FakeRepository): timeout=120, check=False, stdin=subprocess.DEVNULL) -def _tempdir(test: unittest.TestCase) -> Path: - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - path = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) - test.addCleanup(shutil.rmtree, path, True) - return path - - class Placement(unittest.TestCase): def test_each_card_and_where_its_app_goes(self): - root = _tempdir(self) + root = scratch_dir(self) expected = {"muOS": "ARCHIVE", "KNULLI": "roms/ports", "ROCKNIX": ".config/modules"} for system, folder in expected.items(): with self.subTest(system=system): @@ -131,7 +124,7 @@ class Placement(unittest.TestCase): self.assertEqual(card.why, "") def test_a_bios_folder_inside_the_card_finds_its_root(self): - root = _tempdir(self) + root = scratch_dir(self) bios = make_card(root / "sd1", "muOS") bios.mkdir(parents=True, exist_ok=True) self.assertEqual(install.card_app(bios).root, root / "sd1") @@ -139,7 +132,7 @@ class Placement(unittest.TestCase): self.assertIsNone(install.card_app(root / "sd1")) def test_cards_without_a_launcher_say_why(self): - root = _tempdir(self) + root = scratch_dir(self) for system, words in (("Onion", "has no Python"), ("MinUI", "has no Python"), ("spruceOS", "no RetroBIOS app for spruceOS")): with self.subTest(system=system): @@ -148,7 +141,7 @@ class Placement(unittest.TestCase): self.assertIn(words, card.why) def test_a_folder_on_no_card(self): - self.assertIsNone(install.card_app(_tempdir(self) / "bios")) + self.assertIsNone(install.card_app(scratch_dir(self) / "bios")) def test_the_table_names_systems_detection_names(self): names = {rule.name for rule in install._card_rules()} @@ -215,7 +208,7 @@ class TheList(unittest.TestCase): for entry in launcher["members"]] data = install.app_archive(members) from installer_build import port - built = _tempdir(self) / port.MUOS_APP + built = scratch_dir(self) / port.MUOS_APP port.build_archive(port.MUOS_APP, built) with zipfile.ZipFile(built) as release, zipfile.ZipFile(io.BytesIO(data)) as ours: self.assertEqual(release.namelist(), ours.namelist()) @@ -332,7 +325,7 @@ class TheQuestion(unittest.TestCase): """Line mode at a terminal asks once, and only yes puts the app.""" def run_finish(self, answer: str, system: str = "muOS", **given) -> list: - root = _tempdir(self) + root = scratch_dir(self) bios = make_card(root / "card", system) args = mock.Mock(add_app=False, yes=False) for key, value in given.items(): @@ -385,7 +378,7 @@ class TheOption(unittest.TestCase): cls.repo.__exit__(None, None, None) def test_refused_where_it_cannot_apply(self): - root = _tempdir(self) + root = scratch_dir(self) pack = root / "RetroArch_BIOS_Pack.zip" zipfile.ZipFile(pack, "w").close() for options, words in ( @@ -405,7 +398,7 @@ class TheOption(unittest.TestCase): self.assertIn(words, proc.stderr) def test_refused_for_a_folder_on_no_card_or_no_launcher(self): - root = _tempdir(self) + root = scratch_dir(self) for system, words in ((None, "is not on a card this installer recognises"), ("Onion", "Onion has no Python"), ("spruceOS", "no RetroBIOS app for spruceOS yet")): @@ -424,7 +417,7 @@ class TheOption(unittest.TestCase): self.assertFalse([e for e in events if e["event"] == "download"]) def test_applied_after_the_install_and_reported(self): - root = _tempdir(self) + root = scratch_dir(self) for system in ("muOS", "KNULLI"): with self.subTest(system=system): bios = make_card(root / system, system) @@ -449,7 +442,7 @@ class TheOption(unittest.TestCase): self.assertEqual((again.returncode, app["ok"], app["written"]), (0, True, [])) def test_not_added_when_the_install_does_not_finish(self): - root = _tempdir(self) + root = scratch_dir(self) make_card(root / "card", "muOS") # A BIOS folder that is a file: every download fails. (root / "card" / "MUOS" / "bios").rmdir() diff --git a/tests/test_install_cores.py b/tests/test_install_cores.py index 572f0feb3..8c83b1c0a 100644 --- a/tests/test_install_cores.py +++ b/tests/test_install_cores.py @@ -30,7 +30,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent class CoreDirectories(unittest.TestCase): def setUp(self): - self.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(lambda: __import__("shutil").rmtree(self.tmp, ignore_errors=True)) def test_the_config_detection_read_names_the_cores(self): @@ -193,7 +193,7 @@ class ACoreTheListDoesNotKnow(unittest.TestCase): """A core newer than the list (parallel_dc, issue 87) loses nothing its .info declares.""" def setUp(self): - self.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.tmp, True) def test_only_names_no_profile_answers_for(self): @@ -456,7 +456,7 @@ class APlatformFileSettledByCoresAndSystems(unittest.TestCase): the event and a --declared-only check give the same answer.""" import hashlib - tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, tmp, True) payloads = {letter: letter.encode() * 3 for letter in "abc"} manifest = self.manifest() @@ -516,7 +516,7 @@ class APlatformFileSettledByCoresAndSystems(unittest.TestCase): class RefusedBeforeAnyInstall(unittest.TestCase): def test_a_platform_shipping_its_cores_stops_the_run_first(self): - tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, tmp, True) detected = [("retroarch", tmp / "system"), ("batocera", tmp / "bios")] (tmp / "retroarch.cfg").write_text("") @@ -551,7 +551,7 @@ class AnUnknownTargetStopsTheRunFirst(unittest.TestCase): the run ended without a summary.""" def test_nothing_is_fetched_when_one_platform_lacks_the_target(self): - tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, tmp, True) detected = [("emudeck", tmp / "bios"), ("retroarch", tmp / "system")] lists = {"emudeck": {"steamos": {"cores": []}}, "retroarch": {"x86_64": {"cores": []}}} diff --git a/tests/test_install_experience.py b/tests/test_install_experience.py index a56bd9b5b..79047c73e 100644 --- a/tests/test_install_experience.py +++ b/tests/test_install_experience.py @@ -514,7 +514,7 @@ class AStoppedRunCountsWhatLanded(unittest.TestCase): self.addCleanup(httpd.server_close) self.addCleanup(httpd.shutdown) self.addCleanup(_HeldHandler.release.set) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: dest = Path(tmp) / "bios" env = dict(os.environ, RETROBIOS_BASE_URL=f"http://127.0.0.1:{httpd.server_address[1]}") @@ -760,7 +760,7 @@ class ASettingsFileThisUserCannotRead(unittest.TestCase): word on the file, where the same refusal on retroarch.cfg is said.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) install._DETECTION_REFUSED.clear() self.addCleanup(install._DETECTION_REFUSED.clear) @@ -789,7 +789,7 @@ class AConfigThatFailsToRead(unittest.TestCase): refusal was said. Absence itself stays silent.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) install._DETECTION_REFUSED.clear() self.addCleanup(install._DETECTION_REFUSED.clear) @@ -860,7 +860,7 @@ class ARefusalTheProbeDoesNotRaise(unittest.TestCase): @unittest.skipIf(os.name == "nt" or os.geteuid() == 0, "a folder without search permission is POSIX") def test_a_quiet_false_is_still_told_from_absence(self): - base = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + base = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, base, True) closed = base / "closed" closed.mkdir() @@ -940,7 +940,7 @@ class RetroDeckBiosFolderNamedAsDest(unittest.TestCase): BIOS folder, put every file under bios/bios, which RetroDECK never reads.""" def test_the_files_go_below_the_retrodeck_folder(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) (root / "bios").mkdir() choice = install.card_choice("retrodeck", "retrodeck", root / "bios") @@ -949,7 +949,7 @@ class RetroDeckBiosFolderNamedAsDest(unittest.TestCase): self.assertFalse(choice.refused) def test_the_retrodeck_folder_itself_is_kept(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) (root / "bios").mkdir() choice = install.card_choice("retrodeck", "retrodeck", root) @@ -1042,7 +1042,7 @@ class OutputToAFileAsksNothing(unittest.TestCase): with open(read, "rb") as reader, open(write, "w") as writer: self.assertEqual(install._output_kind(writer), "pipe") del reader - with tempfile.TemporaryFile("w", dir=REPO_ROOT / "tmp") as handle: + with tempfile.TemporaryFile("w") as handle: self.assertEqual(install._output_kind(handle), "file") @@ -1128,7 +1128,7 @@ class SmallWordings(unittest.TestCase): self.assertNotIn("Install for:", out.getvalue()) def test_nothing_detected_is_said(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as home: + with tempfile.TemporaryDirectory() as home: env = dict(os.environ, HOME=home, USERPROFILE=home, XDG_CONFIG_HOME=home, RETROBIOS_OS="linux") proc = subprocess.run( @@ -1203,7 +1203,7 @@ class AClosedFolderBehindALink(unittest.TestCase): that loops was named by its open parent.""" def setUp(self): - self.base = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.base = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.base, True) self.home = self.base / "home" self.home.mkdir() @@ -1243,7 +1243,7 @@ class TheQuietConfigReadSaysNothing(unittest.TestCase): the human output never showed.""" def test_no_event_and_no_line(self): - base = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + base = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, base, True) closed = base / "home" / ".config" / "EmuDeck" closed.mkdir(parents=True) @@ -1320,7 +1320,7 @@ class NotFoundWithAClosedFolder(unittest.TestCase): if e["event"] == "error"], [("detect", "not_found")]) def test_the_manual_prompt_says_why_there_is_no_default(self): - home = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, home, True) asked = [] install._DETECTION_REFUSED[:] = [(home / ".config" / "EmuDeck", "Permission denied")] diff --git a/tests/test_install_expert.py b/tests/test_install_expert.py index 26bde1761..dd70640de 100644 --- a/tests/test_install_expert.py +++ b/tests/test_install_expert.py @@ -92,7 +92,7 @@ class RealListParity(unittest.TestCase): contextlib.redirect_stderr(io.StringIO()): platformpack.generate_pack( plat, str(REPO_ROOT / "platforms"), self.db, str(REPO_ROOT / "bios"), - str(REPO_ROOT / "tmp"), emulators_dir=str(REPO_ROOT / "emulators"), + tempfile.gettempdir(), emulators_dir=str(REPO_ROOT / "emulators"), zip_contents=self.zip_contents, emu_profiles=self.profiles, offline=True, record=record, **options) prefix = f"{base}/" if base else "" @@ -191,7 +191,7 @@ class RealListParity(unittest.TestCase): contextlib.redirect_stderr(io.StringIO()): emulatorpack.generate_emulator_pack( [profile], str(REPO_ROOT / "emulators"), self.db, - str(REPO_ROOT / "bios"), str(REPO_ROOT / "tmp"), + str(REPO_ROOT / "bios"), tempfile.gettempdir(), standalone=True, zip_contents=self.zip_contents, offline=True, record=record) files, omitted = install._narrow_to_emulators( @@ -337,7 +337,7 @@ class Lists(unittest.TestCase): """A list written for the runs below, in tmp/.""" def setUp(self): - scratch = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + scratch = tempfile.TemporaryDirectory() self.addCleanup(scratch.cleanup) self.root = Path(scratch.name) self.dest = self.root / "bios" @@ -596,7 +596,7 @@ class ExpertRuns(Lists): except ImportError as exc: self.skipTest(f"validate_schemas needs jsonschema: {exc}") - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as root: + with tempfile.TemporaryDirectory() as root: (Path(root) / "install" / "standalone").mkdir(parents=True) (Path(root) / "install" / "retroarch.json").write_text( json.dumps({**LIST, "truth_files": None}), encoding="utf-8") diff --git a/tests/test_install_filesystems.py b/tests/test_install_filesystems.py index adf6761c5..385616f1e 100644 --- a/tests/test_install_filesystems.py +++ b/tests/test_install_filesystems.py @@ -72,7 +72,7 @@ class NamesAFatCardCannotHold(unittest.TestCase): card each write failed with EINVAL, on every run.""" def test_the_probe_reads_einval_as_a_refusal(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: refused = OSError(errno.EINVAL, "Invalid argument") closed = PermissionError(errno.EACCES, "Permission denied") with mock.patch.object(install.os, "name", "posix"): @@ -88,7 +88,7 @@ class NamesAFatCardCannotHold(unittest.TestCase): self.assertFalse(install.holds_fat_refused_names(Path("."))) def _install(self, holds: bool) -> tuple[str, list[str]]: - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) old, dest = root / "old", root / "dest" old.mkdir() diff --git a/tests/test_install_games.py b/tests/test_install_games.py index d82ec5f22..022806481 100644 --- a/tests/test_install_games.py +++ b/tests/test_install_games.py @@ -35,8 +35,6 @@ import install REPO_ROOT = Path(__file__).resolve().parent.parent -TMP_ROOT = REPO_ROOT / "tmp" / "tests" -TMP_ROOT.mkdir(parents=True, exist_ok=True) def _crc(data: bytes) -> str: @@ -299,7 +297,7 @@ class Card: a saved file list.""" def __init__(self) -> None: - self.root = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + self.root = Path(tempfile.mkdtemp()) self.bios = self.root / "card" / "BIOS" self.roms = self.root / "card" / "Roms" self.bios.mkdir(parents=True) @@ -398,7 +396,7 @@ class Identification(GamesTestCase): self.assertEqual(plan.not_games, 1) def test_a_folder_of_whole_names_holds_only_those_files(self): - root = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) for name in ("C3.EXE", "c3.eng", "readme.txt"): (root / name).write_bytes(b"x") @@ -1079,7 +1077,7 @@ class Published(unittest.TestCase): def test_a_card_reads_with_the_published_index(self): if not (REPO_ROOT / "install" / "games" / "index.json").exists(): self.skipTest("install/games/ not generated") - root = Path(tempfile.mkdtemp(dir=TMP_ROOT)) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) bios = root / "userdata" / "bios" bios.mkdir(parents=True) diff --git a/tests/test_install_journeys.py b/tests/test_install_journeys.py index 3647acf1e..f700b5fb5 100644 --- a/tests/test_install_journeys.py +++ b/tests/test_install_journeys.py @@ -131,6 +131,9 @@ class Repository: muOS setup, and every payload.""" def __init__(self, test: unittest.TestCase) -> None: + # The screens print the card's path and the word budgets count it: + # the per-module scratch folder of run_tests.py is long enough to + # wrap it onto more lines. (REPO_ROOT / "tmp").mkdir(exist_ok=True) self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) test.addCleanup(shutil.rmtree, self.root, True) diff --git a/tests/test_install_offline.py b/tests/test_install_offline.py index 288f173c9..b1bfc2f1c 100644 --- a/tests/test_install_offline.py +++ b/tests/test_install_offline.py @@ -93,9 +93,7 @@ def _offline_env() -> dict: class Scratch(unittest.TestCase): def setUp(self): - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=scratch)) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.dest = self.root / "system" self.list = self.root / "retroarch.json" diff --git a/tests/test_install_pack.py b/tests/test_install_pack.py index 94e735426..f7a8aba55 100644 --- a/tests/test_install_pack.py +++ b/tests/test_install_pack.py @@ -81,9 +81,7 @@ class Repository(unittest.TestCase): tree = TREE def setUp(self): - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=scratch)) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.served = self.root / "served" (self.served / "install").mkdir(parents=True) @@ -462,9 +460,7 @@ class TheSwapIsWhole(unittest.TestCase): failure puts the earlier set back, a cleanup that fails keeps the pack.""" def setUp(self): - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=scratch)) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.out = self.root / "out" self.out.mkdir() diff --git a/tests/test_install_removal.py b/tests/test_install_removal.py index 57a42a4fc..b4f230097 100644 --- a/tests/test_install_removal.py +++ b/tests/test_install_removal.py @@ -356,7 +356,7 @@ class ACraftedRecord(unittest.TestCase): the BIOS folder, through a link, or anything but a regular file.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.folder = self.root / "bios" self.folder.mkdir() @@ -418,7 +418,7 @@ class AFoldingDrive(unittest.TestCase): another setup are compared folded there.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.folder = self.root / "bios" self.folder.mkdir() @@ -472,7 +472,7 @@ class ReviewOfTheRemoval(unittest.TestCase): """What a review of the first version found, each held by a test.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.folder = self.root / "bios" self.folder.mkdir() @@ -747,7 +747,7 @@ class MisplacedCopies(unittest.TestCase): self.assertIn(words, proc.stderr) def test_a_place_a_list_reads_or_a_setup_names_stays(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) folder = root / "bios" folder.mkdir() @@ -787,7 +787,7 @@ class MisplacedCopies(unittest.TestCase): def test_a_card_whose_folder_is_the_roms_root_keeps_its_games(self): """EmuELEC installs into /storage/roms: ports/doom/doom2.wad is the user's game, bios/old/doom2.wad a copy in the wrong place.""" - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) folder = root / "roms" wad = b"doom ii" diff --git a/tests/test_install_selection.py b/tests/test_install_selection.py index e25d21c6a..b047c33f1 100644 --- a/tests/test_install_selection.py +++ b/tests/test_install_selection.py @@ -540,7 +540,7 @@ class FakeRepository: self.selection = selection def __enter__(self) -> FakeRepository: - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) (self.root / "install").mkdir() (self.root / "bios").mkdir() files = [] @@ -889,7 +889,7 @@ class InstallMatchesASystemPack(unittest.TestCase): def _packed(self, systems, regions) -> set[str]: import zipfile - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out: + with tempfile.TemporaryDirectory() as out: zip_path = platformpack.generate_pack( self.PLATFORM, str(REPO_ROOT / "platforms"), self.db, str(REPO_ROOT / "bios"), out, @@ -929,7 +929,7 @@ class DataTreesFollowTheSystemsTheyServe(InstallMatchesASystemPack): from model.registry import load_data_dir_registry # The trees come from the registry the manifest reads by itself. - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out: + with tempfile.TemporaryDirectory() as out: zip_path = platformpack.generate_pack( self.PLATFORM, str(REPO_ROOT / "platforms"), self.db, str(REPO_ROOT / "bios"), out, @@ -1056,7 +1056,7 @@ class AHeldFileTheInstallerCannotFetch(unittest.TestCase): from model.platforms import _platform_config_cache from model.profiles import emulator_profiles_cache import generate_db - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) previous = os.getcwd() os.chdir(tmp.name) @@ -1137,7 +1137,7 @@ class AStandaloneLayoutBelowTheBiosFolder(unittest.TestCase): from model.platforms import _platform_config_cache from model.profiles import emulator_profiles_cache import generate_db - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) previous = os.getcwd() os.chdir(tmp.name) @@ -1220,7 +1220,7 @@ class AnExtraBesideItsDeclarationBelowTheBiosFolder(unittest.TestCase): from model.platforms import _platform_config_cache from model.profiles import emulator_profiles_cache import generate_db - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) previous = os.getcwd() os.chdir(tmp.name) @@ -1434,7 +1434,7 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase): import io import zipfile - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out, \ + with tempfile.TemporaryDirectory() as out, \ contextlib.redirect_stdout(io.StringIO()): zip_path = platformpack.generate_pack( platform, str(REPO_ROOT / "platforms"), self.db, diff --git a/tests/test_install_tui.py b/tests/test_install_tui.py index 22c355fb0..c4c5397c1 100644 --- a/tests/test_install_tui.py +++ b/tests/test_install_tui.py @@ -720,7 +720,7 @@ class Flow(unittest.TestCase): self.assertIsNone(install.typed_path('""')) def test_the_browser_lists_folders_and_goes_up(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) for name in ("system", ".config", "Bios"): (root / name).mkdir() @@ -748,7 +748,7 @@ class Flow(unittest.TestCase): """With no usual folder the browser opens at HOME, on Use this folder: A five times installed the BIOS files into ~. At HOME or a drive's root, A goes into the first folder instead.""" - home = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, home, True) (home / "Games").mkdir() state = install.TuiState(os_type="linux", home=home) @@ -765,7 +765,7 @@ class Flow(unittest.TestCase): self.assertNotEqual(state.browse_rows[state.focus["browse"]].action, "use") def test_cards_are_listed_first(self): - card = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + card = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, card, True) (card / ".system").mkdir() (card / ".system" / "version.txt").write_text("NextUI-20250101\n") @@ -775,7 +775,7 @@ class Flow(unittest.TestCase): self.assertEqual(rows[2].label, f"{card} (NextUI card)") def test_a_mounted_card_is_a_setup_of_its_own(self): - card = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + card = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, card, True) (card / ".system").mkdir() (card / ".system" / "version.txt").write_text("MinUI-20250101\n") @@ -1856,7 +1856,7 @@ class ControlCharacters(unittest.TestCase): self.assertIn("?[2Jevil.bin", "\n".join(lines)) def test_a_folder_name_in_the_browser(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) (root / "x\x1b]52;c;x\x07").mkdir() state = fresh_state() @@ -2092,7 +2092,7 @@ class CleanupSurvivesABrokenTerminal(unittest.TestCase): CleanupSurvivesABrokenTerminal.Tty.broken = True self.addCleanup(setattr, CleanupSurvivesABrokenTerminal.Tty, "broken", False) - work = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + work = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, work, True) with mock.patch.object(install._TuiTerminal, "draw", breaking_draw), \ mock.patch.object(install.tempfile, "mkdtemp", return_value=str(work)), \ @@ -2283,7 +2283,7 @@ class TicksBarAndPaths(unittest.TestCase): " 50 files failed, all for one reason: folder not writable."]) def test_folder_inside_a_card_offers_its_root(self): - card = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + card = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, card, True) (card / ".system").mkdir() (card / ".system" / "version.txt").write_text("MinUI-20250101\n") @@ -2329,7 +2329,7 @@ class TicksBarAndPaths(unittest.TestCase): self.assertEqual(self.focused(state).action, "other") self.assertIn("Every folder of this path would be made", " ".join(install.tui_view(state, 120, 40))) - near = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + near = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, near, True) install._choose(state, "retroarch", near / "bios") self.assertEqual(self.focused(state).action, "create") @@ -2466,7 +2466,7 @@ class WorkFolders(unittest.TestCase): return [Key("enter")] def run_to(self, code: int) -> tuple: - work = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + work = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, work, True) state = checked_state() state.stack.append("result") @@ -2547,7 +2547,7 @@ class WorkFolders(unittest.TestCase): entered = [] WorkFolders.Terminal.state_to = lambda _t: None out = io.StringIO() - work = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + work = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, work, True) with mock.patch.object(install, "_TuiTerminal", self.Terminal), \ mock.patch.object(install.tempfile, "mkdtemp", return_value=str(work)), \ @@ -2585,7 +2585,7 @@ class CopyFromAnOldCard(unittest.TestCase): install.tui_receive(state, ("ended", state.run_id, 1, [])) def test_the_plan_offers_it_and_the_browser_adds_the_folder(self): - old = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + old = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, old, True) (old / "bios").mkdir() (old / "backup.zip").write_bytes(b"PK") @@ -2730,7 +2730,7 @@ class CardsSpaceAndConfirm(unittest.TestCase): } def card(self, files: dict) -> Path: - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) for name, text in files.items(): path = root / name @@ -3266,7 +3266,7 @@ class CardsSpaceAndConfirm(unittest.TestCase): def test_work_folders_left_behind_are_pruned(self): import subprocess - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) gone = subprocess.Popen([sys.executable, "-c", "pass"]) gone.wait() @@ -3362,7 +3362,7 @@ class IdleExit(unittest.TestCase): return [] out = io.StringIO() - work = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + work = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, work, True) with mock.patch.object(install, "_TuiTerminal", Quiet), \ mock.patch.object(install.tempfile, "mkdtemp", return_value=str(work)), \ @@ -3492,7 +3492,7 @@ class TheSaveFolderHasARow(unittest.TestCase): self.assertEqual((row.label, row.right), (f"Save folder: {install._short_path(place.directory, HOME)}", "--save-dir")) - saves = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + saves = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, saves, True) state.stack = ["setup", "plan", "options"] install._option(state, "savedir", 0) @@ -3517,7 +3517,7 @@ class ACardSystemNamedOnAComputer(unittest.TestCase): ONION = {".tmp_update/onionVersion/version.txt": "4.3.1\n"} def card(self, files: dict) -> Path: - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) for name, text in files.items(): (root / name).parent.mkdir(parents=True, exist_ok=True) @@ -3534,7 +3534,7 @@ class ACardSystemNamedOnAComputer(unittest.TestCase): self.assertIsNone(install.card_bound("batocera", "batocera")) def test_without_questions_the_run_names_the_card_and_writes_nothing(self): - home = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, home, True) system = home / ".config" / "retroarch" / "system" system.mkdir(parents=True) @@ -4592,7 +4592,7 @@ class AFolderThisUserCannotOpen(unittest.TestCase): typed on the folder screen it ended on a crash log.""" def setUp(self): - base = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + base = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, base, True) self.lock = base / "lock" self.lock.mkdir() @@ -4710,9 +4710,9 @@ class AGoesIntoASubfolder(unittest.TestCase): the BIOS files at its root) or .cache.""" def setUp(self): - self.home = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.home, True) - self.card = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.card = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.card, True) self.state = install.TuiState(os_type="linux", home=self.home) self.state.platform = "retroarch" @@ -4879,7 +4879,7 @@ class WindowsHasNoPosixModules(unittest.TestCase): kill.assert_called_once_with(0, install.signal.CTRL_C_EVENT) def test_work_folder_owner_and_partial_lock(self): - work = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + work = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, work, True) (work / install.TUI_OWNER).write_text(str(os.getpid()), encoding="utf-8") with SimulatedWindows() as windows: @@ -4897,7 +4897,7 @@ class WindowsHasNoPosixModules(unittest.TestCase): console.broken = True real_draw(terminal, lines, cols) - work = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + work = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, work, True) with SimulatedWindows() as windows, \ mock.patch.object(install._TuiTerminal, "draw", breaking_draw), \ @@ -5088,8 +5088,7 @@ 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 tests.test_install_app import make_card - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) test.addCleanup(shutil.rmtree, root, True) return root / "card", make_card(root / "card", system) @@ -5242,7 +5241,6 @@ class EndToEnd(unittest.TestCase): """The real install.py --tui, keys in and screens out.""" def repo(self, cls=FakeRepository, **options) -> FakeRepository: - (REPO_ROOT / "tmp").mkdir(exist_ok=True) repo = cls(**options) repo.__enter__() self.addCleanup(repo.__exit__, None, None, None) @@ -5828,8 +5826,7 @@ def _terminfo_folder(test: unittest.TestCase) -> Path: """A $TERMINFO with a glass terminal, a VT52, two ANSI terminals of 8 colours, one in the extended format, and two ANSI terminals without colour: one naming 2, one naming none (vt100).""" - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - folder = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + folder = Path(tempfile.mkdtemp()) test.addCleanup(shutil.rmtree, folder, True) ansi = "\x1b[%i%p1%d;%p2%dH" for name, cup, extended, colours in ( @@ -6334,7 +6331,7 @@ class CopyFromStartsInDownloads(unittest.TestCase): browser opened at HOME, under every mounted drive.""" def test_a_zip_in_downloads_opens_there(self): - home = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, home, True) (home / "Downloads").mkdir() state = checked_state() @@ -6372,7 +6369,7 @@ class AFocusesNoSystemFolder(unittest.TestCase): the recycle bin, which Use this folder then took as the BIOS folder.""" def setUp(self): - self.home = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.home, True) self.state = install.TuiState(os_type="linux", home=self.home) self.state.platform = "retroarch" @@ -6464,7 +6461,7 @@ class EveryCardSetupGoesToItsCard(unittest.TestCase): way in, goes to its card.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.setups = install.card_setups() @@ -6686,7 +6683,7 @@ class ConfirmRefusalsAndCardRows(unittest.TestCase): """Confirm before an install, refusals said in full, and card rows.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) def onion(self, name: str = "ONION") -> Path: @@ -6968,7 +6965,7 @@ class OneCardReading(unittest.TestCase): of a card's root, said the same on the screen and in line mode.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) patcher = mock.patch.dict(install._DETECTED_OS, {}) patcher.start() @@ -7228,7 +7225,7 @@ class WhatEachScreenOffers(unittest.TestCase): """What each screen offers and says.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) def setups(self, pad: str = "keys") -> install.TuiState: @@ -7953,7 +7950,7 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings, platform and folder on both, A or Enter taking what each offers first.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) for patcher in (mock.patch.dict(install._DETECTED_OS, {}), mock.patch.dict(os.environ, {"HOME": str(self.root / "home"), @@ -9218,7 +9215,7 @@ class PacksWordingAndDocs(unittest.TestCase): LineModeAndScreenDecideAlike.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) install.LOCAL.reset() self.addCleanup(install.LOCAL.reset) @@ -9670,7 +9667,7 @@ class CardFoldersAndNarrowBars(unittest.TestCase): them.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) patcher = mock.patch.dict(install._DETECTED_OS, {}) patcher.start() @@ -9855,7 +9852,7 @@ class CardBoundaries(unittest.TestCase): seen, a folder named MUOS taken for a card, ismount unprobed.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) def choice(self, folder: Path, points=frozenset()) -> install.CardChoice: @@ -9909,7 +9906,7 @@ class LineModeDecisions(unittest.TestCase): no Enter default, a folder question with no way out).""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) for patcher in (mock.patch.dict(install._DETECTED_OS, {}), mock.patch.dict(os.environ, {"HOME": str(self.root / "home"), @@ -10093,7 +10090,7 @@ class ScreenRowsAndFilters(unittest.TestCase): """Rows, filters and help as the screens draw them.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) patcher = mock.patch.dict(install._DETECTED_OS, {}) patcher.start() @@ -10246,7 +10243,7 @@ class ScreenRowsAndFilters(unittest.TestCase): """Cut after "copied,". On the CI runner /home held three folders, and the list cut the hint: it is kept whole, the list scrolling, from a folder of this test's own.""" - home = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + home = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, home, True) for name in ("linuxbrew", "packer", "runner"): (home / name).mkdir() @@ -10372,8 +10369,7 @@ class EdgesTheMutantsFound(unittest.TestCase): Path("/mnt/g/RetroArch/cores"))) def card(self, system: str) -> Path: - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) make_card(root / "card", system) return root / "card" @@ -10420,8 +10416,7 @@ class CardNamesAndHelp(_CardFixtures, unittest.TestCase): docs answer, line mode's parity being in LineModeAndScreenDecideAlike.""" def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) install.LOCAL.reset() self.addCleanup(install.LOCAL.reset) @@ -10662,8 +10657,7 @@ class TheAndroidResultReadsWhole(unittest.TestCase): and the game data line named no folder.""" def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) for patcher in (mock.patch.dict(install._SPELLED, {}, clear=True),): patcher.start() @@ -11332,8 +11326,7 @@ class TapsGameDataAndExitCodes(_CardFixtures, unittest.TestCase): parity being in LineModeAndScreenDecideAlike.""" def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) install.LOCAL.reset() self.addCleanup(install.LOCAL.reset) @@ -12481,7 +12474,7 @@ class TheUsageNamesTheInstaller(unittest.TestCase): the name install.ps1 gives its copy.""" def test_a_copy_under_a_temporary_name_says_install_py(self): - scratch = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + scratch = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, scratch, True) copy = scratch / "retrobios-install-33826e0b-37cc-4ad3-a6c4-6ed168e3fe9e.py" shutil.copyfile(REPO_ROOT / "install.py", copy) @@ -13642,7 +13635,7 @@ class EachDataTreeReadOnce(unittest.TestCase): on an SD card through a reader.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.dest = self.root / "bios" bios = b"bios bytes" @@ -15979,7 +15972,7 @@ class DeviceAndEmulatorScreens(unittest.TestCase): self.assertNotIn(("--offline", None), install.tui_flags(state)) def test_from_a_pack_opens_the_browser_on_zips_and_reads_the_pack(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) (root / "Downloads").mkdir() pack = root / "Downloads" / "RetroArch_BIOS_Pack.zip" @@ -16009,7 +16002,7 @@ class DeviceAndEmulatorScreens(unittest.TestCase): self.assertIn(("--from-pack", str(pack)), install.tui_flags(state)) def test_open_tui_pack_refuses_another_platforms_pack(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) pack = root / "Batocera_BIOS_Pack.zip" with zipfile.ZipFile(pack, "w") as archive: @@ -16071,7 +16064,7 @@ class ScreenChoicesInstallWhatTheirFlagInstalls(unittest.TestCase): patcher = mock.patch.object(install, "_mounted_cards", return_value=[]) patcher.start() self.addCleanup(patcher.stop) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.listed, self.copies = _parity_list(self.root) self.manifest = json.loads(self.listed.read_text()) @@ -16294,7 +16287,7 @@ class DeviceAndEmulatorReview(unittest.TestCase): self.assertEqual(state.packs, []) def test_open_tui_pack_leaves_the_run_s_pack_alone(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) pack = root / "RetroArch_BIOS_Pack.zip" with zipfile.ZipFile(pack, "w") as archive: @@ -16310,7 +16303,7 @@ class DeviceAndEmulatorReview(unittest.TestCase): self.assertIs(install.LOCAL.pack, previous) def test_a_zip_that_is_no_pack_is_closed(self): - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) notpack = root / "photos.zip" with zipfile.ZipFile(notpack, "w") as archive: diff --git a/tests/test_large_file_cache.py b/tests/test_large_file_cache.py index b77c7d796..b215f8d19 100644 --- a/tests/test_large_file_cache.py +++ b/tests/test_large_file_cache.py @@ -686,7 +686,7 @@ class _StalledResponse(io.BytesIO): class DownloadFailuresAndRevisions(unittest.TestCase): def setUp(self): - self.dir = tempfile.mkdtemp(dir=REPO_ROOT / "tmp") + self.dir = tempfile.mkdtemp() self._urlopen = largefiles.urllib.request.urlopen self.addCleanup(setattr, largefiles.urllib.request, "urlopen", self._urlopen) @@ -794,7 +794,7 @@ class ASameSizeReuploadIsSeen(unittest.TestCase): --clobber: judged by size, the stale cache copy was kept for good.""" def setUp(self): - self.dir = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.dir = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.dir, True) self.cached = self.dir / "dsi_nand.bin" self.cached.write_bytes(b"OLD NAND") @@ -875,7 +875,7 @@ class AVerifiedPathKeepsItsBytes(unittest.TestCase): def setUp(self): _test_registry(self) - self.dir = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.dir = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.dir, True) (self.dir / "asset.bin").write_bytes(PAYLOAD_A) self.served = {"asset.bin": hashlib.sha256(PAYLOAD_B).hexdigest()} diff --git a/tests/test_launcher_placement.py b/tests/test_launcher_placement.py index 53d400c6f..a1b243928 100644 --- a/tests/test_launcher_placement.py +++ b/tests/test_launcher_placement.py @@ -47,8 +47,7 @@ LINK = { class ALinkMovesTheDestination(unittest.TestCase): def setUp(self) -> None: emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) bios = self.root / "bios" / "Commodore" / "Amiga" bios.mkdir(parents=True) @@ -306,8 +305,7 @@ class AProgramRunFromItsFolder(unittest.TestCase): def setUp(self) -> None: emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) bios = self.root / "bios" / "Maker" / "Prog" bios.mkdir(parents=True) @@ -573,8 +571,7 @@ class ASettingSetsTheBiosFolder(unittest.TestCase): def setUp(self) -> None: emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) files, by_md5, by_name = {}, {}, {} for folder, name, data in ( diff --git a/tests/test_launchers_retrobat.py b/tests/test_launchers_retrobat.py index e23d39124..b4505411a 100644 --- a/tests/test_launchers_retrobat.py +++ b/tests/test_launchers_retrobat.py @@ -1592,7 +1592,7 @@ class Helpers(unittest.TestCase): from scraper import retrobat_scraper as rs pin = "ca486005f598551600d04a33b3156a5d764368d6" - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as scratch: + with tempfile.TemporaryDirectory() as scratch: yml = Path(scratch) / "retrobat.yml" yml.write_text( "source: https://raw.githubusercontent.com/RetroBat-Official/emulatorlauncher/" diff --git a/tests/test_maker_folder_names.py b/tests/test_maker_folder_names.py index 3c28df216..5e4e72572 100644 --- a/tests/test_maker_folder_names.py +++ b/tests/test_maker_folder_names.py @@ -80,8 +80,7 @@ PLATFORM = { class _Collection(unittest.TestCase): def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self._cwd = os.getcwd() os.chdir(self._tmp.name) for relative, payload in ( diff --git a/tests/test_md5_pack_context.py b/tests/test_md5_pack_context.py index 99ccb5e8f..4f55ee18f 100644 --- a/tests/test_md5_pack_context.py +++ b/tests/test_md5_pack_context.py @@ -22,7 +22,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent def _pack(*options: str) -> tuple[subprocess.CompletedProcess, list[str]]: - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out: + with tempfile.TemporaryDirectory() as out: proc = subprocess.run( [sys.executable, "scripts/generate_pack.py", *options, "--offline", "--output-dir", out], @@ -41,7 +41,6 @@ class TheEmulatorContextIsChecked(unittest.TestCase): db_path = REPO_ROOT / "database.json" if not db_path.exists(): raise unittest.SkipTest("database.json is not built") - (REPO_ROOT / "tmp").mkdir(exist_ok=True) cls.db = json.loads(db_path.read_text(encoding="utf-8")) def test_an_unknown_emulator_is_refused(self): @@ -79,7 +78,7 @@ class SystemAndEmulatorPacksKeepTheirNames(unittest.TestCase): import generate_db from packs import emulatorpack - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) (root / "bios").mkdir() (root / "emulators").mkdir() diff --git a/tests/test_measurements.py b/tests/test_measurements.py index 8b5bd4c1d..d317c8c90 100644 --- a/tests/test_measurements.py +++ b/tests/test_measurements.py @@ -132,8 +132,7 @@ class Workspace(unittest.TestCase): """A tree with three records under measurements/ and one profile.""" def setUp(self) -> None: - (REPO_ROOT / "tmp" / "tests").mkdir(parents=True, exist_ok=True) - self.tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests")) + self.tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.tmp, True) self.tree = self.tmp / "tree" self.tree.mkdir() @@ -473,7 +472,7 @@ class SitePages(unittest.TestCase): """The Data page said each per-emulator database is "linked from its page". An emulator page shows the proof lines, which link the record lines and never the database.""" - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as scratch: + with tempfile.TemporaryDirectory() as scratch: path = Path(scratch) / "m.sqlite" connection = sqlite3.connect(path) connection.execute("CREATE TABLE meta (key TEXT)") diff --git a/tests/test_minui_platform.py b/tests/test_minui_platform.py index fbd7991a0..cbcbcdb8e 100644 --- a/tests/test_minui_platform.py +++ b/tests/test_minui_platform.py @@ -172,7 +172,7 @@ class PackPlacesCoreFilesUnderTheTag(unittest.TestCase): from model.profiles import emulator_profiles_cache emulator_profiles_cache.clear() - self.root = tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests") + self.root = tempfile.mkdtemp() self.bios = os.path.join(self.root, "bios") self.platforms = os.path.join(self.root, "platforms") self.emulators = os.path.join(self.root, "emulators") @@ -385,7 +385,7 @@ class InstallerReadsTheCard(unittest.TestCase): """install.py runs on the computer the card is mounted on.""" def setUp(self): - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" / "tests")) + self.root = Path(tempfile.mkdtemp()) (self.root / ".system").mkdir() def tearDown(self): diff --git a/tests/test_name_tiebreak.py b/tests/test_name_tiebreak.py index 12bfa07af..16d4b4d01 100644 --- a/tests/test_name_tiebreak.py +++ b/tests/test_name_tiebreak.py @@ -20,7 +20,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class DeclaredSizeOrders(unittest.TestCase): def test_the_fitting_size_comes_first(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: big = Path(tmp) / "a" / "pcm.rom" small = Path(tmp) / "b" / "pcm.rom" for path, size in ((big, 1024), (small, 512)): diff --git a/tests/test_no_game_data.py b/tests/test_no_game_data.py index a97eee9a5..20a536746 100644 --- a/tests/test_no_game_data.py +++ b/tests/test_no_game_data.py @@ -10,6 +10,7 @@ full manifest. from __future__ import annotations import tests +from tests import scratch_dir import contextlib import functools @@ -239,13 +240,8 @@ class InstallerLeavesGameDataOut(unittest.TestCase): "bios/game.wad": (b"wad" * 10, "game_data"), } - def _tempdir(self) -> Path: - handle = tempfile.TemporaryDirectory() - self.addCleanup(handle.cleanup) - return Path(handle.name) - def serve(self, categorized: bool = True) -> None: - root = self._tempdir() + root = scratch_dir(self) files = [] for path, (data, category) in self.FILES.items(): (root / path).parent.mkdir(parents=True, exist_ok=True) @@ -272,7 +268,7 @@ class InstallerLeavesGameDataOut(unittest.TestCase): threading.Thread(target=httpd.serve_forever, daemon=True).start() self.addCleanup(httpd.server_close) self.addCleanup(httpd.shutdown) - home = self._tempdir() + home = scratch_dir(self) self.bios = home / "bios" self.bios.mkdir() self.env = {**os.environ, "HOME": str(home), "RETROBIOS_OS": "linux", diff --git a/tests/test_np2_fonts.py b/tests/test_np2_fonts.py index 750bdc7ec..21ff4ca75 100644 --- a/tests/test_np2_fonts.py +++ b/tests/test_np2_fonts.py @@ -36,8 +36,7 @@ def _entry(profile: str, name: str) -> dict: class FontFormatsAreSeparateFiles(unittest.TestCase): def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.addCleanup(os.chdir, os.getcwd()) os.chdir(self.root) diff --git a/tests/test_pack_conformance_dirs.py b/tests/test_pack_conformance_dirs.py index 523cc1ab6..29c7d6e1d 100644 --- a/tests/test_pack_conformance_dirs.py +++ b/tests/test_pack_conformance_dirs.py @@ -25,8 +25,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class ConformanceUsesTheRunDirectories(unittest.TestCase): def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self.tmp = tempfile.TemporaryDirectory() self.addCleanup(self.tmp.cleanup) def _args(self, split: bool) -> argparse.Namespace: diff --git a/tests/test_pack_core_extras.py b/tests/test_pack_core_extras.py index 6c01f9ad7..a1b4513cc 100644 --- a/tests/test_pack_core_extras.py +++ b/tests/test_pack_core_extras.py @@ -40,7 +40,7 @@ def _held(files: dict, by_name: dict, path: str, payload: bytes) -> str: class CoreFilesAsTheBuilderPlacesThem(unittest.TestCase): def setUp(self): - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) previous = os.getcwd() os.chdir(tmp.name) @@ -96,7 +96,7 @@ class ARefusedPinLeavesItsPathToTheCore(unittest.TestCase): core file the pack carries there was never compared.""" def setUp(self): - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) previous = os.getcwd() os.chdir(tmp.name) @@ -152,7 +152,7 @@ class NarrowedPacksAgainstTheirOwnList(unittest.TestCase): from model.platforms import _platform_config_cache from model.profiles import load_emulator_profiles, emulator_profiles_cache import generate_db - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) previous = os.getcwd() os.chdir(tmp.name) diff --git a/tests/test_pack_counts.py b/tests/test_pack_counts.py index 18af1911b..2f1084045 100644 --- a/tests/test_pack_counts.py +++ b/tests/test_pack_counts.py @@ -643,7 +643,7 @@ class TheReleaseNotesReadTheRecord(unittest.TestCase): "- Every hash comes from the emulator's source, never from a forum list.\n" "- So a game never stops on a missing file."), ["forum", "never stops"]) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: whats_new = Path(tmp) / "whats-new.md" whats_new.write_text("- Hashes never from a forum list\n", encoding="utf-8") record = Path(tmp) / "release.json" @@ -671,7 +671,7 @@ class CoreCopiesKeepTheirCategory(unittest.TestCase): def test_a_copy_counts_as_its_entry_says(self): from packs.extras import collect_emulator_extras, hidden_extras - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: held = Path(tmp) / "x.dat" held.write_bytes(b"data") sha1 = hashlib.sha1(b"data").hexdigest() diff --git a/tests/test_pack_destinations.py b/tests/test_pack_destinations.py index 4e9f9d6da..ddd3bd4f1 100644 --- a/tests/test_pack_destinations.py +++ b/tests/test_pack_destinations.py @@ -32,8 +32,7 @@ class _Fixture(unittest.TestCase): from model.profiles import emulator_profiles_cache emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.bios = self.root / "bios" self.platforms = self.root / "platforms" @@ -244,8 +243,7 @@ class ThePipelineComparesPaths(unittest.TestCase): def test_a_swap_at_equal_counts_fails(self): import pipeline - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) zip_path = root / "Plat_BIOS_Pack.zip" with zipfile.ZipFile(zip_path, "w") as zf: diff --git a/tests/test_pack_failures.py b/tests/test_pack_failures.py index 8bf8f73ca..c989d92e4 100644 --- a/tests/test_pack_failures.py +++ b/tests/test_pack_failures.py @@ -32,8 +32,7 @@ class FailedPlatformFailsTheRun(unittest.TestCase): previous = os.getcwd() os.chdir(REPO_ROOT) self.addCleanup(os.chdir, previous) - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self.tmp = tempfile.TemporaryDirectory() self.addCleanup(self.tmp.cleanup) def _args(self) -> argparse.Namespace: diff --git a/tests/test_pack_file_names.py b/tests/test_pack_file_names.py index c64180b1c..eb095bcec 100644 --- a/tests/test_pack_file_names.py +++ b/tests/test_pack_file_names.py @@ -27,7 +27,7 @@ class PackFileNames(unittest.TestCase): self.assertEqual(file_name_part('a\\b:c*d?"eg|h', "_"), "a-b-c-d--e-f-g-h") def test_an_emulator_named_with_a_slash_writes_its_pack(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: emulators = Path(tmp) / "emulators" out = Path(tmp) / "out" emulators.mkdir() @@ -56,7 +56,7 @@ class SystemPackLeavesTheEmulatorPack(unittest.TestCase): def test_both_packs_stay(self): import subprocess - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: for mode in (["--emulator", "emuscv"], ["--system", "scv"]): subprocess.run( [sys.executable, "scripts/generate_pack.py", *mode, "--offline", diff --git a/tests/test_pack_member_identity.py b/tests/test_pack_member_identity.py index 88a412f58..e09eb3e4a 100644 --- a/tests/test_pack_member_identity.py +++ b/tests/test_pack_member_identity.py @@ -32,7 +32,7 @@ class MembersMustBeKnown(unittest.TestCase): with zipfile.ZipFile(inner, "w") as zf: zf.writestr("rom.bin", known) db = {"files": {}, "indexes": {"by_md5": {md5: "s"}, "by_name": {}}} - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: pack = Path(tmp) / "P_BIOS_Pack.zip" with zipfile.ZipFile(pack, "w") as zf: zf.writestr("clone.zip", inner.getvalue()) @@ -50,7 +50,7 @@ class DataMembersAreCheckedByContent(unittest.TestCase): def test_same_size_other_bytes_is_an_error(self): good = b"A" * 64 - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "cache" (cache / "Sys").mkdir(parents=True) (cache / "Sys" / "font.bin").write_bytes(good) diff --git a/tests/test_pack_probe.py b/tests/test_pack_probe.py index 750b359d4..1c58cfe08 100644 --- a/tests/test_pack_probe.py +++ b/tests/test_pack_probe.py @@ -19,6 +19,7 @@ import json import os import re import shutil +import tempfile import unittest import zipfile from pathlib import Path @@ -32,7 +33,7 @@ from model.profiles import load_emulator_profiles REPO_ROOT = Path(__file__).resolve().parent.parent -TMP = REPO_ROOT / "tmp" / "tests" / "pack_probe" +TMP = Path(tempfile.gettempdir()) / "pack_probe" SATURN = { "type": "libretro", diff --git a/tests/test_path_conflict_status.py b/tests/test_path_conflict_status.py index 564b8ea8f..808365ec8 100644 --- a/tests/test_path_conflict_status.py +++ b/tests/test_path_conflict_status.py @@ -233,7 +233,7 @@ class AlternativesAgreeWithThePack(unittest.TestCase): discrepancy, but verify took the worst status and said missing.""" def setUp(self): - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self.root = Path(self._tmp.name) bios = self.root / "bios" self.emulators = self.root / "emulators" @@ -291,7 +291,7 @@ class AMaskedArchiveIsMissing(unittest.TestCase): def setUp(self): import zipfile - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self.root = Path(self._tmp.name) self.emulators = self.root / "emulators" files = {} diff --git a/tests/test_platform_inheritance.py b/tests/test_platform_inheritance.py index 125ac36a5..828e292e5 100644 --- a/tests/test_platform_inheritance.py +++ b/tests/test_platform_inheritance.py @@ -25,7 +25,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class AChildLeavesItsParentAlone(unittest.TestCase): def setUp(self): - self.dir = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.dir = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.dir, True) self.addCleanup(_platform_config_cache.clear) self.addCleanup(_shared_yml_cache.clear) diff --git a/tests/test_port.py b/tests/test_port.py index be6212b25..5ac556849 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -9,6 +9,7 @@ route of the port, and the other launchers, are in test_handheld_launchers. from __future__ import annotations import tests +from tests import scratch_dir import hashlib import importlib.util @@ -19,7 +20,6 @@ import re import shutil import subprocess import sys -import tempfile import unittest import zipfile from pathlib import Path @@ -41,14 +41,6 @@ _spec.loader.exec_module(rbevents) SCRIPTS = [PORT / "RetroBIOS.sh", PORT / "retrobios" / "screens.txt"] -def _tempdir(test: unittest.TestCase) -> Path: - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - path = Path(tempfile.mkdtemp(dir=str(scratch))) - test.addCleanup(shutil.rmtree, path, True) - return path - - class EveryScriptParses(unittest.TestCase): def test_only_dialog_functions_the_oldest_releases_have(self): """PortMaster 2024.02.26 and 8.5.23 define these in PortMasterDialog.txt, @@ -78,7 +70,7 @@ class EveryScriptParses(unittest.TestCase): class ThePortArchive(unittest.TestCase): def setUp(self): - self.out = _tempdir(self) + self.out = scratch_dir(self) def _build(self, name: str = "RetroBIOS.zip") -> Path: return installer_build_port.build_port(self.out / name) @@ -154,7 +146,7 @@ class LauncherIndex(unittest.TestCase): def test_the_list_refuses_an_installer_the_bootstraps_do_not_pin(self): from installer_build import launcherindex - root = _tempdir(self) + root = scratch_dir(self) shutil.copyfile(REPO_ROOT / "install.py", root / "install.py") (root / "install.sh").write_text('DEFAULT_INSTALL_SHA256="' + "0" * 64 + '"\n') with self.assertRaises(ValueError): @@ -331,7 +323,7 @@ class TheScreens(unittest.TestCase): """Which screens the port shows, scenario by scenario.""" def run_port(self, scenario: str, answers: list[str], before=None, **env: str) -> list[tuple]: - work = _tempdir(self) + work = scratch_dir(self) (work / "install.py").write_text(FAKE_INSTALL) (work / "driver.sh").write_text(DRIVER) (work / "answers").write_text("".join(f"{a}\n" for a in answers)) @@ -526,7 +518,7 @@ class TheScreens(unittest.TestCase): def run_old(self, arch: str, **env: str) -> list[tuple]: """A python3 on PATH that is 3.7.3, ahead of every other.""" - holder = _tempdir(self) + holder = scratch_dir(self) fake = holder / "python3" fake.write_text('#!/bin/sh\n[ "$1" = "--version" ] && echo "Python 3.7.3"\nexit 1\n') fake.chmod(0o755) diff --git a/tests/test_proven_name.py b/tests/test_proven_name.py index 7a7c93f47..4e8318c97 100644 --- a/tests/test_proven_name.py +++ b/tests/test_proven_name.py @@ -83,8 +83,7 @@ class ProvenNameIndex(unittest.TestCase): class HashlessEntryTakesTheProvenDump(unittest.TestCase): def test_resolver_reads_the_index(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) diff --git a/tests/test_refresh_data_dirs.py b/tests/test_refresh_data_dirs.py index 337ae23e2..a07e3c9c1 100644 --- a/tests/test_refresh_data_dirs.py +++ b/tests/test_refresh_data_dirs.py @@ -47,8 +47,7 @@ class _Response(io.BytesIO): class RefreshConcurrency(unittest.TestCase): def setUp(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - self.tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self.tmp = tempfile.TemporaryDirectory() self.addCleanup(self.tmp.cleanup) self.root = Path(self.tmp.name) self.cache = self.root / "data" / "pak" @@ -218,7 +217,7 @@ class PackWalkHoldsTheCache(unittest.TestCase): import fcntl - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "data" / "sdlpal" cache.mkdir(parents=True) (cache / "a.mkf").write_bytes(b"a") @@ -242,7 +241,7 @@ class EmulatorPackHoldsTheCache(unittest.TestCase): from packs.datatrees import pack_data_tree - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "data" / "scummvm" cache.mkdir(parents=True) (cache / "a.dat").write_bytes(b"a") @@ -328,8 +327,7 @@ class TheManifestCarriesTheArchiveSize(unittest.TestCase): def test_recorded_size_is_written_and_an_unrecorded_one_left_out(self): from packs.datatrees import manifest_data_directories - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: data = Path(tmp) / "data" for ref in ("pak", "old"): (data / ref).mkdir(parents=True) @@ -358,8 +356,7 @@ class ASourceThatMovesIsPinnedOrFollowed(unittest.TestCase): def _listed(self, registry: dict, versions: dict) -> dict[str, dict]: from packs.datatrees import manifest_data_directories - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: data = Path(tmp) / "data" for ref, entry in registry.items(): (data / ref).mkdir(parents=True) @@ -390,8 +387,7 @@ class ASourceThatMovesIsPinnedOrFollowed(unittest.TestCase): self.assertIs(listed["unrecorded"]["rolling"], True) def test_a_branch_is_fetched_at_the_commit_it_records(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: versions = str(Path(tmp) / ".versions.json") entry = {"source_type": "zip", "version": "master", "strip_components": 1, "source_url": "https://github.com/o/r/archive/{version}.zip", diff --git a/tests/test_refresh_failures.py b/tests/test_refresh_failures.py index d2b9fec7d..3400fdaeb 100644 --- a/tests/test_refresh_failures.py +++ b/tests/test_refresh_failures.py @@ -200,9 +200,7 @@ class AnEmptyExtractionKeepsTheCache(unittest.TestCase): directory, recorded the version and reported success.""" def setUp(self): - scratch = Path(__file__).resolve().parent.parent / "tmp" - scratch.mkdir(exist_ok=True) - self.root = Path(tempfile.mkdtemp(dir=scratch)) + self.root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.root, True) self.cache = self.root / "cache" self.cache.mkdir() @@ -241,7 +239,7 @@ class TheVersionIsReadBeforeTheDownload(unittest.TestCase): def test_a_build_published_during_the_download(self): from packs import datadirs - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) state = {"downloaded": False} @@ -266,7 +264,7 @@ class ABadResponseIsTriedAgain(unittest.TestCase): failed the whole data step on it, and the next download was fine.""" def setUp(self) -> None: - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) self.versions = str(root / "versions.json") self.entry = {"source_type": "zip", "source_url": "https://example.invalid/S.zip", diff --git a/tests/test_refresh_stale.py b/tests/test_refresh_stale.py index d907dfcce..8264113a2 100644 --- a/tests/test_refresh_stale.py +++ b/tests/test_refresh_stale.py @@ -197,8 +197,7 @@ class Running(unittest.TestCase): self.assertEqual(order.read_text().split(), ["parent", "child"]) def test_the_report_prints_verify_after_a_rescrape(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as directory: + with tempfile.TemporaryDirectory() as directory: log = Path(directory) / "x.log" log.write_text( "$ python -m scripts.scraper.x_scraper\nscraped\n" @@ -243,7 +242,7 @@ class SavedFindings(unittest.TestCase): nightly job checks every area once and refreshes only some.""" def test_rows_outside_the_asked_areas_are_left_out(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory: + with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "freshness.json" path.write_text( '[{"area": "data", "subject": "dolphin-sys", "status": "STALE"},' @@ -259,7 +258,7 @@ class SavedFindings(unittest.TestCase): import json import subprocess - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory: + with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "freshness.json" path.write_text(json.dumps([ finding("catalogs", "mame recipes"), finding("coreinfo", "anybor"), @@ -286,7 +285,7 @@ class SavedFindings(unittest.TestCase): self.assertEqual((jobs, [f["subject"] for f in surfaced]), ([], ["muos"])) def test_a_report_that_is_not_a_list_is_refused(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" / "tests") as directory: + with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "freshness.json" path.write_text('{"area": "data"}', encoding="utf-8") with self.assertRaises(RuntimeError): diff --git a/tests/test_region.py b/tests/test_region.py index 825a99489..3cf5d1d4e 100644 --- a/tests/test_region.py +++ b/tests/test_region.py @@ -1012,7 +1012,7 @@ class EmulatorModeKeepsAHeldFile(unittest.TestCase): import shutil import tempfile - root = Path(tempfile.mkdtemp(dir=Path(__file__).resolve().parents[1] / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) held = root / "scph5501.bin" held.write_bytes(b"us bios") @@ -1315,9 +1315,7 @@ class ARefusedRegionalFileHoldsNoSlot(unittest.TestCase): from packs.emulatorcheck import verify_emulator emulator_profiles_cache.clear() - repo = Path(__file__).resolve().parents[1] - (repo / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=repo / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) diff --git a/tests/test_region_held.py b/tests/test_region_held.py index e1472cfe2..bf8c6a2f9 100644 --- a/tests/test_region_held.py +++ b/tests/test_region_held.py @@ -24,8 +24,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class ARefusedDumpHoldsNothing(unittest.TestCase): def test_held_follows_the_frontend(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) diff --git a/tests/test_release_packs.py b/tests/test_release_packs.py index 8864453d6..6e7b21ec3 100644 --- a/tests/test_release_packs.py +++ b/tests/test_release_packs.py @@ -34,7 +34,6 @@ from model import releaserecord REPO_ROOT = Path(__file__).resolve().parent.parent PLATFORMS = str(REPO_ROOT / "platforms") -TMP_ROOT = REPO_ROOT / "tmp" SITE = "https://abdess.github.io/retrobios/" # The owner's choice of 2026-10-23, from the download counts of v2026.10.10. RELEASED = {"retroarch", "emudeck", "retrobat", "batocera", "romm", "misterfpga"} @@ -68,7 +67,7 @@ class TheFieldIsTheList(unittest.TestCase): ) def test_only_marked_platforms_are_listed(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: platforms_dir = _write_registry(Path(tmp), { "big": {"release_pack": True}, "small": {}, @@ -132,7 +131,7 @@ class TheBuildReadsTheField(unittest.TestCase): def capture(args, groups, *rest, **kw): built.extend(name for group, _rep in groups for name in group) - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as out, \ + with tempfile.TemporaryDirectory() as out, \ contextlib.chdir(REPO_ROOT), \ mock.patch.object(generate_pack, "_run_platform_packs", capture), \ mock.patch.object(generate_pack, "_run_manifest_mode", capture), \ @@ -205,7 +204,7 @@ class APlatformWithoutAPackFailsNoCheck(unittest.TestCase): def test_verify_packs_sweeps_the_release_packs_only(self): import subprocess - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: proc = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--all", "--verify-packs", "--output-dir", directory], @@ -452,7 +451,7 @@ class TheReleaseNotesThankPeople(unittest.TestCase): import release_notes from release import notes - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: tmp = Path(tmp) (tmp / "whats-new.md").write_text("### What changed\n\n- x\n", encoding="utf-8") (tmp / "thanks.md").write_text("- **Code and data**: @habib256.\n", @@ -562,7 +561,7 @@ class TheSiteCheckResolvesEveryGetPage(unittest.TestCase): "platforms": ["romm"], "assets": ["RomM_BIOS_Pack.zip"], "files": 1, "extracted_size": 1, "download_size": 1}}} download = validate.RELEASE_DOWNLOAD - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) record_path = root / "release.json" record_path.write_text(json.dumps(record), encoding="utf-8") diff --git a/tests/test_required_only_archives.py b/tests/test_required_only_archives.py index 24327e43d..92339d2d4 100644 --- a/tests/test_required_only_archives.py +++ b/tests/test_required_only_archives.py @@ -22,7 +22,7 @@ class RequiredOnlyArchives(unittest.TestCase): def test_optional_archives_stay_out(self): if not (REPO_ROOT / "database.json").is_file(): self.skipTest("database.json not built") - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: result = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--emulator", "geolith", "--required-only", "--offline", "--output-dir", tmp], diff --git a/tests/test_retired_files.py b/tests/test_retired_files.py index 0b5e615a8..f67826116 100644 --- a/tests/test_retired_files.py +++ b/tests/test_retired_files.py @@ -54,7 +54,7 @@ class WhatLeftIsRecorded(unittest.TestCase): self.assertEqual(model_retired.merge(again, {}, self.old), {}) def test_generate_db_writes_it_beside_the_database(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: database = Path(tmp) / "database.json" path = model_retired.retired_path(database) self.assertEqual(path, Path(tmp) / "retired.json") diff --git a/tests/test_romm_hash_rule.py b/tests/test_romm_hash_rule.py index 013ff065d..26149605a 100644 --- a/tests/test_romm_hash_rule.py +++ b/tests/test_romm_hash_rule.py @@ -28,7 +28,7 @@ PAYLOAD = b"romm firmware" class SizeAndAnyHash(unittest.TestCase): def setUp(self): - scratch = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + scratch = tempfile.TemporaryDirectory() self.addCleanup(scratch.cleanup) self.path = str(Path(scratch.name) / "fw.bin") Path(self.path).write_bytes(PAYLOAD) diff --git a/tests/test_romset_recipes.py b/tests/test_romset_recipes.py index 487e6e381..ebc74a2f8 100644 --- a/tests/test_romset_recipes.py +++ b/tests/test_romset_recipes.py @@ -36,8 +36,7 @@ from core.hashing import git_blob_sha from core.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) +TMP_ROOT = Path(tempfile.gettempdir()) ROM_A = b"first rom payload" ROM_B = b"second rom payload" @@ -85,7 +84,7 @@ class RecipeCollection(unittest.TestCase): class PoolAndBuild(unittest.TestCase): def setUp(self): - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.bios = Path(self.temp.name) with zipfile.ZipFile(self.bios / "source.zip", "w") as archive: archive.writestr("a.rom", ROM_A) @@ -172,7 +171,7 @@ class ReportsOverAFixture(unittest.TestCase): """A whole run over a synthetic collection, database and platform.""" def setUp(self): - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.root = Path(self.temp.name) self.bios = self.root / "bios" self.bios.mkdir() @@ -334,7 +333,7 @@ class DatRecipes(unittest.TestCase): self.assertEqual(entries, []) def test_snapshot_round_trips_into_usable_recipes(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) snapshot = root / "romset-recipes.json" entries = recipe_entries(parse_logiqx(self._dat())) @@ -520,7 +519,7 @@ class ListXmlRecipes(unittest.TestCase): """A .variants/ copy stands for the name its tag is cut from.""" from scripts.scraper.romset_dat_importer import collection_archives, member_list - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as temp: + with tempfile.TemporaryDirectory() as temp: root = Path(temp) plain, variant = root / "set.zip", root / "other.zip.1a2b3c4d" for path in (plain, variant): @@ -568,7 +567,7 @@ class ListXmlRecipes(unittest.TestCase): self.assertTrue(holds_target([member], {(_crc(ROM_B), len(ROM_B)): {"a" * 40}})) def test_catalog_targets_leave_out_what_the_collection_holds(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: root = Path(directory) (root / "prov").mkdir() (root / "prov" / "tosec.json").write_text(json.dumps({"source": "tosec", "entries": [ @@ -588,7 +587,7 @@ class ListXmlRecipes(unittest.TestCase): "description": "", "members": [{"name": "a", "crc32": "1"}], } - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: output = str(Path(directory) / "fbneo.json") merge_snapshot(output, "fbneo", {"FBNeo - X": "1.0"}, [entry], {"X.dat": "aaa"}) with open(output, encoding="utf-8") as handle: @@ -619,7 +618,7 @@ class ListXmlRecipes(unittest.TestCase): def test_versions_accumulate_instead_of_replacing_each_other(self): """A platform pins the archive of whichever version it was built on.""" - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: output = str(Path(directory) / "romset-recipes.json") merge_snapshot( output, @@ -773,7 +772,7 @@ class IdentificationReadsTheDirectoryFirst(unittest.TestCase): rom = b"rom bytes" crc = format(zlib.crc32(rom), "08x") - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: archive = Path(tmp) / "set.zip" archive.write_bytes(build_torrentzip([("a.rom", rom)])) @@ -806,7 +805,7 @@ class BuildDigestsOutliveTheRun(unittest.TestCase): from unittest import mock - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: bios = Path(tmp) / "bios" bios.mkdir() with zipfile.ZipFile(bios / "source.zip", "w") as archive: @@ -855,7 +854,7 @@ class AnOversizedDatIsNamed(unittest.TestCase): from scripts.scraper.listxml import iter_dat_documents - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: pack = Path(directory) / "pack.zip" with zipfile.ZipFile(pack, "w") as archive: archive.writestr("big.dat", b"x" * 64) @@ -904,7 +903,7 @@ class FbneoFetchReadsOneRevision(unittest.TestCase): from scripts.scraper import romset_dat_importer as importer self.importer = importer - self._tmp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self._tmp = tempfile.TemporaryDirectory() self.dir = Path(self._tmp.name) self.calls: list[str] = [] self.served = FBNEO_DAT @@ -977,7 +976,7 @@ class LooseRomsAreAtoms(unittest.TestCase): its one ROM sat loose in bios/Arcade/FBNeo/nmk004.bin.""" def test_a_loose_file_completes_a_recipe(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + with tempfile.TemporaryDirectory() as directory: bios = Path(directory) / "bios" bios.mkdir() loose = bios / "nmk004.bin" diff --git a/tests/test_schema_semantic_gate.py b/tests/test_schema_semantic_gate.py index 187a1a24f..dd02a985a 100644 --- a/tests/test_schema_semantic_gate.py +++ b/tests/test_schema_semantic_gate.py @@ -147,9 +147,7 @@ class WithoutJsonschema(unittest.TestCase): import os import subprocess - scratch = REPO_ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(dir=scratch) as directory: + with tempfile.TemporaryDirectory() as directory: stub = Path(directory) / "jsonschema" stub.mkdir() (stub / "__init__.py").write_text( diff --git a/tests/test_scraper_contract.py b/tests/test_scraper_contract.py index 04f31aeca..89e86726c 100644 --- a/tests/test_scraper_contract.py +++ b/tests/test_scraper_contract.py @@ -994,7 +994,7 @@ class ImportingAScraperFetchesNothing(unittest.TestCase): self.assertEqual(self._offenders(REPO_ROOT, "scripts.scraper"), "") def test_a_swallowed_import_time_fetch_is_caught(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as directory: + with tempfile.TemporaryDirectory() as directory: package = Path(directory) / "planted" package.mkdir() (package / "__init__.py").write_text("") @@ -1013,7 +1013,7 @@ class ImportingAScraperFetchesNothing(unittest.TestCase): ) def test_an_import_time_fetch_is_caught(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as directory: + with tempfile.TemporaryDirectory() as directory: package = Path(directory) / "planted" package.mkdir() (package / "__init__.py").write_text("") diff --git a/tests/test_scraper_network.py b/tests/test_scraper_network.py index b36b6125f..29259135a 100644 --- a/tests/test_scraper_network.py +++ b/tests/test_scraper_network.py @@ -35,7 +35,6 @@ from scraper.base_scraper import ( ) REPO_ROOT = Path(__file__).resolve().parent.parent -TMP_ROOT = REPO_ROOT / "tmp" SHA = "0123456789abcdef0123456789abcdef01234567" @@ -143,7 +142,7 @@ class SourceRevisionReadsEveryShape(unittest.TestCase): self.assertEqual(scraped_revision(Path(tmp, "absent.yml")), "") def test_a_platform_without_a_revision_raises(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: path = Path(tmp, "p.yml") path.write_text("source: https://github.com/emulatorjs/emulatorjs\n") with self.assertRaises(RuntimeError): @@ -232,7 +231,7 @@ class GitHubAnswers(unittest.TestCase): class Downloads(unittest.TestCase): def test_written_whole_with_its_disposition(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: target = Path(tmp, "sub", "a.zip") with mock.patch("urllib.request.urlopen", _answer(503, b"payload")), \ mock.patch("time.sleep"): @@ -242,7 +241,7 @@ class Downloads(unittest.TestCase): self.assertEqual(sorted(p.name for p in target.parent.iterdir()), ["a.zip"]) def test_a_failure_leaves_nothing(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: target = Path(tmp, "a.zip") with mock.patch("urllib.request.urlopen", _answer(403)), \ self.assertRaises(FetchError): @@ -250,7 +249,7 @@ class Downloads(unittest.TestCase): self.assertEqual(list(Path(tmp).iterdir()), []) def test_an_existing_file_is_kept_when_asked(self): - with tempfile.TemporaryDirectory(dir=TMP_ROOT) as tmp: + with tempfile.TemporaryDirectory() as tmp: target = Path(tmp, "a.zip") target.write_bytes(b"cached") with mock.patch("urllib.request.urlopen", _answer(403)): diff --git a/tests/test_site_arcade_boards.py b/tests/test_site_arcade_boards.py index 95b490266..824ddc219 100644 --- a/tests/test_site_arcade_boards.py +++ b/tests/test_site_arcade_boards.py @@ -224,9 +224,7 @@ class BoardRules(unittest.TestCase): board, a machine's own set is no board, contents: rejects a homonym.""" def setUp(self) -> None: - tmp_root = REPO_ROOT / "tmp" - tmp_root.mkdir(exist_ok=True) - self._tmp = tempfile.TemporaryDirectory(dir=tmp_root) + self._tmp = tempfile.TemporaryDirectory() self.root = Path(self._tmp.name) systemnames.set_console_sections({("Arcade", "MAME"), ("SNK", "Neo Geo")}) diff --git a/tests/test_site_availability.py b/tests/test_site_availability.py index c8a042ce7..97b259d97 100644 --- a/tests/test_site_availability.py +++ b/tests/test_site_availability.py @@ -78,7 +78,7 @@ class AHeldEntrySaysWhere(unittest.TestCase): from sitegen import emulatorcards from packs.crossref import FileConsumers, held_copy - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: data, bios = Path(tmp) / "data", Path(tmp) / "bios" (data / "dolphin-sys" / "GC").mkdir(parents=True) (data / "dolphin-sys" / "GC" / "font_western.bin").write_bytes(b"font") diff --git a/tests/test_site_bootstrap.py b/tests/test_site_bootstrap.py index dd7266c20..37c34fe92 100644 --- a/tests/test_site_bootstrap.py +++ b/tests/test_site_bootstrap.py @@ -88,8 +88,7 @@ class ServedCopies(unittest.TestCase): self.assertEqual(sitebootstrap.build_commit(REPO_ROOT), self.commit) def test_the_copies_land_at_the_root_of_the_public_folder(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() - else None) as scratch: + with tempfile.TemporaryDirectory() as scratch: public = Path(scratch) / "public" written = sitebootstrap.write_bootstraps(public, REPO_ROOT, self.commit) self.assertEqual(sorted(p.name for p in written), ["i", "i.ps1"]) @@ -117,8 +116,7 @@ class ServedCopies(unittest.TestCase): def test_a_stale_pin_stops_the_build(self): """A pin that is not the installer's was served, and refused every install until the next good deploy.""" - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() - else None) as scratch: + with tempfile.TemporaryDirectory() as scratch: root = Path(scratch) for source in ("install.sh", "install.ps1"): (root / source).write_text((REPO_ROOT / source).read_text(encoding="utf-8"), @@ -143,8 +141,7 @@ class ServedCopies(unittest.TestCase): self.assertLess(check, upload) def test_a_bootstrap_without_its_address_line_stops_the_build(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() - else None) as scratch: + with tempfile.TemporaryDirectory() as scratch: root = Path(scratch) (root / "install.sh").write_text("#!/bin/sh\n", encoding="utf-8") with self.assertRaises(ValueError): diff --git a/tests/test_site_content_data.py b/tests/test_site_content_data.py index fb545ad9b..b7b66786b 100644 --- a/tests/test_site_content_data.py +++ b/tests/test_site_content_data.py @@ -43,7 +43,7 @@ def _guides_text() -> str: class GuidesLiveInYaml(unittest.TestCase): def _load(self, text: str, registry: dict | None = None) -> dict: - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "_guides.yml" path.write_text(text, encoding="utf-8") return load_guides(path, registry if registry is not None else _registry()) @@ -171,7 +171,7 @@ class NavFromFrontMatter(unittest.TestCase): self.assertEqual(tabs["Reference"][0], "wiki/index.md") def test_a_new_page_lands_in_its_tab_at_its_order(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wiki = _wiki_copy(tmp) (wiki / "save-files.md").write_text( "---\nlevel: start\norder: 45\n---\n\n# Save files\n\nText.\n", @@ -183,7 +183,7 @@ class NavFromFrontMatter(unittest.TestCase): self.assertIn({"Save files": "wiki/save-files.md"}, start) def test_a_page_without_a_level_fails_by_name(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wiki = _wiki_copy(tmp) (wiki / "orphan.md").write_text("# Orphan\n\nText.\n", encoding="utf-8") with self.assertRaisesRegex(sitegen_nav.NavError, @@ -191,7 +191,7 @@ class NavFromFrontMatter(unittest.TestCase): self._nav(wiki) def test_a_page_without_an_order_fails_by_name(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wiki = _wiki_copy(tmp) (wiki / "orphan.md").write_text( "---\nlevel: reference\n---\n\n# Orphan\n", encoding="utf-8") @@ -202,7 +202,7 @@ class NavFromFrontMatter(unittest.TestCase): self._nav(wiki) def test_two_pages_on_one_place_fail_naming_both(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wiki = _wiki_copy(tmp) (wiki / "twin.md").write_text( "---\nlevel: contribute\norder: 20\n---\n\n# Twin\n", encoding="utf-8") @@ -211,7 +211,7 @@ class NavFromFrontMatter(unittest.TestCase): self._nav(wiki) def test_nav_false_keeps_a_page_out(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wiki = _wiki_copy(tmp) (wiki / "hidden.md").write_text( "---\nlevel: start\nnav: false\n---\n\n# Hidden\n", encoding="utf-8") diff --git a/tests/test_site_emulator_page.py b/tests/test_site_emulator_page.py index 2db3185de..9dd1512d9 100644 --- a/tests/test_site_emulator_page.py +++ b/tests/test_site_emulator_page.py @@ -171,7 +171,7 @@ class WhatASearchSnippetSays(unittest.TestCase): import json import tempfile - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: page = Path(tmp) / "emulators" / "idtech4a++.md" page.parent.mkdir() page.write_text("# idTech4A++\n\nSome text long enough to be a description.\n") diff --git a/tests/test_site_emulators.py b/tests/test_site_emulators.py index e5294f697..22a396497 100644 --- a/tests/test_site_emulators.py +++ b/tests/test_site_emulators.py @@ -383,8 +383,7 @@ class DataDirectoryPagesStayOutOfSearch(unittest.TestCase): class AnElementBudget(unittest.TestCase): def test_validate_site_reports_a_crowded_page(self): self.assertEqual(validate.MAX_PAGE_ELEMENTS, 10_000) - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: page = Path(tmp) / "crowded" / "index.html" page.parent.mkdir() page.write_text("" + "" * 10_001 diff --git a/tests/test_site_exports.py b/tests/test_site_exports.py index 2beb0d381..31ff8c7b1 100644 --- a/tests/test_site_exports.py +++ b/tests/test_site_exports.py @@ -27,9 +27,7 @@ ROOT = Path(__file__).resolve().parent.parent class SiteReferenceContracts(unittest.TestCase): def setUp(self) -> None: - scratch = ROOT / "tmp" / "tests" - scratch.mkdir(parents=True, exist_ok=True) - self.temp = tempfile.TemporaryDirectory(dir=scratch) + self.temp = tempfile.TemporaryDirectory() self.docs = Path(self.temp.name) / "docs" self.docs.mkdir() @@ -713,7 +711,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase): body = b"approved inis\n" sha1 = hashlib.sha1(body).hexdigest() - with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: member = Path(tmp, "data", "dolphin-sys", "ApprovedInis.json") member.parent.mkdir(parents=True) member.write_bytes(body) @@ -771,7 +769,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase): self.assertEqual(found[("emulator", "duckstation", "crc32", "11223344")]["name"], "m.rom") self.assertNotIn(("emulator", "an-alias", "md5", md5), found) - with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: shards = lookup.write_lookup_shards(Path(tmp), records, "2026-01-01T00:00:00Z") folder = Path(tmp) / "lookup" names = sorted(path.name for path in folder.glob("*.json")) @@ -796,7 +794,7 @@ class AnArchiveMemberIsFoundByItsCrc(unittest.TestCase): from sitegen import lookup - with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) archive = root / "bios" / "Arcade" / "Arcade" / "a500.zip" archive.parent.mkdir(parents=True) @@ -930,7 +928,7 @@ class ACardNamesThePacksThatInstallIt(unittest.TestCase): from packs.crossref import FileConsumers from sitegen.cards import _installed_places - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: Path(tmp, "retrobat.json").write_text(_json.dumps({ "platform": "retrobat", "files": [{"dest": "scph5501.bin", "sha1": "b" * 40, @@ -1062,7 +1060,7 @@ class ADataDirectoryFileCanBeLookedUp(unittest.TestCase): from sitegen.lookup import data_directory_members, file_location_items - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: Path(tmp, "retroarch.json").write_text(_json.dumps({"data_directories": [ {"ref": "dolphin-sys", "files": {"GC/font.bin": {"sha1": "c" * 40, "size": 3}}}, ]})) @@ -1267,7 +1265,7 @@ class EveryPageLinksItsOwnData(unittest.TestCase): item = dataexports.system_export_item("sony", "Sony", {"PlayStation": [entry]}) self.assertEqual(item["consoles"]["PlayStation"][0]["sha1"], "a" * 40) - with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "sony.json" dataexports.write_single_item(path, "systems", item, "2026-10-21T00:00:00Z") document = json.loads(path.read_text()) diff --git a/tests/test_site_freshness.py b/tests/test_site_freshness.py index f9dc4ad76..3d1dee868 100644 --- a/tests/test_site_freshness.py +++ b/tests/test_site_freshness.py @@ -37,7 +37,7 @@ def _site(root: Path, words: str = "Words of the page.") -> Path: class BuildStamp(unittest.TestCase): def setUp(self): - self.tmp = tempfile.TemporaryDirectory(dir=ROOT / "tmp") + self.tmp = tempfile.TemporaryDirectory() self.dist = _site(Path(self.tmp.name)) pagemarkdown.convert_site(self.dist, STAMP) @@ -63,7 +63,7 @@ class BuildStamp(unittest.TestCase): def test_digests_ignore_the_build_line(self): first = json.loads((self.dist / "digests.json").read_text(encoding="utf-8")) - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as other: + with tempfile.TemporaryDirectory() as other: dist = _site(Path(other)) pagemarkdown.convert_site(dist, {"commit": "f" * 40, "date": "2026-11-10T00:00:00Z"}) second = json.loads((dist / "digests.json").read_text(encoding="utf-8")) @@ -83,7 +83,7 @@ class IndexNowList(unittest.TestCase): def test_the_key_is_served_where_the_request_says(self): body = indexnow.payload(["https://abdess.github.io/retrobios/"]) self.assertEqual(body["keyLocation"], "https://abdess.github.io/retrobios/indexnow.txt") - with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as public: + with tempfile.TemporaryDirectory() as public: written: dict[str, str] = {} siteagents.write(Path(public), [], lambda path, text: written.__setitem__(path, text)) self.assertEqual(written[str(Path(public) / "indexnow.txt")].strip(), body["key"]) diff --git a/tests/test_site_funnel.py b/tests/test_site_funnel.py index 2bd7fa746..547c2a111 100644 --- a/tests/test_site_funnel.py +++ b/tests/test_site_funnel.py @@ -186,7 +186,7 @@ class EveryPageHasALevel(unittest.TestCase): self.assertIn(f"{level}: '{label}'", component) def test_the_decoration_keeps_an_authored_level(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: page = Path(tmp) / "wiki" / "faq.md" page.parent.mkdir() page.write_text("---\nlevel: start\n---\n\n# FAQ\n\nQuestions people ask first.\n") diff --git a/tests/test_site_handheld.py b/tests/test_site_handheld.py index fc282c2f5..7eaf26dde 100644 --- a/tests/test_site_handheld.py +++ b/tests/test_site_handheld.py @@ -45,9 +45,7 @@ def _pages() -> dict[str, str]: class TheSiteServesTheLaunchers(unittest.TestCase): def setUp(self): - scratch = REPO_ROOT / "tmp" - scratch.mkdir(exist_ok=True) - self.tmp = Path(tempfile.mkdtemp(dir=scratch, prefix="site-handheld-")) + self.tmp = Path(tempfile.mkdtemp(prefix="site-handheld-")) self.addCleanup(shutil.rmtree, self.tmp, True) def test_the_written_archives_are_the_ones_build_port_writes(self): diff --git a/tests/test_site_inputs.py b/tests/test_site_inputs.py index 6b10232b2..71a8ff311 100644 --- a/tests/test_site_inputs.py +++ b/tests/test_site_inputs.py @@ -41,7 +41,7 @@ class _Inputs(unittest.TestCase): class TheGivenDatabase(_Inputs): def setUp(self) -> None: - tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() else None)) + tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, tmp) self.db = tmp / "database.json" self.db.write_text(json.dumps({"files": {SHA1: {"path": "bios/X/only-here.bin"}}})) @@ -58,7 +58,7 @@ class TheGivenDatabase(_Inputs): class TheGivenProfilesAndPlatforms(_Inputs): def setUp(self) -> None: - tmp = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() else None)) + tmp = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, tmp) self.emulators = tmp / "emulators" self.emulators.mkdir() @@ -103,7 +103,7 @@ class TheCollectionDoesNotDependOnTheWorkingDirectory(unittest.TestCase): db = json.loads((REPO_ROOT / "database.json").read_text(encoding="utf-8")) here = sitecollection.collection_paths(db) places = sitecollection.copy_places(db) - elsewhere = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() else None)) + elsewhere = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, elsewhere) cwd = os.getcwd() os.chdir(elsewhere) diff --git a/tests/test_site_nav.py b/tests/test_site_nav.py index bba586a9f..b85542ca3 100644 --- a/tests/test_site_nav.py +++ b/tests/test_site_nav.py @@ -255,8 +255,7 @@ class ReferenceGrouped(unittest.TestCase): self.assertEqual(reference[0], "wiki/index.md") def test_a_wiki_page_joins_a_group_from_its_front_matter(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wiki = Path(tmp) (wiki / "index.md").write_text("---\nlevel: reference\norder: 0\n---\n# Reference\n") (wiki / "modes.md").write_text( diff --git a/tests/test_site_picker.py b/tests/test_site_picker.py index 666b158e9..65f775f81 100644 --- a/tests/test_site_picker.py +++ b/tests/test_site_picker.py @@ -40,7 +40,7 @@ class PickerMatchesInstaller(unittest.TestCase): def setUp(self): from sitegen import starlight as sitestarlight - self.folder = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() else None) + self.folder = tempfile.TemporaryDirectory() self.out = Path(self.folder.name) self.count = sitestarlight.picker_data(REPO_ROOT / "install", self.out, {"sony-playstation": "Sony PlayStation"}) diff --git a/tests/test_site_reference.py b/tests/test_site_reference.py index 113773ff6..d7160b7ca 100644 --- a/tests/test_site_reference.py +++ b/tests/test_site_reference.py @@ -472,7 +472,7 @@ class BuiltBatoceraPage(unittest.TestCase): PUBLIC = REPO_ROOT / "website" / "public" API = PUBLIC / "api" / "v1" SITE = "https://abdess.github.io/retrobios/" -TMP = REPO_ROOT / "tmp" +TMP = Path(tempfile.gettempdir()) def _built(path: Path) -> Path: @@ -571,7 +571,7 @@ class AFolderCheckAgreesWithTheVerifier(unittest.TestCase): return contract, root def test_each_rule_on_a_sample_folder(self): - with tempfile.TemporaryDirectory(dir=TMP) as tmp: + with tempfile.TemporaryDirectory() as tmp: contract, root = self._folder(Path(tmp)) platforms = Path(tmp) / "platforms" platforms.mkdir() @@ -592,7 +592,7 @@ class AFolderCheckAgreesWithTheVerifier(unittest.TestCase): the collection.""" text = _built(PUBLIC / "downloads" / "platform-files.csv").read_text(encoding="utf-8") rows = [row for row in csv.DictReader(io.StringIO(text)) if row["platform_id"] == "batocera"] - with tempfile.TemporaryDirectory(dir=TMP) as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) for row in rows: source = REPO_ROOT / row["collection_path"] if row["collection_path"] else None @@ -1052,7 +1052,7 @@ class TheFolderCheckReadsEmuDecksWhitelist(unittest.TestCase): "md5": hashlib.md5(good).hexdigest()}, {"name": "sony-playstation:" + "0" * 32, "destination": "", "md5": "0" * 32}, ]}}} - with tempfile.TemporaryDirectory(dir=TMP) as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) / "bios" (root / "sub").mkdir(parents=True) for name, data in files.items(): @@ -1378,8 +1378,7 @@ class OneAnswerOnReleasePacks(unittest.TestCase): self.assertEqual(found, _released()) def test_the_picker_file_is_the_advertised_record(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir() - else None) as folder: + with tempfile.TemporaryDirectory() as folder: publish.write_release_advertised(Path(folder)) written = json.loads((Path(folder) / "release-advertised.json").read_text()) self.assertEqual(written, releaserecord.load_advertised()) diff --git a/tests/test_site_search.py b/tests/test_site_search.py index be1c672fc..62c4123c7 100644 --- a/tests/test_site_search.py +++ b/tests/test_site_search.py @@ -199,7 +199,7 @@ class PartPages(unittest.TestCase): "---\n\n# MAME files, part 3 of 8\n\nPart of [MAME](mame.md). " "This part holds 196 entries, `a.zip` to `b.zip`.\n" ) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "emulators" / "mame-files-3.md" path.parent.mkdir() path.write_text(page, encoding="utf-8") diff --git a/tests/test_site_system_links.py b/tests/test_site_system_links.py index 3a8eee934..d144fabad 100644 --- a/tests/test_site_system_links.py +++ b/tests/test_site_system_links.py @@ -134,7 +134,7 @@ class ACopyIsOnItsOwnFoldersPage(unittest.TestCase): def test_every_folder_holding_a_copy_lists_it(self): import tempfile - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: for rel in ("Arcade/FBNeo/sl31253.rom", "Fairchild/Channel F/sl31253.bin"): (Path(tmp) / rel).parent.mkdir(parents=True, exist_ok=True) (Path(tmp) / rel).write_bytes(b"x") @@ -203,7 +203,7 @@ class ACopyFiledByEmulatorDoesNotMoveAMachine(unittest.TestCase): def test_the_copy_under_the_declared_name_places_the_system(self): import tempfile - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: db = self._db(tmp) files = [{"name": "disksys.rom", "sha1": "d" * 40}] self.assertEqual( @@ -221,7 +221,7 @@ class ACopyFiledByEmulatorDoesNotMoveAMachine(unittest.TestCase): def test_an_id_that_spells_a_folder_links_to_it(self): import tempfile - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: db = self._db(tmp) manufacturers = collection.group_by_manufacturer(db) config = {"systems": {"nintendo-nes": {"files": [ diff --git a/tests/test_site_systems.py b/tests/test_site_systems.py index 84ef39b61..ae316a145 100644 --- a/tests/test_site_systems.py +++ b/tests/test_site_systems.py @@ -33,6 +33,7 @@ from __future__ import annotations import tests import re +import tempfile import types import unittest from pathlib import Path @@ -374,7 +375,7 @@ class TheBuiltSonyPage(unittest.TestCase): self.assertNotRegex(self.text, r'

]*>\s') -TMP = REPO_ROOT / "tmp" +TMP = Path(tempfile.gettempdir()) def _file_at(name: str, char: str, path: str) -> dict: @@ -520,7 +521,6 @@ class ArcadeSetsAreNamedWhereverFiled(unittest.TestCase): class CardsSayWhichReleaseTheSetMatches(unittest.TestCase): def setUp(self) -> None: - TMP.mkdir(exist_ok=True) self.path = TMP / "r3_systems_set.zip" with zipfile.ZipFile(self.path, "w") as archive: archive.writestr("sp-s2.sp1", b"bios") diff --git a/tests/test_site_validation.py b/tests/test_site_validation.py index b6fb601e4..b7a397ef1 100644 --- a/tests/test_site_validation.py +++ b/tests/test_site_validation.py @@ -14,8 +14,6 @@ from pathlib import Path from sitegen.validate import validate_site ROOT = Path(__file__).resolve().parent.parent -TMP_ROOT = ROOT / "tmp" / "tests" -TMP_ROOT.mkdir(parents=True, exist_ok=True) def _page(title: str, description: str, body: str = "") -> str: @@ -108,7 +106,7 @@ class PlatformDetails(unittest.TestCase): class RenderedSiteValidation(unittest.TestCase): def setUp(self) -> None: - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.root = Path(self.temp.name) self.site = self.root / "site" self.site.mkdir() @@ -188,7 +186,7 @@ class TheSiteStaysWithinItsBudgets(unittest.TestCase): validate_site now holds the gains, each limit with its reason.""" def setUp(self) -> None: - self.temp = tempfile.TemporaryDirectory(dir=TMP_ROOT) + self.temp = tempfile.TemporaryDirectory() self.site = Path(self.temp.name) / "site" self.site.mkdir() self.config = "/retrobios/" diff --git a/tests/test_split_extras.py b/tests/test_split_extras.py index 0ea27e6f7..e477a6eb1 100644 --- a/tests/test_split_extras.py +++ b/tests/test_split_extras.py @@ -29,7 +29,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent class SplitPartsCoverTheExtras(unittest.TestCase): def test_an_extra_of_an_undeclared_system_has_a_part(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) (root / "platforms").mkdir() (root / "emulators").mkdir() @@ -86,7 +86,7 @@ class SplitPartsHoldWhatTheFullPackHolds(unittest.TestCase): """ def _build(self, platform: dict, profiles: dict[str, dict], blobs: dict[str, bytes]): - tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + tmp = tempfile.TemporaryDirectory() self.addCleanup(tmp.cleanup) root = Path(tmp.name) (root / "platforms").mkdir() diff --git a/tests/test_system_pack_parity.py b/tests/test_system_pack_parity.py index 7a669d51b..b6a04d747 100644 --- a/tests/test_system_pack_parity.py +++ b/tests/test_system_pack_parity.py @@ -41,7 +41,7 @@ class SystemPackMatchesVerify(unittest.TestCase): def setUp(self): if not (REPO_ROOT / "database.json").exists(): self.skipTest("database.json is not generated") - self.out = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + self.out = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, self.out, True) def test_the_same_files_are_missing(self): diff --git a/tests/test_system_selection.py b/tests/test_system_selection.py index 16496c163..a8c425845 100644 --- a/tests/test_system_selection.py +++ b/tests/test_system_selection.py @@ -118,7 +118,7 @@ class AMistypedPlatformIsNamed(unittest.TestCase): } def test_every_cli_names_the_platform_it_meant(self): - scratch = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + scratch = tempfile.TemporaryDirectory() self.addCleanup(scratch.cleanup) out = Path(scratch.name) / "packs" writers = { @@ -220,7 +220,7 @@ class AMissingDatabaseIsNamed(unittest.TestCase): ) def test_every_script_names_the_missing_file(self): - scratch = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + scratch = tempfile.TemporaryDirectory() self.addCleanup(scratch.cleanup) out = str(Path(scratch.name) / "out") for script in self._taking_db(): @@ -249,7 +249,7 @@ class AMissingBiosDirIsRefused(unittest.TestCase): } def test_every_script_taking_a_bios_dir_refuses_a_missing_one(self): - scratch = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + scratch = tempfile.TemporaryDirectory() self.addCleanup(scratch.cleanup) out = str(Path(scratch.name) / "out") taking = sorted( @@ -306,7 +306,7 @@ class AMissingProfileDirIsRefused(unittest.TestCase): } def test_every_script_taking_an_emulators_dir_refuses_a_missing_one(self): - scratch = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + scratch = tempfile.TemporaryDirectory() self.addCleanup(scratch.cleanup) root = Path(scratch.name) (root / "cache").mkdir() @@ -364,7 +364,7 @@ class AMissingPlatformsDirIsRefused(unittest.TestCase): } def test_every_script_taking_a_platforms_dir_refuses_a_missing_one(self): - scratch = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + scratch = tempfile.TemporaryDirectory() self.addCleanup(scratch.cleanup) root = Path(scratch.name) (root / "empty.dat").write_bytes(b"") @@ -423,7 +423,7 @@ class AMissingInputFileIsNamed(unittest.TestCase): self.assertIn(message, proc.stderr) def test_a_missing_hash_list_is_named(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: self._refused( ["scripts/generate_pack.py", "--platform", "batocera", "--from-md5-file", "nosuch.txt", "--offline", "--output-dir", tmp], @@ -513,7 +513,7 @@ class StrictVerifyFailsOnACriticalMiss(unittest.TestCase): the pipeline printed "verify OK" over a pack the frontend rejects.""" def test_strict_exits_nonzero_and_plain_does_not(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) (root / "plat").mkdir() (root / "emu").mkdir() @@ -632,8 +632,7 @@ class ASystemPackHoldsThatSystem(unittest.TestCase): from packs.emulatorcheck import verify_system emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) @@ -686,8 +685,7 @@ class ATreeHoldsAPathForAnotherProfile(unittest.TestCase): from packs.emulatorcheck import verify_emulator emulator_profiles_cache.clear() - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp")) + root = Path(tempfile.mkdtemp()) self.addCleanup(shutil.rmtree, root, True) previous = os.getcwd() os.chdir(root) diff --git a/tests/test_target_names.py b/tests/test_target_names.py index ef2f5d220..9a1631583 100644 --- a/tests/test_target_names.py +++ b/tests/test_target_names.py @@ -91,8 +91,7 @@ class TheBuilderNamesByTheCanonicalTarget(unittest.TestCase): def test_an_alias_writes_the_canonical_manifest(self): if not (REPO_ROOT / "database.json").exists(): self.skipTest("database.json is not built") - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out: + with tempfile.TemporaryDirectory() as out: proc = subprocess.run( [sys.executable, "scripts/generate_pack.py", "--platform", "retroarch", "--target", "nx", "--manifest", "--offline", "--output-dir", out], diff --git a/tests/test_target_verify.py b/tests/test_target_verify.py index 7f2a9cac7..154ef08ea 100644 --- a/tests/test_target_verify.py +++ b/tests/test_target_verify.py @@ -149,7 +149,7 @@ class ASplitBuildsOnlyTheTargetsSystems(unittest.TestCase): asked.append(kw["system_filter"]) return - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out, \ + with tempfile.TemporaryDirectory() as out, \ mock.patch.object(platformpack, "generate_pack", record), \ mock.patch.object(platformpack, "collect_emulator_extras", return_value=[]), \ mock.patch.object(manifest, "collect_emulator_extras", return_value=[]): @@ -225,7 +225,7 @@ class TheSplitDirectoryReadsThePackStem(unittest.TestCase): from packs import platformpack as packs_platformpack config = {"platform": "Foo: Bar", "version": "release/1.22", "systems": {}} - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as out, \ + with tempfile.TemporaryDirectory() as out, \ mock.patch.object(packs_platformpack, "load_platform_config", return_value=config), \ mock.patch.object(naming, "load_platform_config", return_value=config), \ mock.patch.object(manifest, "load_platform_config", return_value=config), \ diff --git a/tests/test_tool_messages.py b/tests/test_tool_messages.py index 689bea2d4..664c25f31 100644 --- a/tests/test_tool_messages.py +++ b/tests/test_tool_messages.py @@ -95,7 +95,7 @@ class AMistypedTargetGetsTheClosestName(unittest.TestCase): """`--target swich` printed every target and alias on two lines.""" def test_did_you_mean(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: targets = Path(tmp) / "targets" targets.mkdir() names = [f"board-{n}" for n in range(30)] + ["nintendo-switch"] @@ -144,7 +144,7 @@ class ADamagedProfileNamesItself(unittest.TestCase): faulty file named near its end.""" def test_one_line_names_the_file_and_line(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as folder: + with tempfile.TemporaryDirectory() as folder: profiles = Path(folder) (profiles / "handy.yml").write_text( (REPO_ROOT / "emulators" / "handy.yml").read_text(encoding="utf-8"), @@ -252,7 +252,7 @@ class ReadOnlyToolsRunFromAnyFolder(unittest.TestCase): ) def test_each_reads_the_repository_from_a_subfolder(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as folder: + with tempfile.TemporaryDirectory() as folder: for command in self.COMMANDS: with self.subTest(command=command[0]): proc = subprocess.run( @@ -266,7 +266,7 @@ class ReadOnlyToolsRunFromAnyFolder(unittest.TestCase): self.assertEqual(os.listdir(folder), []) def test_a_typed_path_is_read_from_where_it_was_typed(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as folder: + with tempfile.TemporaryDirectory() as folder: proc = subprocess.run( [sys.executable, str(REPO_ROOT / "scripts" / "slots.py"), "--db", "nosuch.json"], @@ -371,7 +371,7 @@ class AnOfflineRunWithNoCacheStopsFirst(unittest.TestCase): return argparse.Namespace(**{"offline": True, "skip_packs": False, **flags}) def test_refused_before_any_step(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "cache" (Path(tmp) / "_data_dirs.yml").write_text( f"data_directories:\n a:\n local_cache: {cache}\n" @@ -405,7 +405,7 @@ class AnOfflineExportWithNoOriginalsStopsFirst(unittest.TestCase): patched = sorted(n for n, e in discover_exporters().items() if e.needs_original()) self.assertIn("batocera", patched) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: parser = mock.Mock() pipeline._refuse_offline_export_without_originals(parser, self._args(), tmp) message = parser.error.call_args.args[0] @@ -988,7 +988,7 @@ class CitedCommandsRunWhenPasted(unittest.TestCase): self.assertEqual(offenders, []) def test_the_target_hint_is_a_whole_command(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: targets = Path(tmp) / "targets" targets.mkdir() (targets / "p.yml").write_text("targets:\n switch:\n cores: [a]\n") diff --git a/tests/test_torrentzip.py b/tests/test_torrentzip.py index 57e32c495..bc4188e9a 100644 --- a/tests/test_torrentzip.py +++ b/tests/test_torrentzip.py @@ -197,7 +197,7 @@ class CheckModeExitCode(unittest.TestCase): def test_the_exit_code_follows_conformance(self): import subprocess - with tempfile.TemporaryDirectory(dir=os.path.join(REPO_ROOT, "tmp")) as directory: + with tempfile.TemporaryDirectory() as directory: plain = os.path.join(directory, "plain.zip") with zipfile.ZipFile(plain, "w") as zf: zf.writestr("a.bin", b"rom") diff --git a/tests/test_truth_data_dir_readers.py b/tests/test_truth_data_dir_readers.py index b4cec1dd0..06e174954 100644 --- a/tests/test_truth_data_dir_readers.py +++ b/tests/test_truth_data_dir_readers.py @@ -33,7 +33,7 @@ def _profile(name: str, **fields) -> dict: class DataDirectoryReaders(unittest.TestCase): def setUp(self): - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self.addCleanup(self._tmp.cleanup) root = Path(self._tmp.name) for tree, content in (("lrps2", TREE_COPY), ("resources", TREE_COPY)): diff --git a/tests/test_truth_diff.py b/tests/test_truth_diff.py index a4e72e733..8eda46783 100644 --- a/tests/test_truth_diff.py +++ b/tests/test_truth_diff.py @@ -35,7 +35,7 @@ class ATargetedModelIsItsOwnArtifact(unittest.TestCase): def test_a_target_writes_beside_the_full_model(self): repo = pathlib.Path(__file__).resolve().parent.parent - with tempfile.TemporaryDirectory(dir=str(repo / "tmp")) as directory: + with tempfile.TemporaryDirectory() as directory: for extra in ([], ["--target", "browser"]): proc = subprocess.run( [sys.executable, "scripts/generate_truth.py", "--platform", @@ -58,7 +58,7 @@ class ATargetedModelIsItsOwnArtifact(unittest.TestCase): """bizhawk --target switch printed "skipped", then Done., exit 0, and wrote no model: the diff after it failed instead.""" repo = pathlib.Path(__file__).resolve().parent.parent - with tempfile.TemporaryDirectory(dir=str(repo / "tmp")) as directory: + with tempfile.TemporaryDirectory() as directory: proc = subprocess.run( [sys.executable, "scripts/generate_truth.py", "--platform", "bizhawk", "--target", "switch", "--output-dir", directory], @@ -75,7 +75,7 @@ class ADiffThatComparedNothingFails(unittest.TestCase): def test_an_empty_truth_directory_is_an_error(self): repo = pathlib.Path(__file__).resolve().parent.parent - with tempfile.TemporaryDirectory(dir=str(repo / "tmp")) as directory: + with tempfile.TemporaryDirectory() as directory: for selection in (["--all"], ["--platform", "retroarch"]): proc = subprocess.run( [sys.executable, "scripts/diff_truth.py", *selection, diff --git a/tests/test_twin_declaration_status.py b/tests/test_twin_declaration_status.py index 71a40cd79..70ced4db2 100644 --- a/tests/test_twin_declaration_status.py +++ b/tests/test_twin_declaration_status.py @@ -36,7 +36,7 @@ SHA1 = hashlib.sha1(PAYLOAD).hexdigest() class TwinDeclarationStatus(unittest.TestCase): def setUp(self): - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self._cwd = os.getcwd() os.chdir(self._tmp.name) for d in ("emulators", "platforms", "bios/Twin"): diff --git a/tests/test_validate_pr_flow.py b/tests/test_validate_pr_flow.py index 47cf6a193..dfc052ac8 100644 --- a/tests/test_validate_pr_flow.py +++ b/tests/test_validate_pr_flow.py @@ -183,7 +183,7 @@ class AnUnfetchedUpstreamIsFetched(unittest.TestCase): subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True, text=True) def test_the_branch_file_is_found(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) project = root / "Abdess" / "retrobios.git" fork = root / "fork.git" diff --git a/tests/test_validated_choice.py b/tests/test_validated_choice.py index 07717e359..f66f0115f 100644 --- a/tests/test_validated_choice.py +++ b/tests/test_validated_choice.py @@ -24,7 +24,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent class ValidatedChoice(unittest.TestCase): def test_a_rejected_file_gives_way_to_an_accepted_variant(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wrong = Path(tmp) / "ps2" / "ROM2.BIN" right = Path(tmp) / "galaksija" / "ROM2.BIN" wrong.parent.mkdir() @@ -68,7 +68,7 @@ class ValidatedChoice(unittest.TestCase): } index = build_validation_index(profiles) owners = destination_owners(profiles) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: rom = Path(tmp) / "cpc6128.rom" rom.write_bytes(b"c" * 32768) db = {"files": {}, "indexes": {"by_name": {}, "by_md5": {}}} @@ -201,7 +201,7 @@ class EachReaderJudgesWithItsOwnRules(unittest.TestCase): "cemu": {"files": [{"name": "otp.bin", "path": "Cemu/otp.bin", "size": 1024, "validation": ["size"]}]}, }) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: wiiu = Path(tmp) / "otp.bin" wiiu.write_bytes(b"w" * 1024) self.assertIsNone(check_file_validation(str(wiiu), "otp.bin", index, tmp, {"cemu"})) @@ -214,7 +214,7 @@ class EachReaderJudgesWithItsOwnRules(unittest.TestCase): {"name": "SW.GRP", "size": 100, "validation": ["size"]}, {"name": "SW.GRP", "size": 200, "validation": ["size"]}, ]}}) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: grp = Path(tmp) / "SW.GRP" grp.write_bytes(b"s" * 200) self.assertIsNone(check_file_validation(str(grp), "SW.GRP", index, tmp, {"raze"})) @@ -272,7 +272,7 @@ class AWarningRejectsNothing(unittest.TestCase): return short, good, db, index def test_the_core_runs_a_file_that_only_warns(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: short, _good, db, index = self._setup(tmp, held_good=False) chosen, disagreement = validated_choice( {"name": "OS12.rom"}, str(short), db, index, tmp, None, emulators={"beebem"} @@ -280,7 +280,7 @@ class AWarningRejectsNothing(unittest.TestCase): self.assertEqual((chosen, disagreement), (str(short), None)) def test_a_file_passing_the_warned_check_is_preferred(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: short, good, db, index = self._setup(tmp, held_good=True) chosen, disagreement = validated_choice( {"name": "OS12.rom"}, str(short), db, index, tmp, None, emulators={"beebem"} @@ -290,7 +290,7 @@ class AWarningRejectsNothing(unittest.TestCase): def test_the_merged_view_rejects_nothing_for_it(self): from resolve.validation import check_file_validation - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: short, _good, _db, index = self._setup(tmp, held_good=False) self.assertIsNone(check_file_validation(str(short), "OS12.rom", index, tmp)) @@ -346,7 +346,7 @@ class AVersionTakenWithoutACheck(unittest.TestCase): from resolve.validation import check_file_validation index = build_validation_index({"raze": self.RAZE}) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: self.assertIsNone(check_file_validation( self._file(tmp), "BLOOD.RFF", index, emulators={"raze"} )) @@ -355,7 +355,7 @@ class AVersionTakenWithoutACheck(unittest.TestCase): from packs import platformpack fe = {"name": "BLOOD.RFF", "source_profile": "raze", "source_path": "BLOOD.RFF"} - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: self.assertTrue(platformpack._matches_an_alternative( fe, self._file(tmp), {"raze": self.RAZE} )) @@ -365,7 +365,7 @@ class AVersionTakenWithoutACheck(unittest.TestCase): checked = {"files": self.RAZE["files"][:2]} index = build_validation_index({"raze": checked}) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: reason, emulators = check_file_validation( self._file(tmp), "BLOOD.RFF", index, emulators={"raze"} ) diff --git a/tests/test_verify_all_dir.py b/tests/test_verify_all_dir.py index 001d5a0d7..3e9b0d376 100644 --- a/tests/test_verify_all_dir.py +++ b/tests/test_verify_all_dir.py @@ -21,8 +21,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1] class AllReadsTheGivenDirectory(unittest.TestCase): def test_only_the_directory_platforms(self): - (REPO_ROOT / "tmp").mkdir(exist_ok=True) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: plat = Path(tmp) (plat / "_registry.yml").write_text( "platforms:\n solo:\n config: solo.yml\n" diff --git a/tests/test_verify_data_dir_notice.py b/tests/test_verify_data_dir_notice.py index b71776c2d..a200b6ed9 100644 --- a/tests/test_verify_data_dir_notice.py +++ b/tests/test_verify_data_dir_notice.py @@ -27,7 +27,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent class UncachedDataDirectoryNotice(unittest.TestCase): def setUp(self): - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self._cwd = os.getcwd() os.chdir(self._tmp.name) Path("emulators").mkdir() diff --git a/tests/test_verify_listing.py b/tests/test_verify_listing.py index cad14cf56..9f9acb717 100644 --- a/tests/test_verify_listing.py +++ b/tests/test_verify_listing.py @@ -140,7 +140,7 @@ class ExistenceReportsWhatThePackReports(unittest.TestCase): from packs import verdicts - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "aes.zip" path.write_bytes(b"local dump") entry = {"name": "aes.zip", "md5": "9d2ff2333e23910cf56f7f785609d36a"} diff --git a/tests/test_verify_pack_choice.py b/tests/test_verify_pack_choice.py index d2745af43..386c7d4cf 100644 --- a/tests/test_verify_pack_choice.py +++ b/tests/test_verify_pack_choice.py @@ -33,7 +33,7 @@ class VerifyPackChoice(unittest.TestCase): previous = os.getcwd() os.chdir(REPO_ROOT) self.addCleanup(os.chdir, previous) - self.tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self.tmp = tempfile.TemporaryDirectory() self.addCleanup(self.tmp.cleanup) self.out = Path(self.tmp.name) self.db = self.out / "db.json" @@ -182,7 +182,7 @@ class GroupRenameKeepsSystemTag(unittest.TestCase): previous = os.getcwd() os.chdir(REPO_ROOT) self.addCleanup(os.chdir, previous) - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: def fake_generate(*a, pack_name=None, **kw): # The group's name is handed in: nothing is renamed afterwards. built = Path(tmp) / ( diff --git a/tests/test_verify_release_asset.py b/tests/test_verify_release_asset.py index 903235542..fa7084132 100644 --- a/tests/test_verify_release_asset.py +++ b/tests/test_verify_release_asset.py @@ -45,7 +45,7 @@ class ReleaseAssetNotCached(unittest.TestCase): mode = "existence" def setUp(self): - self._tmp = tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") + self._tmp = tempfile.TemporaryDirectory() self._cwd = os.getcwd() os.chdir(self._tmp.name) for d in ("emulators", "platforms", "bios/Big"): diff --git a/tests/test_zipped_member.py b/tests/test_zipped_member.py index 0db7b559f..8083a4b0c 100644 --- a/tests/test_zipped_member.py +++ b/tests/test_zipped_member.py @@ -24,7 +24,7 @@ REPO_ROOT = Path(__file__).resolve().parent.parent class ZippedMemberIsChecked(unittest.TestCase): def test_an_archive_without_the_member_is_not_shipped(self): - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) (root / "platforms").mkdir() archive = root / "bios" / "trs80.zip" @@ -101,7 +101,7 @@ class TheMemberIndexIsCachedByContent(unittest.TestCase): from core import ziptools - with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp: + with tempfile.TemporaryDirectory() as tmp: archive = Path(tmp) / "set.zip" with zipfile.ZipFile(archive, "w") as zf: zf.writestr("small.rom", b"a" * 16)