|
4 | 4 | import pathlib |
5 | 5 | import unittest |
6 | 6 |
|
7 | | -from jsonschema import Draft4Validator, RefResolver |
| 7 | +from jsonschema import Draft4Validator, RefResolver, FormatChecker |
| 8 | +from referencing.jsonschema import DRAFT4 |
| 9 | +from referencing import Registry |
8 | 10 |
|
9 | 11 | from isatools import isajson, isatab |
10 | 12 | from isatools.tests import utils |
@@ -356,13 +358,22 @@ def test_validate_testdata_sampleassayplan_json(self): |
356 | 358 | with open(os.path.join(self.v2_create_schemas_path, "sample_assay_plan_schema.json")) as fp: |
357 | 359 | sample_assay_plan_schema = json.load(fp) |
358 | 360 |
|
| 361 | + resources = [] |
359 | 362 | res_path = pathlib.Path( |
360 | 363 | "file://", self.v2_create_schemas_path, "sample_assay_plan_schema.json" |
361 | | - ).as_uri() |
362 | | - resolver = RefResolver(res_path, sample_assay_plan_schema) |
| 364 | + ).resolve().as_uri() |
| 365 | + schemas_dir = pathlib.Path("file://", self.v2_create_schemas_path) |
| 366 | + for p in sorted(schemas_dir.glob("*.json")): |
| 367 | + contents = json.loads(p.read_text(encoding="utf-8")) |
| 368 | + resource = DRAFT4.create_resource(contents) |
| 369 | + resources.append((p.resolve().as_uri(), resource)) |
| 370 | + |
| 371 | + registry = Registry().with_resources(resources) |
| 372 | + schema_ref = {"$ref": res_path, "$schema": "https://json-schema.org/draft-04/schema"} |
| 373 | + |
| 374 | + validator = Draft4Validator(schema_ref, registry=registry, format_checker=FormatChecker()) |
| 375 | + validator.validate(json.load(test_case_fp)) |
363 | 376 |
|
364 | | - validator = Draft4Validator(sample_assay_plan_schema, resolver=resolver) |
365 | | - validator.validate(json.load(test_case_fp)) |
366 | 377 |
|
367 | 378 | def test_validate_testdata_sampleassayplan_qc_json(self): |
368 | 379 | with open(os.path.join(utils.JSON_DATA_DIR, "create", "sampleassayplan_qc_test.json")) as test_case_fp: |
|
0 commit comments