Repository navigation
Expand file tree
/
Copy pathtests.py
More file actions
50 lines (42 loc) · 1.75 KB
/
Copy pathtests.py
File metadata and controls
50 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import glob
import json
import jsonschema
import pytest
import requests
# Validate against the schema of the latest *released* probeinterface, not main:
# the catalog is meant to be readable by the version users actually install.
pypi_response = requests.get("https://pypi.org/pypi/probeinterface/json")
pypi_response.raise_for_status()
probeinterface_version = pypi_response.json()["info"]["version"]
schema_url = (
f"https://raw.githubusercontent.com/SpikeInterface/probeinterface/{probeinterface_version}/"
"src/probeinterface/schema/probe.json.schema"
)
response = requests.get(schema_url)
response.raise_for_status()
# Probe files live at <manufacturer>/<model>/<model>.json. Exclude directories
# that are not probe data (the probe-viewer app ships its own JSON config files).
NON_PROBE_DIRS = {"apps", "scripts", "node_modules", ".github"}
files = [
file
for file in glob.glob("*/*/*.json")
if file.split("/")[0] not in NON_PROBE_DIRS
]
@pytest.mark.parametrize("file", files)
def test_valid_probe_dict(file):
with open(file) as f:
data = json.load(f)
jsonschema.validate(data, response.json())
@pytest.mark.parametrize("file", files)
def test_naming_convention(file):
"""Check that model_name and manufacturer are lowercase. and they correspond to the path."""
with open(file) as f:
data = json.load(f)
probe_annotations = data["probes"][0]["annotations"]
model_name = probe_annotations["model_name"]
manufacturer = probe_annotations["manufacturer"]
assert manufacturer == manufacturer.lower()
path_parts = file.split("/")
assert model_name == path_parts[-1].replace(".json", "")
assert model_name == path_parts[-2]
assert manufacturer == path_parts[-3]