Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
],
"version": "0.4"
}
]
],
"recommended": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.4"
}
]
],
"recommended": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.4"
}
]
],
"recommended": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
}
}
]
}
},
"valid": false
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
}
}
]
}
},
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.3"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
],
"version": "0.4"
}
]
],
"recommended": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
],
"version": "0.4"
}
]
],
"valid": false
}

Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
}
]
}
]
],
"recommended": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
}
]
}
]
],
"recommended": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"version": "0.4"
}
]
],
"valid": false
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"datasets": [],
"version": "0.4"
}
]
],
"valid": false
}
5 changes: 5 additions & 0 deletions 0.4/examples/image/no_multiscales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"@type": "ngff:Image",
"multiscales": [],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
],
"version": "0.4"
}
]
],
"valid": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
],
"version": "0.4"
}
]
],
"recommended": false
}
4 changes: 0 additions & 4 deletions 0.4/examples/invalid/no_multiscales.json

This file was deleted.

2 changes: 1 addition & 1 deletion 0.4/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Each "multiscales" dictionary SHOULD contain the field "type", which gives the t
It SHOULD contain the field "metadata", which contains a dictionary with additional information about the downscaling method.

<pre class=include-code>
path: examples/valid_strict/multiscales_example.json
path: examples/image/multiscales_example.json
highlight: json
</pre>

Expand Down
69 changes: 28 additions & 41 deletions 0.4/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,44 @@
}

resolver = RefResolver.from_schema(image_schema, store=schema_store)
validator = Draft202012Validator(image_schema, resolver=resolver)
strict_validator = Draft202012Validator(strict_image_schema, resolver=resolver)

valid_strict_files = list(glob.glob("examples/valid_strict/*.json"))
valid_files = list(glob.glob("examples/valid/*.json"))
invalid_files = list(glob.glob("examples/invalid/*.json"))
invalid_but_dont_fail_files = list(
glob.glob("examples/invalid_but_dont_fail/*.json"))
# Dictionary of validators
validators = {}
strict_validators = {}
validators["multiscales"] = Draft202012Validator(
image_schema, resolver=resolver)
strict_validators["multiscales"] = Draft202012Validator(
strict_image_schema, resolver=resolver)


json_files = list(glob.glob("examples/**/*.json"))


def ids(files):
return [str(x).split("/")[-1][0:-5] for x in files]

def get_spec(jsondata):
for s in ["multiscales"]:
if s in jsondata.keys():
return s
raise Exception("No specification found %s" % jsondata.keys())


@pytest.mark.parametrize(
"testfile", valid_strict_files, ids=ids(valid_strict_files))
def test_valid_strict(testfile):
with open(testfile) as f:
@pytest.mark.parametrize("json_file", json_files, ids=ids(json_files))
def test_compliance(json_file):
with open(json_file) as f:
data = ''.join(line for line in f if not line.lstrip().startswith('//'))
jsondata = json.loads(data)
validator.validate(jsondata)
strict_validator.validate(jsondata)


@pytest.mark.parametrize("testfile", valid_files, ids=ids(valid_files))
def test_valid_files(testfile):
with open(testfile) as f:
json_file = json.load(f)
validator.validate(json_file)
with pytest.raises(ValidationError):
strict_validator.validate(json_file)


@pytest.mark.parametrize("testfile", invalid_files, ids=ids(invalid_files))
def test_invalid(testfile):
with open(testfile) as f:
json_file = json.load(f)
with pytest.raises(ValidationError):
validator.validate(json_file)
spec = get_spec(jsondata)
if jsondata.get("valid", True):
validators[spec].validate(jsondata)
else:
with pytest.raises(ValidationError):
strict_validator.validate(json_file)
validators[spec].validate(jsondata)


@pytest.mark.xfail
@pytest.mark.parametrize(
"testfile", invalid_but_dont_fail_files,
ids=ids(invalid_but_dont_fail_files))
def test_invalid_but_dontfail(testfile):
with open(testfile) as f:
json_file = json.load(f)
with pytest.raises(ValidationError):
validator.validate(json_file)
if jsondata.get("recommended", True) and jsondata.get("valid", True):
strict_validators[spec].validate(jsondata)
else:
with pytest.raises(ValidationError):
strict_validator.validate(json_file)
strict_validators[spec].validate(jsondata)