diff options
| author | Eli Schwartz <eschwartz93@gmail.com> | 2023-12-05 20:33:38 -0500 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-12-10 19:02:39 -0500 |
| commit | 17c6d5eb478386ad183fa7e11b688217645d8f4f (patch) | |
| tree | 9665d76103b8b9405b4aeb65e174a60a368533d7 /unittests/internaltests.py | |
| parent | 5883089f6c7b39726dd06a48a23d8eb8754a75f7 (diff) | |
| download | meson-17c6d5eb478386ad183fa7e11b688217645d8f4f.tar.gz | |
unittests: migrate from jsonschema to fastjsonschema
The former has rust dependencies, which lead to max capping on Cygwin
since there is no rust compiler there. But it turns out there are other
disadvantages of jsonschema:
- it involves installing 5 wheels, instead of just 1
- it is much slower
To give some perspective to the latter issue, this is what it looks like
when I test with jsonschema:
```
===== 1 passed, 509 deselected in 3.07s =====
Total time: 3.341 seconds
```
And here's what it looks like when I test with fastjsonschema:
```
===== 1 passed, 509 deselected, 1 warning in 0.28s =====
Total time: 0.550 seconds
```
I cannot think of a good reason to use the former. Although in order to
work on old CI images, we'll support it as a fallback mechanism
Diffstat (limited to 'unittests/internaltests.py')
| -rw-r--r-- | unittests/internaltests.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 1c55b2976..66bf4586c 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1012,19 +1012,30 @@ class InternalTests(unittest.TestCase): def test_validate_json(self) -> None: """Validate the json schema for the test cases.""" try: - from jsonschema import validate, ValidationError + from fastjsonschema import compile, JsonSchemaValueException as JsonSchemaFailure + fast = True except ImportError: - if is_ci(): - raise - raise unittest.SkipTest('Python jsonschema module not found.') - - schema = json.loads(Path('data/test.schema.json').read_text(encoding='utf-8')) + try: + from jsonschema import validate, ValidationError as JsonSchemaFailure + fast = False + except: + if is_ci(): + raise + raise unittest.SkipTest('neither Python fastjsonschema nor jsonschema module not found.') + + with open('data/test.schema.json', 'r', encoding='utf-8') as f: + data = json.loads(f.read()) + + if fast: + schema_validator = compile(data) + else: + schema_validator = lambda x: validate(x, schema=data) errors: T.List[T.Tuple[Path, Exception]] = [] for p in Path('test cases').glob('**/test.json'): try: - validate(json.loads(p.read_text(encoding='utf-8')), schema=schema) - except ValidationError as e: + schema_validator(json.loads(p.read_text(encoding='utf-8'))) + except JsonSchemaFailure as e: errors.append((p.resolve(), e)) for f, e in errors: |
