diff --git a/scripts/common.py b/scripts/common.py index 1a3fbe51..1518f387 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -59,12 +59,12 @@ def load_database(db_path: str) -> dict: except FileNotFoundError: raise DatabaseUnreadable( f"{db_path} not found. Build it with: python scripts/generate_db.py " - "--force --bios-dir bios --output database.json" + f"--force --bios-dir bios --output {db_path}" ) from None except json.JSONDecodeError as exc: raise DatabaseUnreadable( f"{db_path} is not valid JSON ({exc}). Rebuild it with: " - "python scripts/generate_db.py --force --bios-dir bios --output database.json" + f"python scripts/generate_db.py --force --bios-dir bios --output {db_path}" ) from None diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index eab09149..dc0f0790 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -5132,5 +5132,23 @@ class StrictFailsOnMissingOnly(unittest.TestCase): self.assertNotIn("or rejected", verify_mod._exit_if_strict.__doc__) +class TheRepairCommandWritesTheFileNamed(unittest.TestCase): + """--db nosuch.json said to rebuild with --output database.json: the + command wrote another file and the next run failed the same way.""" + + def test_the_command_names_the_path(self): + from scripts.common import DatabaseUnreadable, load_database + + with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + target = str(Path(directory) / "nosuch.json") + with self.assertRaises(DatabaseUnreadable) as caught: + load_database(target) + self.assertIn(f"--output {target}", str(caught.exception)) + Path(target).write_text("{") + with self.assertRaises(DatabaseUnreadable) as caught: + load_database(target) + self.assertIn(f"--output {target}", str(caught.exception)) + + if __name__ == "__main__": unittest.main()