mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-23 20:29:06 -05:00
fix: read validate_pr data from the repo root
Run from another directory, validate_pr.py read no database, platform or profile and reported every file as referenced by no platform and outside bios/. It now moves to the root as verify.py does, reading the files named from where they were typed.
This commit is contained in:
1 parent
d63c881648
commit
ec1001de95
3 files changed
+45
-1
No files matched your search
@@ -512,6 +512,16 @@ def main() -> None:
|
||||
output.add_argument("--json", action="store_true", help="Output as JSON")
|
||||
args = parser.parse_args()
|
||||
|
||||
# The database, platforms and profiles are read from the repository
|
||||
# root. Run from elsewhere, every file read as referenced by no platform
|
||||
# and placed outside bios/. The files named are read from where they
|
||||
# were typed.
|
||||
from verify import REPO_ROOT, work_from_repo_root
|
||||
|
||||
if os.path.realpath(os.getcwd()) != os.path.realpath(REPO_ROOT):
|
||||
args.files = [os.path.abspath(f) for f in args.files]
|
||||
work_from_repo_root(args, parser, ["db", "platforms_dir", "emulators_dir"])
|
||||
|
||||
files = _files_to_validate(args, parser)
|
||||
if not files:
|
||||
if args.json:
|
||||
|
||||
@@ -30,8 +30,15 @@ class GitThatCannotAnswer(unittest.TestCase):
|
||||
# TMPDIR may lie inside this repository (the audit gate puts it in
|
||||
# tmp/): git must not find the enclosing work tree from there.
|
||||
env = dict(os.environ, GIT_CEILING_DIRECTORIES=str(Path(tmp).parent))
|
||||
# The script moves to its own checkout first: kept here, it stands
|
||||
# for a copy of scripts/ that no repository holds.
|
||||
proc = subprocess.run(
|
||||
[sys.executable, str(REPO_ROOT / "scripts" / "validate_pr.py"), "--changed"],
|
||||
[sys.executable, "-c", (
|
||||
f"import sys; sys.path.insert(0, {str(REPO_ROOT / 'scripts')!r}); "
|
||||
"import verify; verify.work_from_repo_root = lambda *a: None; "
|
||||
"import validate_pr; sys.argv = ['validate_pr.py', '--changed']; "
|
||||
"validate_pr.main()"
|
||||
)],
|
||||
cwd=tmp, env=env, capture_output=True, text=True, timeout=60, check=False,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr)
|
||||
|
||||
@@ -7,7 +7,9 @@ cannot hold has to be an action the contributor can take.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -119,5 +121,30 @@ class OversizedFileAdvice(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class RunFromAnyDirectory(unittest.TestCase):
|
||||
"""database.json, platforms/ and emulators/ were read from the current
|
||||
directory. Run from elsewhere, scph5501.bin came back referenced by no
|
||||
platform and not under bios/, with rc 0."""
|
||||
|
||||
def test_the_report_is_the_one_the_root_gives(self):
|
||||
path = REPO_ROOT / "bios" / "Sony" / "PlayStation" / "scph5501.bin"
|
||||
self.assertTrue(path.is_file(), path)
|
||||
reports = {}
|
||||
with tempfile.TemporaryDirectory() as elsewhere:
|
||||
for cwd, arg in ((REPO_ROOT, "bios/Sony/PlayStation/scph5501.bin"),
|
||||
(Path(elsewhere), str(path))):
|
||||
proc = subprocess.run(
|
||||
[sys.executable, str(REPO_ROOT / "scripts" / "validate_pr.py"),
|
||||
"--json", arg],
|
||||
cwd=cwd, capture_output=True, text=True, timeout=120, check=False,
|
||||
)
|
||||
self.assertEqual(proc.returncode, 0, proc.stderr)
|
||||
reports[cwd == REPO_ROOT] = json.loads(proc.stdout)[0]["checks"]
|
||||
self.assertEqual(reports[False], reports[True])
|
||||
messages = [c["message"] for c in reports[False]]
|
||||
self.assertIn("SHA1 matches known platform requirement", messages)
|
||||
self.assertIn("Already in the database at this path", messages)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user