|
19 | 19 | GENERIC_SCHEMA = schema_store[ |
20 | 20 | "https://ngff.openmicroscopy.org/0.6dev2/schemas/ome_zarr.schema" |
21 | 21 | ] |
22 | | - |
23 | | -print(schema_store) |
| 22 | +GENERIC_STRICT_SCHEMA = schema_store[ |
| 23 | + "https://ngff.openmicroscopy.org/0.6dev2/schemas/strict_ome_zarr.schema" |
| 24 | +] |
24 | 25 |
|
25 | 26 |
|
26 | 27 | @dataclass |
@@ -57,60 +58,60 @@ def pytest_generate_tests(metafunc): |
57 | 58 | styled JSON tests. Metadata in each test defines which schema is used |
58 | 59 | and whether or not the block is considered valid. |
59 | 60 | """ |
60 | | - if "suite" in metafunc.fixturenames: |
61 | | - suites: List[Schema] = [] |
62 | | - ids: List[str] = [] |
63 | | - schema_store = {} |
64 | | - for filename in glob.glob("ngff_spec/schemas/*.schema"): |
65 | | - with open(filename) as o: |
66 | | - schema = json.load(o) |
67 | | - schema_store[schema["$id"]] = schema |
68 | | - |
69 | | - # Validation |
70 | | - for filename in glob.glob("tests/*.json"): |
71 | | - with open(filename) as o: |
72 | | - suite = json.load(o) |
73 | | - schema = suite["schema"] |
74 | | - with open(schema["id"]) as f: |
75 | | - schema = json.load(f) |
76 | | - for test in suite["tests"]: |
77 | | - ids.append("validate_" + str(test["formerly"]).split("/")[-1][0:-5]) |
78 | | - suites.append(Suite(schema, test["data"], test["valid"])) |
79 | | - |
80 | | - # Examples |
81 | | - for config_filename in glob.glob("examples/*/.config.json"): |
82 | | - with open(config_filename) as o: |
83 | | - data = json.load(o) |
84 | | - schema = data["schema"] |
85 | | - with open(schema) as f: |
86 | | - schema = json.load(f) |
87 | | - example_folder = os.path.dirname(config_filename) |
88 | | - for filename in glob.glob(f"{example_folder}/*.json"): |
89 | | - with open(filename) as f: |
90 | | - # Strip comments |
91 | | - data = "".join( |
92 | | - line for line in f if not line.lstrip().startswith("//") |
93 | | - ) |
94 | | - data = json.loads(data) |
95 | | - data = data["attributes"] # Only validate the attributes object |
96 | | - ids.append("example_" + str(filename).split("/")[-1][0:-5]) |
97 | | - suites.append(Suite(schema, data, True)) # Assume true |
98 | | - |
99 | | - metafunc.parametrize("suite", suites, ids=ids, indirect=True) |
| 61 | + if "suite" not in metafunc.fixturenames: |
| 62 | + return |
| 63 | + |
| 64 | + suites: List[Suite] = [] |
| 65 | + ids: List[str] = [] |
| 66 | + schema_store = {} |
| 67 | + for filename in glob.glob("ngff_spec/schemas/*.schema"): |
| 68 | + with open(filename) as o: |
| 69 | + schema = json.load(o) |
| 70 | + schema_store[schema["$id"]] = schema |
| 71 | + |
| 72 | + # Validation |
| 73 | + for filename in glob.glob("tests/*.json"): |
| 74 | + with open(filename) as o: |
| 75 | + suite = json.load(o) |
| 76 | + schema_path = suite["schema"] |
| 77 | + with open(schema_path["id"]) as f: |
| 78 | + schema = json.load(f) |
| 79 | + for test in suite["tests"]: |
| 80 | + ids.append("validate_" + str(test["formerly"]).split("/")[-1][0:-5]) |
| 81 | + suites.append(Suite(schema, test["data"], test["valid"])) |
| 82 | + |
| 83 | + # Examples |
| 84 | + for config_filename in glob.glob("examples/*/.config.json"): |
| 85 | + with open(config_filename) as o: |
| 86 | + data = json.load(o) |
| 87 | + schema_path = data["schema"] |
| 88 | + with open(schema_path) as f: |
| 89 | + schema = json.load(f) |
| 90 | + example_folder = os.path.dirname(config_filename) |
| 91 | + for filename in glob.glob(f"{example_folder}/*.json"): |
| 92 | + with open(filename) as f: |
| 93 | + # Strip comments |
| 94 | + data = "".join(line for line in f if not line.lstrip().startswith("//")) |
| 95 | + data = json.loads(data) |
| 96 | + data = data["attributes"] # Only validate the attributes object |
| 97 | + ids.append("example_" + str(filename).split("/")[-1][0:-5]) |
| 98 | + suites.append(Suite(schema, data, True)) # Assume true |
| 99 | + |
| 100 | + metafunc.parametrize("suite", suites, ids=ids, indirect=True) |
100 | 101 |
|
101 | 102 |
|
102 | 103 | @pytest.fixture |
103 | | -def suite(request): |
| 104 | +def suite(request) -> Suite: |
104 | 105 | return request.param |
105 | 106 |
|
106 | 107 |
|
107 | | -def test_run(suite): |
| 108 | +def test_run(suite: Suite): |
108 | 109 | resolver = RefResolver.from_schema(suite.schema, store=schema_store) |
109 | 110 | validator = Validator(suite.schema, resolver=resolver) |
110 | 111 | suite.validate(validator) |
111 | 112 |
|
112 | 113 |
|
113 | | -def test_generic_run(suite): |
| 114 | +def test_generic_run(suite: Suite): |
114 | 115 | resolver = RefResolver.from_schema(GENERIC_SCHEMA, store=schema_store) |
115 | 116 | validator = Validator(GENERIC_SCHEMA, resolver=resolver) |
116 | 117 | suite.maybe_validate(validator) |
|
0 commit comments