Skip to content

Commit 4ccdf14

Browse files
Merge branch 'dev' into negative_job_slicing
2 parents b0f87a2 + fd01962 commit 4ccdf14

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
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
@@ -338,6 +338,9 @@ def inspect_all(
338338
Common options are 'draft' or 'published'.
339339
Defaults to the most recent published version, or if not published then the most recent draft version.
340340
"""
341+
importance_threshold = (
342+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
343+
)
341344
modules = modules or []
342345
n_jobs = calculate_number_of_cpu(requested_cpu=n_jobs)
343346
if progress_bar_options is None:
@@ -413,7 +416,7 @@ def inspect_nwb(
413416
config: dict = None,
414417
ignore: OptionalListOfStrings = None,
415418
select: OptionalListOfStrings = None,
416-
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
419+
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
417420
driver: str = None,
418421
skip_validate: bool = False,
419422
) -> List[InspectorMessage]:
@@ -434,7 +437,7 @@ def inspect_nwb(
434437
Names of functions to skip.
435438
select: list, optional
436439
Names of functions to pick out of available checks.
437-
importance_threshold : string, optional
440+
importance_threshold : string or Importance, optional
438441
Ignores tests with an assigned importance below this threshold.
439442
Importance has three levels:
440443
CRITICAL
@@ -450,6 +453,9 @@ def inspect_nwb(
450453
Skip the PyNWB validation step. This may be desired for older NWBFiles (< schema version v2.10).
451454
The default is False, which is also recommended.
452455
"""
456+
importance_threshold = (
457+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
458+
)
453459
if any(x is not None for x in [config, ignore, select, importance_threshold]):
454460
checks = configure_checks(
455461
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(

0 commit comments

Comments
 (0)