Skip to content

Commit 3f0780a

Browse files
Merge branch 'dev' into order_of_images
2 parents 3cbe0ba + fd01962 commit 3f0780a

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

nwbinspector/nwbinspector.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pathlib import Path
99
from collections.abc import Iterable
1010
from enum import Enum
11-
from typing import Optional, List
11+
from typing import Union, Optional, List
1212
from concurrent.futures import ProcessPoolExecutor, as_completed
1313
from types import FunctionType
1414
from warnings import filterwarnings, warn
@@ -278,7 +278,7 @@ def inspect_all(
278278
config: Optional[dict] = None,
279279
ignore: OptionalListOfStrings = None,
280280
select: OptionalListOfStrings = None,
281-
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
281+
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
282282
n_jobs: int = 1,
283283
skip_validate: bool = False,
284284
progress_bar: bool = True,
@@ -305,7 +305,7 @@ def inspect_all(
305305
Names of functions to skip.
306306
select: list of strings, optional
307307
Names of functions to pick out of available checks.
308-
importance_threshold : string, optional
308+
importance_threshold : string or Importance, optional
309309
Ignores tests with an assigned importance below this threshold.
310310
Importance has three levels:
311311
CRITICAL
@@ -336,6 +336,9 @@ def inspect_all(
336336
Common options are 'draft' or 'published'.
337337
Defaults to the most recent published version, or if not published then the most recent draft version.
338338
"""
339+
importance_threshold = (
340+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
341+
)
339342
modules = modules or []
340343
if progress_bar_options is None:
341344
progress_bar_options = dict(position=0, leave=False)
@@ -410,7 +413,7 @@ def inspect_nwb(
410413
config: dict = None,
411414
ignore: OptionalListOfStrings = None,
412415
select: OptionalListOfStrings = None,
413-
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
416+
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
414417
driver: str = None,
415418
skip_validate: bool = False,
416419
) -> List[InspectorMessage]:
@@ -431,7 +434,7 @@ def inspect_nwb(
431434
Names of functions to skip.
432435
select: list, optional
433436
Names of functions to pick out of available checks.
434-
importance_threshold : string, optional
437+
importance_threshold : string or Importance, optional
435438
Ignores tests with an assigned importance below this threshold.
436439
Importance has three levels:
437440
CRITICAL
@@ -447,6 +450,9 @@ def inspect_nwb(
447450
Skip the PyNWB validation step. This may be desired for older NWBFiles (< schema version v2.10).
448451
The default is False, which is also recommended.
449452
"""
453+
importance_threshold = (
454+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
455+
)
450456
if any(x is not None for x in [config, ignore, select, importance_threshold]):
451457
checks = configure_checks(
452458
checks=checks, config=config, ignore=ignore, select=select, importance_threshold=importance_threshold

tests/test_inspector.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_inspect_nwb(self):
330330
]
331331
self.assertCountEqual(first=test_results, second=true_results)
332332

333-
def test_inspect_nwb_importance_threshold(self):
333+
def test_inspect_nwb_importance_threshold_as_importance(self):
334334
test_results = list(
335335
inspect_nwb(
336336
nwbfile_path=self.nwbfile_paths[0], checks=self.checks, importance_threshold=Importance.CRITICAL
@@ -361,6 +361,35 @@ def test_inspect_nwb_importance_threshold(self):
361361
]
362362
self.assertCountEqual(first=test_results, second=true_results)
363363

364+
def test_inspect_nwb_importance_threshold_as_string(self):
365+
test_results = list(
366+
inspect_nwb(nwbfile_path=self.nwbfile_paths[0], checks=self.checks, importance_threshold="CRITICAL")
367+
)
368+
true_results = [
369+
InspectorMessage(
370+
message=(
371+
"Data may be in the wrong orientation. Time should be in the first dimension, and is "
372+
"usually the longest dimension. Here, another dimension is longer."
373+
),
374+
importance=Importance.CRITICAL,
375+
check_function_name="check_data_orientation",
376+
object_type="SpatialSeries",
377+
object_name="my_spatial_series",
378+
location="/processing/behavior/Position/my_spatial_series",
379+
file_path=self.nwbfile_paths[0],
380+
),
381+
InspectorMessage(
382+
message="The length of the first dimension of data does not match the length of timestamps.",
383+
importance=Importance.CRITICAL,
384+
check_function_name="check_timestamps_match_first_dimension",
385+
object_type="TimeSeries",
386+
object_name="test_time_series_3",
387+
location="/acquisition/test_time_series_3",
388+
file_path=self.nwbfile_paths[0],
389+
),
390+
]
391+
self.assertCountEqual(first=test_results, second=true_results)
392+
364393
def test_command_line_runs_cli_only(self):
365394
console_output_file = self.tempdir / "test_console_output.txt"
366395
os.system(

tests/unit_tests/test_tables.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import platform
22
import json
33
from unittest import TestCase
4+
from packaging import version
45

56
import numpy as np
67
from hdmf.common import DynamicTable, DynamicTableRegion
@@ -17,6 +18,7 @@
1718
check_single_row,
1819
check_table_values_for_dict,
1920
)
21+
from nwbinspector.utils import get_package_version
2022

2123

2224
class TestCheckDynamicTableRegion(TestCase):
@@ -237,16 +239,27 @@ def test_check_single_row_ignore_electrodes():
237239
table = ElectrodeTable(
238240
name="electrodes", # default name when building through nwbfile
239241
)
240-
table.add_row(
241-
x=np.nan,
242-
y=np.nan,
243-
z=np.nan,
244-
imp=np.nan,
245-
location="unknown",
246-
filtering="unknown",
247-
group=ElectrodeGroup(name="test_group", description="", device=Device(name="test_device"), location="unknown"),
248-
group_name="test_group",
249-
)
242+
if get_package_version(name="pynwb") >= version.Version("2.1.0"):
243+
table.add_row(
244+
location="unknown",
245+
group=ElectrodeGroup(
246+
name="test_group", description="", device=Device(name="test_device"), location="unknown"
247+
),
248+
group_name="test_group",
249+
)
250+
else:
251+
table.add_row(
252+
x=np.nan,
253+
y=np.nan,
254+
z=np.nan,
255+
imp=np.nan,
256+
location="unknown",
257+
filtering="unknown",
258+
group=ElectrodeGroup(
259+
name="test_group", description="", device=Device(name="test_device"), location="unknown"
260+
),
261+
group_name="test_group",
262+
)
250263
assert check_single_row(table=table) is None
251264

252265

0 commit comments

Comments
 (0)