mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-06 10:03:49 -06:00
fix: validate_schemas names its jsonschema install
Without jsonschema the documented command stopped on an ImportError traceback. Run as a command it now prints the install pipeline.py names for the same step, with the format-nongpl extra, and exits 1. An import from the tests still raises ImportError, which they skip on.
This commit is contained in:
1 parent
54eac3b2df
commit
9f3f1cec3b
2 files changed
+35
-1
No files matched your search
@@ -14,7 +14,15 @@ from pathlib import Path, PurePosixPath
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from common import source_yaml_paths, yaml_load
|
from common import source_yaml_paths, yaml_load
|
||||||
from jsonschema import Draft202012Validator, FormatChecker
|
|
||||||
|
try:
|
||||||
|
from jsonschema import Draft202012Validator, FormatChecker
|
||||||
|
except ImportError:
|
||||||
|
# Tests import this module and skip on the ImportError, the command
|
||||||
|
# names the install pipeline.py names for the same step.
|
||||||
|
if __name__ != "__main__":
|
||||||
|
raise
|
||||||
|
sys.exit('Error: jsonschema required (pip install "jsonschema[format-nongpl]")')
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parent.parent
|
ROOT = Path(__file__).resolve().parent.parent
|
||||||
SCHEMAS = ROOT / "schemas"
|
SCHEMAS = ROOT / "schemas"
|
||||||
|
|||||||
@@ -120,5 +120,31 @@ class DataRootIsKeyedBySystem(unittest.TestCase):
|
|||||||
self.assertTrue(self._errors({}))
|
self.assertTrue(self._errors({}))
|
||||||
|
|
||||||
|
|
||||||
|
class WithoutJsonschema(unittest.TestCase):
|
||||||
|
"""The documented command stopped on a bare ImportError traceback that
|
||||||
|
named neither the install nor the format-nongpl extra."""
|
||||||
|
|
||||||
|
def test_the_command_names_the_install(self):
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
scratch = REPO_ROOT / "tmp" / "tests"
|
||||||
|
scratch.mkdir(parents=True, exist_ok=True)
|
||||||
|
with tempfile.TemporaryDirectory(dir=scratch) as directory:
|
||||||
|
stub = Path(directory) / "jsonschema"
|
||||||
|
stub.mkdir()
|
||||||
|
(stub / "__init__.py").write_text(
|
||||||
|
'raise ImportError("No module named jsonschema")\n', encoding="utf-8"
|
||||||
|
)
|
||||||
|
env = {**os.environ, "PYTHONPATH": directory}
|
||||||
|
proc = subprocess.run(
|
||||||
|
[sys.executable, "scripts/validate_schemas.py", "--source-only"],
|
||||||
|
capture_output=True, text=True, check=False, cwd=REPO_ROOT, env=env,
|
||||||
|
)
|
||||||
|
self.assertEqual(proc.returncode, 1)
|
||||||
|
self.assertNotIn("Traceback", proc.stderr)
|
||||||
|
self.assertIn('pip install "jsonschema[format-nongpl]"', proc.stderr)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user