From fad4a86c93c2e05bb992cf0b65346b7f64e8303d Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 12 May 2022 12:57:00 +0200 Subject: [PATCH 1/7] Proposal: use test suite structure --- .../{valid => axes}/custom_type_axes.json | 0 .../{valid => axes}/invalid_axis_units.json | 0 .../{valid => axes}/mismatch_axes_units.json | 0 .../{valid => axes}/untyped_axes.json | 0 .../{valid => image}/missing_name.json | 0 .../{valid => image}/missing_version.json | 0 .../{valid_strict => image_strict}/image.json | 0 .../image_metadata.json | 0 .../image_omero.json | 0 latest/examples/invalid/duplicate_axes.json | 33 - latest/examples/invalid/duplicate_scale.json | 40 - .../invalid/empty_transformations.json | 25 - .../examples/invalid/invalid_axes_count.json | 28 - .../examples/invalid/invalid_axis_type.json | 33 - .../invalid/invalid_channels_color.json | 48 - .../invalid/invalid_channels_window.json | 50 - .../invalid_multiscales_transformations.json | 39 - latest/examples/invalid/invalid_path.json | 33 - .../invalid/invalid_transformation_type.json | 33 - latest/examples/invalid/invalid_version.json | 33 - latest/examples/invalid/missing_axes.json | 21 - .../examples/invalid/missing_axes_name.json | 31 - latest/examples/invalid/missing_datasets.json | 20 - latest/examples/invalid/missing_path.json | 32 - latest/examples/invalid/missing_scale.json | 30 - .../examples/invalid/missing_space_axes.json | 31 - .../invalid/missing_transformations.json | 24 - latest/examples/invalid/no_axes.json | 23 - latest/examples/invalid/no_datasets.json | 20 - latest/examples/invalid/no_multiscales.json | 4 - latest/examples/invalid/one_space_axes.json | 36 - latest/examples/invalid/too_many_axes.json | 51 - .../examples/invalid/too_many_space_axes.json | 41 - .../duplicate_axes_name.json | 33 - .../multiscales_example.json | 0 .../multiscales_transformations.json | 0 latest/tests/image_suite.json | 1186 +++++++++++++++++ latest/tests/strict_image_suite.json | 388 ++++++ latest/tests/test_examples.py | 79 ++ latest/tests/test_validation.py | 104 +- 40 files changed, 1693 insertions(+), 856 deletions(-) rename latest/examples/{valid => axes}/custom_type_axes.json (100%) rename latest/examples/{valid => axes}/invalid_axis_units.json (100%) rename latest/examples/{valid => axes}/mismatch_axes_units.json (100%) rename latest/examples/{valid => axes}/untyped_axes.json (100%) rename latest/examples/{valid => image}/missing_name.json (100%) rename latest/examples/{valid => image}/missing_version.json (100%) rename latest/examples/{valid_strict => image_strict}/image.json (100%) rename latest/examples/{valid_strict => image_strict}/image_metadata.json (100%) rename latest/examples/{valid_strict => image_strict}/image_omero.json (100%) delete mode 100644 latest/examples/invalid/duplicate_axes.json delete mode 100644 latest/examples/invalid/duplicate_scale.json delete mode 100644 latest/examples/invalid/empty_transformations.json delete mode 100644 latest/examples/invalid/invalid_axes_count.json delete mode 100644 latest/examples/invalid/invalid_axis_type.json delete mode 100644 latest/examples/invalid/invalid_channels_color.json delete mode 100644 latest/examples/invalid/invalid_channels_window.json delete mode 100644 latest/examples/invalid/invalid_multiscales_transformations.json delete mode 100644 latest/examples/invalid/invalid_path.json delete mode 100644 latest/examples/invalid/invalid_transformation_type.json delete mode 100644 latest/examples/invalid/invalid_version.json delete mode 100644 latest/examples/invalid/missing_axes.json delete mode 100644 latest/examples/invalid/missing_axes_name.json delete mode 100644 latest/examples/invalid/missing_datasets.json delete mode 100644 latest/examples/invalid/missing_path.json delete mode 100644 latest/examples/invalid/missing_scale.json delete mode 100644 latest/examples/invalid/missing_space_axes.json delete mode 100644 latest/examples/invalid/missing_transformations.json delete mode 100644 latest/examples/invalid/no_axes.json delete mode 100644 latest/examples/invalid/no_datasets.json delete mode 100644 latest/examples/invalid/no_multiscales.json delete mode 100644 latest/examples/invalid/one_space_axes.json delete mode 100644 latest/examples/invalid/too_many_axes.json delete mode 100644 latest/examples/invalid/too_many_space_axes.json delete mode 100644 latest/examples/invalid_but_dont_fail/duplicate_axes_name.json rename latest/examples/{valid_strict => multiscales_strict}/multiscales_example.json (100%) rename latest/examples/{valid_strict => multiscales_strict}/multiscales_transformations.json (100%) create mode 100644 latest/tests/image_suite.json create mode 100644 latest/tests/strict_image_suite.json create mode 100644 latest/tests/test_examples.py diff --git a/latest/examples/valid/custom_type_axes.json b/latest/examples/axes/custom_type_axes.json similarity index 100% rename from latest/examples/valid/custom_type_axes.json rename to latest/examples/axes/custom_type_axes.json diff --git a/latest/examples/valid/invalid_axis_units.json b/latest/examples/axes/invalid_axis_units.json similarity index 100% rename from latest/examples/valid/invalid_axis_units.json rename to latest/examples/axes/invalid_axis_units.json diff --git a/latest/examples/valid/mismatch_axes_units.json b/latest/examples/axes/mismatch_axes_units.json similarity index 100% rename from latest/examples/valid/mismatch_axes_units.json rename to latest/examples/axes/mismatch_axes_units.json diff --git a/latest/examples/valid/untyped_axes.json b/latest/examples/axes/untyped_axes.json similarity index 100% rename from latest/examples/valid/untyped_axes.json rename to latest/examples/axes/untyped_axes.json diff --git a/latest/examples/valid/missing_name.json b/latest/examples/image/missing_name.json similarity index 100% rename from latest/examples/valid/missing_name.json rename to latest/examples/image/missing_name.json diff --git a/latest/examples/valid/missing_version.json b/latest/examples/image/missing_version.json similarity index 100% rename from latest/examples/valid/missing_version.json rename to latest/examples/image/missing_version.json diff --git a/latest/examples/valid_strict/image.json b/latest/examples/image_strict/image.json similarity index 100% rename from latest/examples/valid_strict/image.json rename to latest/examples/image_strict/image.json diff --git a/latest/examples/valid_strict/image_metadata.json b/latest/examples/image_strict/image_metadata.json similarity index 100% rename from latest/examples/valid_strict/image_metadata.json rename to latest/examples/image_strict/image_metadata.json diff --git a/latest/examples/valid_strict/image_omero.json b/latest/examples/image_strict/image_omero.json similarity index 100% rename from latest/examples/valid_strict/image_omero.json rename to latest/examples/image_strict/image_omero.json diff --git a/latest/examples/invalid/duplicate_axes.json b/latest/examples/invalid/duplicate_axes.json deleted file mode 100644 index ea4f5462..00000000 --- a/latest/examples/invalid/duplicate_axes.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "x", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} \ No newline at end of file diff --git a/latest/examples/invalid/duplicate_scale.json b/latest/examples/invalid/duplicate_scale.json deleted file mode 100644 index c2721ef7..00000000 --- a/latest/examples/invalid/duplicate_scale.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - }, - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/empty_transformations.json b/latest/examples/invalid/empty_transformations.json deleted file mode 100644 index 4fde9e23..00000000 --- a/latest/examples/invalid/empty_transformations.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/invalid_axes_count.json b/latest/examples/invalid/invalid_axes_count.json deleted file mode 100644 index 10168e3a..00000000 --- a/latest/examples/invalid/invalid_axes_count.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/invalid_axis_type.json b/latest/examples/invalid/invalid_axis_type.json deleted file mode 100644 index 5cfc3f7c..00000000 --- a/latest/examples/invalid/invalid_axis_type.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "invalid", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/invalid_channels_color.json b/latest/examples/invalid/invalid_channels_color.json deleted file mode 100644 index 99fd91a0..00000000 --- a/latest/examples/invalid/invalid_channels_color.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [1, 1], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ], - "omero": { - "channels": [ - { - "active": true, - "coefficient": 1.0, - "color": 255, - "family": "linear", - "label": "1234", - "window": { - "end": 1765.0, - "max": 2555.0, - "min": 5.0, - "start": 0.0 - } - } - ] - } -} - diff --git a/latest/examples/invalid/invalid_channels_window.json b/latest/examples/invalid/invalid_channels_window.json deleted file mode 100644 index 1565cbcb..00000000 --- a/latest/examples/invalid/invalid_channels_window.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ], - "omero": { - "channels": [ - { - "active": true, - "coefficient": 1.0, - "color": "ff0000", - "family": "linear", - "label": "1234", - "window": { - "end": "100", - "max": 2555.0, - "min": 5.0, - "start": 0.0 - } - } - ] - } -} diff --git a/latest/examples/invalid/invalid_multiscales_transformations.json b/latest/examples/invalid/invalid_multiscales_transformations.json deleted file mode 100644 index 56cca4c1..00000000 --- a/latest/examples/invalid/invalid_multiscales_transformations.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "coordinateTransformations": [ - { - "scale": ["invalid"], - "type": "scale" - } - ], - "version": "0.5-dev" - } - ] -} \ No newline at end of file diff --git a/latest/examples/invalid/invalid_path.json b/latest/examples/invalid/invalid_path.json deleted file mode 100644 index 68e7f582..00000000 --- a/latest/examples/invalid/invalid_path.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": 0, - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/invalid_transformation_type.json b/latest/examples/invalid/invalid_transformation_type.json deleted file mode 100644 index 16785300..00000000 --- a/latest/examples/invalid/invalid_transformation_type.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "translation" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/invalid_version.json b/latest/examples/invalid/invalid_version.json deleted file mode 100644 index cab8991b..00000000 --- a/latest/examples/invalid/invalid_version.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.3" - } - ] -} diff --git a/latest/examples/invalid/missing_axes.json b/latest/examples/invalid/missing_axes.json deleted file mode 100644 index 60a85066..00000000 --- a/latest/examples/invalid/missing_axes.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "multiscales": [ - { - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/missing_axes_name.json b/latest/examples/invalid/missing_axes_name.json deleted file mode 100644 index e834822b..00000000 --- a/latest/examples/invalid/missing_axes_name.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "type": "space", - "units": "micron" - }, - { - "type": "space", - "units": "micron" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 0.13, - 0.13 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/missing_datasets.json b/latest/examples/invalid/missing_datasets.json deleted file mode 100644 index 58246451..00000000 --- a/latest/examples/invalid/missing_datasets.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "version": "0.5-dev" - } - ] -} - diff --git a/latest/examples/invalid/missing_path.json b/latest/examples/invalid/missing_path.json deleted file mode 100644 index ace36eaa..00000000 --- a/latest/examples/invalid/missing_path.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/missing_scale.json b/latest/examples/invalid/missing_scale.json deleted file mode 100644 index 5c6fde7d..00000000 --- a/latest/examples/invalid/missing_scale.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "translation": [1, 1], - "type": "translation" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} \ No newline at end of file diff --git a/latest/examples/invalid/missing_space_axes.json b/latest/examples/invalid/missing_space_axes.json deleted file mode 100644 index 0b2cb5ad..00000000 --- a/latest/examples/invalid/missing_space_axes.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "t", - "type": "time" - }, - { - "name": "c", - "type": "channel" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/missing_transformations.json b/latest/examples/invalid/missing_transformations.json deleted file mode 100644 index feadd6b0..00000000 --- a/latest/examples/invalid/missing_transformations.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0" - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/no_axes.json b/latest/examples/invalid/no_axes.json deleted file mode 100644 index 6425c32f..00000000 --- a/latest/examples/invalid/no_axes.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "multiscales": [ - { - "axes": [], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} - diff --git a/latest/examples/invalid/no_datasets.json b/latest/examples/invalid/no_datasets.json deleted file mode 100644 index 3fc33429..00000000 --- a/latest/examples/invalid/no_datasets.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/no_multiscales.json b/latest/examples/invalid/no_multiscales.json deleted file mode 100644 index d6dbfb33..00000000 --- a/latest/examples/invalid/no_multiscales.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "@type": "ngff:Image", - "multiscales": [] -} diff --git a/latest/examples/invalid/one_space_axes.json b/latest/examples/invalid/one_space_axes.json deleted file mode 100644 index 39b59c88..00000000 --- a/latest/examples/invalid/one_space_axes.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "t", - "type": "time" - }, - { - "name": "c", - "type": "channel" - }, - { - "name": "x", - "type": "space" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/too_many_axes.json b/latest/examples/invalid/too_many_axes.json deleted file mode 100644 index e384e8d4..00000000 --- a/latest/examples/invalid/too_many_axes.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "angle", - "type": "custom" - }, - { - "name": "t", - "type": "time" - }, - { - "name": "c", - "type": "channel" - }, - { - "name": "z", - "type": "space" - }, - { - "name": "y", - "type": "space" - }, - { - "name": "x", - "type": "space" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1, - 1, - 1, - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid/too_many_space_axes.json b/latest/examples/invalid/too_many_space_axes.json deleted file mode 100644 index 1f93863f..00000000 --- a/latest/examples/invalid/too_many_space_axes.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "X", - "type": "space" - }, - { - "name": "z", - "type": "space" - }, - { - "name": "y", - "type": "space" - }, - { - "name": "x", - "type": "space" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1, - 1, - 1 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/invalid_but_dont_fail/duplicate_axes_name.json b/latest/examples/invalid_but_dont_fail/duplicate_axes_name.json deleted file mode 100644 index 889e06e8..00000000 --- a/latest/examples/invalid_but_dont_fail/duplicate_axes_name.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "x", - "type": "space", - "units": "meter" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 0.13, - 0.13 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/valid_strict/multiscales_example.json b/latest/examples/multiscales_strict/multiscales_example.json similarity index 100% rename from latest/examples/valid_strict/multiscales_example.json rename to latest/examples/multiscales_strict/multiscales_example.json diff --git a/latest/examples/valid_strict/multiscales_transformations.json b/latest/examples/multiscales_strict/multiscales_transformations.json similarity index 100% rename from latest/examples/valid_strict/multiscales_transformations.json rename to latest/examples/multiscales_strict/multiscales_transformations.json diff --git a/latest/tests/image_suite.json b/latest/tests/image_suite.json new file mode 100644 index 00000000..e92378ec --- /dev/null +++ b/latest/tests/image_suite.json @@ -0,0 +1,1186 @@ +{ + "description": "TBD", + "schema": { + "id": "schemas/image.schema" + }, + "tests": [ + { + "formerly": "valid/mismatch_axes_units.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "t", + "type": "time", + "units": "micrometer" + }, + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 0.13, + 0.13 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": true + }, + { + "formerly": "valid/untyped_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "angle" + }, + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": true + }, + { + "formerly": "valid/missing_version.json", + "description": "TBD", + "data": { + "@type": "ngff:Image", + "multiscales": [ + { + "name": "example", + "datasets": [ + { + "path": "path/to/0", + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + 1, + 1 + ] + } + ] + } + ], + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ] + } + ] + }, + "valid": true + }, + { + "formerly": "valid/invalid_axis_units.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micron" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 0.13, + 0.13 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": true + }, + { + "formerly": "valid/missing_name.json", + "description": "TBD", + "data": { + "@type": "ngff:Image", + "multiscales": [ + { + "version": "0.5-dev", + "datasets": [ + { + "path": "path/to/0", + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + 1, + 1 + ] + } + ] + } + ], + "type": "gaussian", + "metadata": { + "method": "skimage.transform.pyramid_gaussian", + "version": "0.16.1", + "args": [ + "true", + "false" + ], + "kwargs": { + "multichannel": true + } + }, + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ] + } + ] + }, + "valid": true + }, + { + "formerly": "valid/custom_type_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "angle", + "type": "custom" + }, + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": true + }, + { + "formerly": "invalid/duplicate_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "x", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/missing_space_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "t", + "type": "time" + }, + { + "name": "c", + "type": "channel" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_transformation_type.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "translation" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/missing_scale.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "translation": [ + 1, + 1 + ], + "type": "translation" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/too_many_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "angle", + "type": "custom" + }, + { + "name": "t", + "type": "time" + }, + { + "name": "c", + "type": "channel" + }, + { + "name": "z", + "type": "space" + }, + { + "name": "y", + "type": "space" + }, + { + "name": "x", + "type": "space" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1, + 1, + 1, + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_channels_color.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ], + "omero": { + "channels": [ + { + "active": true, + "coefficient": 1.0, + "color": 255, + "family": "linear", + "label": "1234", + "window": { + "end": 1765.0, + "max": 2555.0, + "min": 5.0, + "start": 0.0 + } + } + ] + } + }, + "valid": false + }, + { + "formerly": "invalid/missing_axes_name.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "type": "space", + "units": "micron" + }, + { + "type": "space", + "units": "micron" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 0.13, + 0.13 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_axes_count.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/one_space_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "t", + "type": "time" + }, + { + "name": "c", + "type": "channel" + }, + { + "name": "x", + "type": "space" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_path.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": 0, + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_multiscales_transformations.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "coordinateTransformations": [ + { + "scale": [ + "invalid" + ], + "type": "scale" + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/missing_transformations.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0" + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/no_datasets.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/missing_datasets.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/missing_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_version.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.3" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_axis_type.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "invalid", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/duplicate_scale.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + }, + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/no_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/too_many_space_axes.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "X", + "type": "space" + }, + { + "name": "z", + "type": "space" + }, + { + "name": "y", + "type": "space" + }, + { + "name": "x", + "type": "space" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1, + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/no_multiscales.json", + "description": "TBD", + "data": { + "@type": "ngff:Image", + "multiscales": [] + }, + "valid": false + }, + { + "formerly": "invalid/invalid_channels_window.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ], + "omero": { + "channels": [ + { + "active": true, + "coefficient": 1.0, + "color": "ff0000", + "family": "linear", + "label": "1234", + "window": { + "end": "100", + "max": 2555.0, + "min": 5.0, + "start": 0.0 + } + } + ] + } + }, + "valid": false + }, + { + "formerly": "invalid/empty_transformations.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid/missing_path.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + }, + { + "formerly": "invalid_but_dont_fail/duplicate_axes_name.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "x", + "type": "space", + "units": "meter" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 0.13, + 0.13 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev" + } + ] + }, + "valid": false + } + ] +} \ No newline at end of file diff --git a/latest/tests/strict_image_suite.json b/latest/tests/strict_image_suite.json new file mode 100644 index 00000000..3122ab98 --- /dev/null +++ b/latest/tests/strict_image_suite.json @@ -0,0 +1,388 @@ +{ + "description": "TBD", + "schema": { + "id": "schemas/strict_image.schema" + }, + "tests": [ + { + "formerly": "valid_strict/multiscales_example.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "version": "0.5-dev", + "name": "example", + "axes": [ + { + "name": "t", + "type": "time", + "unit": "millisecond" + }, + { + "name": "c", + "type": "channel" + }, + { + "name": "z", + "type": "space", + "unit": "micrometer" + }, + { + "name": "y", + "type": "space", + "unit": "micrometer" + }, + { + "name": "x", + "type": "space", + "unit": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + 1.0, + 1.0, + 0.5, + 0.5, + 0.5 + ] + } + ] + }, + { + "path": "1", + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0 + ] + } + ] + }, + { + "path": "2", + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + 1.0, + 1.0, + 2.0, + 2.0, + 2.0 + ] + } + ] + } + ], + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + 0.1, + 1.0, + 1.0, + 1.0, + 1.0 + ] + } + ], + "type": "gaussian", + "metadata": { + "description": "the fields in metadata depend on the downscaling implementation. Here, the parameters passed to the skimage function are given", + "method": "skimage.transform.pyramid_gaussian", + "version": "0.16.1", + "args": "[true]", + "kwargs": { + "multichannel": true + } + } + } + ] + }, + "valid": "TBD" + }, + { + "formerly": "valid_strict/multiscales_transformations.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "coordinateTransformations": [ + { + "scale": [ + 10, + 10 + ], + "type": "scale" + } + ], + "version": "0.5-dev", + "name": "image_with_coordinateTransformations", + "type": "foo", + "metadata": { + "key": "value" + } + } + ] + }, + "valid": "TBD" + }, + { + "formerly": "valid_strict/image_metadata.json", + "description": "TBD", + "data": { + "@id": "top", + "@type": "ngff:Image", + "multiscales": [ + { + "@id": "inner", + "version": "0.5-dev", + "name": "example", + "datasets": [ + { + "path": "path/to/0", + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + 1, + 1 + ] + } + ] + } + ], + "type": "gaussian", + "metadata": { + "method": "skimage.transform.pyramid_gaussian", + "version": "0.16.1", + "args": [ + "true", + "false" + ], + "kwargs": { + "multichannel": true + } + }, + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ] + } + ] + }, + "valid": "TBD" + }, + { + "formerly": "valid_strict/image.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev", + "name": "simple_image", + "type": "foo", + "metadata": { + "key": "value" + } + } + ] + }, + "valid": "TBD" + }, + { + "formerly": "valid_strict/image_omero.json", + "description": "TBD", + "data": { + "multiscales": [ + { + "axes": [ + { + "name": "t", + "type": "time" + }, + { + "name": "c", + "type": "channel" + }, + { + "name": "z", + "type": "space", + "units": "micrometer" + }, + { + "name": "y", + "type": "space", + "units": "micrometer" + }, + { + "name": "x", + "type": "space", + "units": "micrometer" + } + ], + "datasets": [ + { + "path": "0", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1, + 0.5, + 0.13, + 0.13 + ], + "type": "scale" + }, + { + "translation": [ + 0, + 9, + 0.5, + 25.74, + 21.58 + ], + "type": "translation" + } + ] + }, + { + "path": "1", + "coordinateTransformations": [ + { + "scale": [ + 1, + 1, + 1, + 0.26, + 0.26 + ], + "type": "scale" + } + ] + } + ], + "version": "0.5-dev", + "name": "image_with_omero_metadata", + "type": "foo", + "metadata": { + "key": "value" + } + } + ], + "omero": { + "channels": [ + { + "active": true, + "coefficient": 1.0, + "color": "00FF00", + "family": "linear", + "inverted": false, + "label": "FITC", + "window": { + "end": 813.0, + "max": 870.0, + "min": 102.0, + "start": 82.0 + } + }, + { + "active": true, + "coefficient": 1.0, + "color": "FF0000", + "family": "linear", + "inverted": false, + "label": "RD-TR-PE", + "window": { + "end": 815.0, + "max": 441.0, + "min": 129.0, + "start": 78.0 + } + } + ], + "id": 1, + "rdefs": { + "defaultT": 0, + "defaultZ": 2, + "model": "color" + }, + "version": "0.5-dev" + } + }, + "valid": "TBD" + } + ] +} diff --git a/latest/tests/test_examples.py b/latest/tests/test_examples.py new file mode 100644 index 00000000..23987968 --- /dev/null +++ b/latest/tests/test_examples.py @@ -0,0 +1,79 @@ +""" +This test evalutes all of the files under the examples/ directory +using the configuration in the provided config file in order detect +what should be run. It is assumed that all files are valid and complete +so that they can be wholly included into the specification. +""" +import json +import glob + +import pytest + +from jsonschema import RefResolver, Draft202012Validator +from jsonschema.exceptions import ValidationError + + +with open('schemas/image.schema') as f: + image_schema = json.load(f) +with open('schemas/strict_image.schema') as f: + strict_image_schema = json.load(f) +schema_store = { + image_schema['$id']: image_schema, + strict_image_schema['$id']: strict_image_schema, +} + +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")) + + +def ids(files): + return [str(x).split("/")[-1][0:-5] for x in files] + + +@pytest.mark.parametrize( + "testfile", valid_strict_files, ids=ids(valid_strict_files)) +def test_valid_strict(testfile): + with open(testfile) 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) + with pytest.raises(ValidationError): + strict_validator.validate(json_file) + + +@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) + with pytest.raises(ValidationError): + strict_validator.validate(json_file) diff --git a/latest/tests/test_validation.py b/latest/tests/test_validation.py index 3a6a5761..47fcbaf9 100644 --- a/latest/tests/test_validation.py +++ b/latest/tests/test_validation.py @@ -1,73 +1,49 @@ +""" +This test consumes https://github.com/json-schema-org/JSON-Schema-Test-Suite#structure-of-a-test +styled JSON tests. +""" import json import glob import pytest -from jsonschema import RefResolver, Draft202012Validator +from jsonschema import RefResolver, Draft7Validator from jsonschema.exceptions import ValidationError -with open('schemas/image.schema') as f: - image_schema = json.load(f) -with open('schemas/strict_image.schema') as f: - strict_image_schema = json.load(f) -schema_store = { - image_schema['$id']: image_schema, - strict_image_schema['$id']: strict_image_schema, -} - -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")) - - -def ids(files): - return [str(x).split("/")[-1][0:-5] for x in files] - - -@pytest.mark.parametrize( - "testfile", valid_strict_files, ids=ids(valid_strict_files)) -def test_valid_strict(testfile): - with open(testfile) 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) - with pytest.raises(ValidationError): - strict_validator.validate(json_file) - - -@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) +def pytest_generate_tests(metafunc): + if "suite" in metafunc.fixturenames: + suites = [] + for filename in glob.glob("tests/*.json"): + with open(filename) as o: + data = json.load(o) + schema = data["schema"] + for test in data["tests"]: + suites.append((schema, test)) + metafunc.parametrize("suite", suites, indirect=True) + + +@pytest.fixture +def suite(request): + return request.param + + +def test_run(suite): + schema, test = suite + + # Load schema + # Currently missing the "id" field + with open(schema["id"]) as f: + schema = json.load(f) + schema_store = { + schema['$id']: schema + } + resolver = RefResolver.from_schema(schema, store=schema_store) + validator = Draft7Validator(schema, resolver=resolver) + + # Load data and test + jsondata = test["data"] + valid = test["valid"] + if not valid: with pytest.raises(ValidationError): - strict_validator.validate(json_file) + validator.validate(jsondata) \ No newline at end of file From 06672cea5b7d1ab0a70ec6c62c55dda3f4d6abbc Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 12 May 2022 13:14:34 +0200 Subject: [PATCH 2/7] Update examples tests --- latest/examples/axes/.config.json | 3 + latest/examples/image/.config.json | 3 + latest/examples/image_strict/.config.json | 3 + .../examples/multiscales_strict/.config.json | 3 + latest/tests/test_examples.py | 103 +++++++----------- latest/tests/test_validation.py | 2 + 6 files changed, 51 insertions(+), 66 deletions(-) create mode 100644 latest/examples/axes/.config.json create mode 100644 latest/examples/image/.config.json create mode 100644 latest/examples/image_strict/.config.json create mode 100644 latest/examples/multiscales_strict/.config.json diff --git a/latest/examples/axes/.config.json b/latest/examples/axes/.config.json new file mode 100644 index 00000000..5236dec2 --- /dev/null +++ b/latest/examples/axes/.config.json @@ -0,0 +1,3 @@ +{ + "schema": "schemas/image.schema" +} diff --git a/latest/examples/image/.config.json b/latest/examples/image/.config.json new file mode 100644 index 00000000..5236dec2 --- /dev/null +++ b/latest/examples/image/.config.json @@ -0,0 +1,3 @@ +{ + "schema": "schemas/image.schema" +} diff --git a/latest/examples/image_strict/.config.json b/latest/examples/image_strict/.config.json new file mode 100644 index 00000000..b0469538 --- /dev/null +++ b/latest/examples/image_strict/.config.json @@ -0,0 +1,3 @@ +{ + "schema": "schemas/strict_image.schema" +} diff --git a/latest/examples/multiscales_strict/.config.json b/latest/examples/multiscales_strict/.config.json new file mode 100644 index 00000000..b0469538 --- /dev/null +++ b/latest/examples/multiscales_strict/.config.json @@ -0,0 +1,3 @@ +{ + "schema": "schemas/strict_image.schema" +} diff --git a/latest/tests/test_examples.py b/latest/tests/test_examples.py index 23987968..5090e7b7 100644 --- a/latest/tests/test_examples.py +++ b/latest/tests/test_examples.py @@ -9,71 +9,42 @@ import pytest -from jsonschema import RefResolver, Draft202012Validator +from jsonschema import RefResolver, Draft7Validator from jsonschema.exceptions import ValidationError - -with open('schemas/image.schema') as f: - image_schema = json.load(f) -with open('schemas/strict_image.schema') as f: - strict_image_schema = json.load(f) -schema_store = { - image_schema['$id']: image_schema, - strict_image_schema['$id']: strict_image_schema, -} - -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")) - - -def ids(files): - return [str(x).split("/")[-1][0:-5] for x in files] - - -@pytest.mark.parametrize( - "testfile", valid_strict_files, ids=ids(valid_strict_files)) -def test_valid_strict(testfile): - with open(testfile) 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) - with pytest.raises(ValidationError): - strict_validator.validate(json_file) - - -@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) - with pytest.raises(ValidationError): - strict_validator.validate(json_file) +def pytest_generate_tests(metafunc): + if "suite" in metafunc.fixturenames: + suites = [] + ids = [] + for config_filename in glob.glob("examples/*/.config.json"): + with open(config_filename) as o: + data = json.load(o) + schema = data["schema"] + for filename in glob.glob("examples/*/*.json"): + ids.append(str(filename).split("/")[-1][0:-5]) + with open(filename) as f: + # Strip comments + data = ''.join(line for line in f if not line.lstrip().startswith('//')) + jsondata = json.loads(data) + suites.append((schema, jsondata)) + metafunc.parametrize("suite", suites, ids=ids, indirect=True) + + +@pytest.fixture +def suite(request): + return request.param + +def test_run(suite): + schema, jsondata = suite + + # Load schema + with open(schema) as f: + schema = json.load(f) + schema_store = { + schema['$id']: schema + } + resolver = RefResolver.from_schema(schema, store=schema_store) + validator = Draft7Validator(schema, resolver=resolver) + + # Test loaded data + validator.validate(jsondata) \ No newline at end of file diff --git a/latest/tests/test_validation.py b/latest/tests/test_validation.py index 47fcbaf9..f7582f90 100644 --- a/latest/tests/test_validation.py +++ b/latest/tests/test_validation.py @@ -14,7 +14,9 @@ def pytest_generate_tests(metafunc): if "suite" in metafunc.fixturenames: suites = [] + ids = [] for filename in glob.glob("tests/*.json"): + ids.append(str(filename).split("/")[-1][0:-5]) with open(filename) as o: data = json.load(o) schema = data["schema"] From 7c1cd6edca42c0d54937d01bb29724dd2b5ba4ea Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 12 May 2022 13:33:50 +0200 Subject: [PATCH 3/7] Remove unused examples --- latest/examples/axes/.config.json | 3 - latest/examples/axes/custom_type_axes.json | 34 ----- latest/examples/axes/invalid_axis_units.json | 33 ----- latest/examples/axes/mismatch_axes_units.json | 38 ------ latest/examples/axes/untyped_axes.json | 33 ----- latest/examples/image/.config.json | 3 - latest/examples/image/missing_name.json | 43 ------- latest/examples/image/missing_version.json | 31 ----- latest/examples/image_strict/.config.json | 3 - latest/examples/image_strict/image.json | 35 ------ .../examples/image_strict/image_metadata.json | 46 ------- latest/examples/image_strict/image_omero.json | 118 ------------------ latest/index.bs | 2 +- 13 files changed, 1 insertion(+), 421 deletions(-) delete mode 100644 latest/examples/axes/.config.json delete mode 100644 latest/examples/axes/custom_type_axes.json delete mode 100644 latest/examples/axes/invalid_axis_units.json delete mode 100644 latest/examples/axes/mismatch_axes_units.json delete mode 100644 latest/examples/axes/untyped_axes.json delete mode 100644 latest/examples/image/.config.json delete mode 100644 latest/examples/image/missing_name.json delete mode 100644 latest/examples/image/missing_version.json delete mode 100644 latest/examples/image_strict/.config.json delete mode 100644 latest/examples/image_strict/image.json delete mode 100644 latest/examples/image_strict/image_metadata.json delete mode 100644 latest/examples/image_strict/image_omero.json diff --git a/latest/examples/axes/.config.json b/latest/examples/axes/.config.json deleted file mode 100644 index 5236dec2..00000000 --- a/latest/examples/axes/.config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "schema": "schemas/image.schema" -} diff --git a/latest/examples/axes/custom_type_axes.json b/latest/examples/axes/custom_type_axes.json deleted file mode 100644 index a5859341..00000000 --- a/latest/examples/axes/custom_type_axes.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "angle", - "type": "custom" - }, - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [1, 1, 1], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} \ No newline at end of file diff --git a/latest/examples/axes/invalid_axis_units.json b/latest/examples/axes/invalid_axis_units.json deleted file mode 100644 index 0d3fa97f..00000000 --- a/latest/examples/axes/invalid_axis_units.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micron" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 0.13, - 0.13 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/axes/mismatch_axes_units.json b/latest/examples/axes/mismatch_axes_units.json deleted file mode 100644 index 1025a360..00000000 --- a/latest/examples/axes/mismatch_axes_units.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "t", - "type": "time", - "units": "micrometer" - }, - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 0.13, - 0.13 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} diff --git a/latest/examples/axes/untyped_axes.json b/latest/examples/axes/untyped_axes.json deleted file mode 100644 index 3d11170b..00000000 --- a/latest/examples/axes/untyped_axes.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "angle" - }, - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [1, 1, 1], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] -} \ No newline at end of file diff --git a/latest/examples/image/.config.json b/latest/examples/image/.config.json deleted file mode 100644 index 5236dec2..00000000 --- a/latest/examples/image/.config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "schema": "schemas/image.schema" -} diff --git a/latest/examples/image/missing_name.json b/latest/examples/image/missing_name.json deleted file mode 100644 index 5503af70..00000000 --- a/latest/examples/image/missing_name.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "@type": "ngff:Image", - "multiscales": [ - { - "version": "0.5-dev", - "datasets": [ - { - "path": "path/to/0", - "coordinateTransformations": [ - { - "type": "scale", - "scale": [1, 1] - } - ] - } - ], - "type": "gaussian", - "metadata": { - "method": "skimage.transform.pyramid_gaussian", - "version": "0.16.1", - "args": [ - "true", - "false" - ], - "kwargs": { - "multichannel": true - } - }, - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ] - } - ] -} diff --git a/latest/examples/image/missing_version.json b/latest/examples/image/missing_version.json deleted file mode 100644 index 0e1e6b7f..00000000 --- a/latest/examples/image/missing_version.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "@type": "ngff:Image", - "multiscales": [ - { - "name": "example", - "datasets": [ - { - "path": "path/to/0", - "coordinateTransformations": [ - { - "type": "scale", - "scale": [1, 1] - } - ] - } - ], - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ] - } - ] -} diff --git a/latest/examples/image_strict/.config.json b/latest/examples/image_strict/.config.json deleted file mode 100644 index b0469538..00000000 --- a/latest/examples/image_strict/.config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "schema": "schemas/strict_image.schema" -} diff --git a/latest/examples/image_strict/image.json b/latest/examples/image_strict/image.json deleted file mode 100644 index 4ccb7da5..00000000 --- a/latest/examples/image_strict/image.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [1, 1], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev", - "name": "simple_image", - "type": "foo", - "metadata": { - "key": "value" - } - } - ] -} \ No newline at end of file diff --git a/latest/examples/image_strict/image_metadata.json b/latest/examples/image_strict/image_metadata.json deleted file mode 100644 index ea2c046d..00000000 --- a/latest/examples/image_strict/image_metadata.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "@id": "top", - "@type": "ngff:Image", - "multiscales": [ - { - "@id": "inner", - "version": "0.5-dev", - "name": "example", - "datasets": [ - { - "path": "path/to/0", - "coordinateTransformations": [ - { - "type": "scale", - "scale": [1, 1] - } - ] - } - ], - "type": "gaussian", - "metadata": { - "method": "skimage.transform.pyramid_gaussian", - "version": "0.16.1", - "args": [ - "true", - "false" - ], - "kwargs": { - "multichannel": true - } - }, - "axes": [ - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ] - } - ] -} diff --git a/latest/examples/image_strict/image_omero.json b/latest/examples/image_strict/image_omero.json deleted file mode 100644 index fa88d09e..00000000 --- a/latest/examples/image_strict/image_omero.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "multiscales": [ - { - "axes": [ - { - "name": "t", - "type": "time" - }, - { - "name": "c", - "type": "channel" - }, - { - "name": "z", - "type": "space", - "units": "micrometer" - }, - { - "name": "y", - "type": "space", - "units": "micrometer" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1, - 0.5, - 0.13, - 0.13 - ], - "type": "scale" - }, - { - "translation": [ - 0, - 9, - 0.5, - 25.74, - 21.58 - ], - "type": "translation" - } - ] - }, - { - "path": "1", - "coordinateTransformations": [ - { - "scale": [ - 1, - 1, - 1, - 0.26, - 0.26 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev", - "name": "image_with_omero_metadata", - "type": "foo", - "metadata": { - "key": "value" - } - } - ], - "omero": { - "channels": [ - { - "active": true, - "coefficient": 1.0, - "color": "00FF00", - "family": "linear", - "inverted": false, - "label": "FITC", - "window": { - "end": 813.0, - "max": 870.0, - "min": 102.0, - "start": 82.0 - } - }, - { - "active": true, - "coefficient": 1.0, - "color": "FF0000", - "family": "linear", - "inverted": false, - "label": "RD-TR-PE", - "window": { - "end": 815.0, - "max": 441.0, - "min": 129.0, - "start": 78.0 - } - } - ], - "id": 1, - "rdefs": { - "defaultT": 0, - "defaultZ": 2, - "model": "color" - }, - "version": "0.5-dev" - } -} diff --git a/latest/index.bs b/latest/index.bs index 76a40ab2..00b06c29 100644 --- a/latest/index.bs +++ b/latest/index.bs @@ -298,7 +298,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.
-path: examples/valid_strict/multiscales_example.json
+path: examples/multiscales_strict/multiscales_example.json
 highlight: json
 
From 9d602747fbf606e62a68ef72fdcf461266b133fa Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 12 May 2022 14:25:09 +0200 Subject: [PATCH 4/7] Recombine test classes --- latest/tests/test_examples.py | 50 ------------------ latest/tests/test_validation.py | 90 +++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 78 deletions(-) delete mode 100644 latest/tests/test_examples.py diff --git a/latest/tests/test_examples.py b/latest/tests/test_examples.py deleted file mode 100644 index 5090e7b7..00000000 --- a/latest/tests/test_examples.py +++ /dev/null @@ -1,50 +0,0 @@ -""" -This test evalutes all of the files under the examples/ directory -using the configuration in the provided config file in order detect -what should be run. It is assumed that all files are valid and complete -so that they can be wholly included into the specification. -""" -import json -import glob - -import pytest - -from jsonschema import RefResolver, Draft7Validator -from jsonschema.exceptions import ValidationError - -def pytest_generate_tests(metafunc): - if "suite" in metafunc.fixturenames: - suites = [] - ids = [] - for config_filename in glob.glob("examples/*/.config.json"): - with open(config_filename) as o: - data = json.load(o) - schema = data["schema"] - for filename in glob.glob("examples/*/*.json"): - ids.append(str(filename).split("/")[-1][0:-5]) - with open(filename) as f: - # Strip comments - data = ''.join(line for line in f if not line.lstrip().startswith('//')) - jsondata = json.loads(data) - suites.append((schema, jsondata)) - metafunc.parametrize("suite", suites, ids=ids, indirect=True) - - -@pytest.fixture -def suite(request): - return request.param - -def test_run(suite): - schema, jsondata = suite - - # Load schema - with open(schema) as f: - schema = json.load(f) - schema_store = { - schema['$id']: schema - } - resolver = RefResolver.from_schema(schema, store=schema_store) - validator = Draft7Validator(schema, resolver=resolver) - - # Test loaded data - validator.validate(jsondata) \ No newline at end of file diff --git a/latest/tests/test_validation.py b/latest/tests/test_validation.py index f7582f90..3eed18b6 100644 --- a/latest/tests/test_validation.py +++ b/latest/tests/test_validation.py @@ -1,28 +1,77 @@ -""" -This test consumes https://github.com/json-schema-org/JSON-Schema-Test-Suite#structure-of-a-test -styled JSON tests. -""" import json import glob +from dataclasses import dataclass +from typing import List + import pytest from jsonschema import RefResolver, Draft7Validator from jsonschema.exceptions import ValidationError +@dataclass +class Suite: + schema: dict + schema_store: dict + data: dict + valid: bool = True + + def validate(self, validator) -> None: + if not self.valid: + with pytest.raises(ValidationError): + validator.validate(self.data) + else: + validator.validate(self.data) + + def pytest_generate_tests(metafunc): + """ + Generates tests for the examples/ as well as tests/ subdirectories. + + Examples: + These tests evalute all of the files under the examples/ directory + using the configuration in the provided config file in order detect + what should be run. It is assumed that all files are valid and complete + so that they can be wholly included into the specification. The + .config.json file in each directory defines which schema will be used. + + Validation: + These test consumes https://github.com/json-schema-org/JSON-Schema-Test-Suite#structure-of-a-test + styled JSON tests. Metadata in each test defines which schema is used + and whether or not the block is considered valid. + """ if "suite" in metafunc.fixturenames: - suites = [] - ids = [] + suites: List[Schema] = [] + ids: List[str] = [] + + # Validation for filename in glob.glob("tests/*.json"): - ids.append(str(filename).split("/")[-1][0:-5]) with open(filename) as o: + suite = json.load(o) + schema = suite["schema"] + with open(schema["id"]) as f: + schema = json.load(f) + for test in suite["tests"]: + ids.append("validate_" + str(test["formerly"]).split("/")[-1][0:-5]) + suites.append(Suite(schema, {schema["$id"]: schema}, test["data"], test["valid"])) + + # Examples + for config_filename in glob.glob("examples/*/.config.json"): + with open(config_filename) as o: data = json.load(o) schema = data["schema"] - for test in data["tests"]: - suites.append((schema, test)) - metafunc.parametrize("suite", suites, indirect=True) + with open(schema) as f: + schema = json.load(f) + for filename in glob.glob("examples/*/*.json"): + with open(filename) as f: + # Strip comments + data = ''.join(line for line in f if not line.lstrip().startswith('//')) + data = json.loads(data) + ids.append("example_" + str(filename).split("/")[-1][0:-5]) + suites.append(Suite(schema, {schema["$id"]: schema}, data, True)) # Assume true + + metafunc.parametrize("suite", suites, ids=ids, indirect=True) @pytest.fixture @@ -31,21 +80,6 @@ def suite(request): def test_run(suite): - schema, test = suite - - # Load schema - # Currently missing the "id" field - with open(schema["id"]) as f: - schema = json.load(f) - schema_store = { - schema['$id']: schema - } - resolver = RefResolver.from_schema(schema, store=schema_store) - validator = Draft7Validator(schema, resolver=resolver) - - # Load data and test - jsondata = test["data"] - valid = test["valid"] - if not valid: - with pytest.raises(ValidationError): - validator.validate(jsondata) \ No newline at end of file + resolver = RefResolver.from_schema(suite.schema, store=suite.schema_store) + validator = Draft7Validator(suite.schema, resolver=resolver) + suite.validate(validator) \ No newline at end of file From 7c5e989aec1ae6035eb15f20bcb7fb382f9a2e8f Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 12 May 2022 16:06:49 +0200 Subject: [PATCH 5/7] Fix TBDs in strict json --- latest/tests/strict_image_suite.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/latest/tests/strict_image_suite.json b/latest/tests/strict_image_suite.json index 3122ab98..b8aeebe1 100644 --- a/latest/tests/strict_image_suite.json +++ b/latest/tests/strict_image_suite.json @@ -110,7 +110,7 @@ } ] }, - "valid": "TBD" + "valid": true }, { "formerly": "valid_strict/multiscales_transformations.json", @@ -162,7 +162,7 @@ } ] }, - "valid": "TBD" + "valid": true }, { "formerly": "valid_strict/image_metadata.json", @@ -216,7 +216,7 @@ } ] }, - "valid": "TBD" + "valid": true }, { "formerly": "valid_strict/image.json", @@ -259,7 +259,7 @@ } ] }, - "valid": "TBD" + "valid": true }, { "formerly": "valid_strict/image_omero.json", @@ -382,7 +382,7 @@ "version": "0.5-dev" } }, - "valid": "TBD" + "valid": true } ] } From 67384348048135fc15ff34644d2c7c0f6e7b58b9 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 12 May 2022 16:40:07 +0200 Subject: [PATCH 6/7] Upgrade jsonschema to use Draft202012Validator --- latest/tests/test_validation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/latest/tests/test_validation.py b/latest/tests/test_validation.py index 3eed18b6..83f49911 100644 --- a/latest/tests/test_validation.py +++ b/latest/tests/test_validation.py @@ -6,7 +6,7 @@ import pytest -from jsonschema import RefResolver, Draft7Validator +from jsonschema import RefResolver, Draft202012Validator as Validator from jsonschema.exceptions import ValidationError @@ -35,7 +35,7 @@ def pytest_generate_tests(metafunc): what should be run. It is assumed that all files are valid and complete so that they can be wholly included into the specification. The .config.json file in each directory defines which schema will be used. - + Validation: These test consumes https://github.com/json-schema-org/JSON-Schema-Test-Suite#structure-of-a-test styled JSON tests. Metadata in each test defines which schema is used @@ -81,5 +81,5 @@ def suite(request): def test_run(suite): resolver = RefResolver.from_schema(suite.schema, store=suite.schema_store) - validator = Draft7Validator(suite.schema, resolver=resolver) - suite.validate(validator) \ No newline at end of file + validator = Validator(suite.schema, resolver=resolver) + suite.validate(validator) From e151ae06b96fb2e40c5827ba11b079c39bd1830b Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Thu, 12 May 2022 18:20:48 +0200 Subject: [PATCH 7/7] Remove 'invalid but doesn't fail' test --- latest/tests/image_suite.json | 40 +---------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/latest/tests/image_suite.json b/latest/tests/image_suite.json index e92378ec..39cb73d5 100644 --- a/latest/tests/image_suite.json +++ b/latest/tests/image_suite.json @@ -1143,44 +1143,6 @@ ] }, "valid": false - }, - { - "formerly": "invalid_but_dont_fail/duplicate_axes_name.json", - "description": "TBD", - "data": { - "multiscales": [ - { - "axes": [ - { - "name": "x", - "type": "space", - "units": "meter" - }, - { - "name": "x", - "type": "space", - "units": "micrometer" - } - ], - "datasets": [ - { - "path": "0", - "coordinateTransformations": [ - { - "scale": [ - 0.13, - 0.13 - ], - "type": "scale" - } - ] - } - ], - "version": "0.5-dev" - } - ] - }, - "valid": false } ] -} \ No newline at end of file +}