diff --git a/pyproject.toml b/pyproject.toml index cbdbbda..23bf8b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ package-dir = {"probeinterface" = "src/probeinterface"} [project.optional-dependencies] test = [ + "jsonschema", "pytest", "pytest-cov", "matplotlib", diff --git a/resources/probe.json.schema b/resources/probe.json.schema index eecdda1..9d09e1b 100644 --- a/resources/probe.json.schema +++ b/resources/probe.json.schema @@ -26,10 +26,10 @@ "annotations": { "type": "object", "properties": { - "name": { "type": "string" }, + "model_name": { "type": "string" }, "manufacturer": { "type": "string" } }, - "required": ["name", "manufacturer"], + "required": ["model_name", "manufacturer"], "additionalProperties": true }, "contact_annotations": { @@ -101,6 +101,10 @@ "shank_ids": { "type": "array", "items": { "type": "string" } + }, + "device_channel_indices": { + "type": "array", + "items": { "type": "integer" } } }, "required": [ diff --git a/src/probeinterface/probe.py b/src/probeinterface/probe.py index 2fc137a..4cbf5a4 100644 --- a/src/probeinterface/probe.py +++ b/src/probeinterface/probe.py @@ -2,7 +2,6 @@ import numpy as np from typing import Optional from pathlib import Path -import json from .shank import Shank diff --git a/src/probeinterface/testing.py b/src/probeinterface/testing.py new file mode 100644 index 0000000..1b3131c --- /dev/null +++ b/src/probeinterface/testing.py @@ -0,0 +1,13 @@ +import json +from pathlib import Path + +from probeinterface import __version__ as version +import jsonschema + +json_schema_file = Path(__file__).absolute().parent.parent.parent / "resources" / "probe.json.schema" +schema = json.load(open(json_schema_file, "r")) + + +def validate_probe_dict(probe_dict): + instance = dict(specification="probeinterface", version=version, probes=[probe_dict]) + jsonschema.validate(instance=instance, schema=schema) diff --git a/tests/test_io/test_3brain.py b/tests/test_io/test_3brain.py index 11a4473..1128a23 100644 --- a/tests/test_io/test_3brain.py +++ b/tests/test_io/test_3brain.py @@ -1,3 +1,4 @@ +import glob from pathlib import Path import numpy as np @@ -5,7 +6,19 @@ from probeinterface import read_3brain +from probeinterface.testing import validate_probe_dict + + data_path = Path(__file__).absolute().parent.parent / "data" / "3brain" +brw_files = glob.glob(str(data_path / "*.brw")) + + +@pytest.mark.parametrize("file_", brw_files) +def test_valid_probe_dict(file_: str): + probe = read_3brain(data_path / file_) + probe_dict = probe.to_dict(array_as_list=True) + probe_dict["annotations"].update(model_name="placeholder") + validate_probe_dict(probe_dict) def test_3brain(): diff --git a/tests/test_io/test_imro.py b/tests/test_io/test_imro.py index 9e6e269..a579047 100644 --- a/tests/test_io/test_imro.py +++ b/tests/test_io/test_imro.py @@ -1,11 +1,22 @@ +import glob from pathlib import Path import pytest import numpy as np from probeinterface import read_imro, write_imro +from probeinterface.testing import validate_probe_dict data_path = Path(__file__).absolute().parent.parent / "data" / "imro" +imro_files = glob.glob(str(data_path / "*.imro")) + +imro_files.pop(imro_files.index(str(data_path / "test_non_standard.imro"))) + + +@pytest.mark.parametrize("file_", imro_files) +def test_valid_probe_dict(file_: str): + probe = read_imro(data_path / file_) + validate_probe_dict(probe.to_dict(array_as_list=True)) def test_reading_multishank_imro(tmp_path): diff --git a/tests/test_io/test_maxwell.py b/tests/test_io/test_maxwell.py index f6b6851..664b5d6 100644 --- a/tests/test_io/test_maxwell.py +++ b/tests/test_io/test_maxwell.py @@ -4,10 +4,19 @@ import pytest from probeinterface import read_maxwell +from probeinterface.testing import validate_probe_dict data_path = Path(__file__).absolute().parent.parent / "data" / "maxwell" +def test_valid_probe_dict(): + file_ = "data.raw.h5" + probe = read_maxwell(data_path / file_) + probe_dict = probe.to_dict(array_as_list=True) + probe_dict["annotations"].update(model_name="placeholder") + validate_probe_dict(probe_dict) + + def test_maxwell(): """Basic file taken from the ephys data repository and provided by Alessio Buccino""" diff --git a/tests/test_io/test_spikeglx.py b/tests/test_io/test_spikeglx.py index f32ee6e..e6bc657 100644 --- a/tests/test_io/test_spikeglx.py +++ b/tests/test_io/test_spikeglx.py @@ -1,3 +1,4 @@ +import glob from pathlib import Path import numpy as np @@ -8,8 +9,16 @@ parse_spikeglx_meta, get_saved_channel_indices_from_spikeglx_meta, ) +from probeinterface.testing import validate_probe_dict data_path = Path(__file__).absolute().parent.parent / "data" / "spikeglx" +meta_files = glob.glob(str(data_path / "*.meta")) + + +@pytest.mark.parametrize("meta_file", meta_files) +def test_valid_probe_dict(meta_file: str): + probe = read_spikeglx(data_path / meta_file) + validate_probe_dict(probe.to_dict(array_as_list=True)) def test_parse_meta():