Skip to content

Commit a4008a0

Browse files
Merge branch 'dev' into add_curl_retry
2 parents d98fcc5 + fd01962 commit a4008a0

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
@@ -279,7 +279,7 @@ def inspect_all(
279279
config: Optional[dict] = None,
280280
ignore: OptionalListOfStrings = None,
281281
select: OptionalListOfStrings = None,
282-
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
282+
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
283283
n_jobs: int = 1,
284284
skip_validate: bool = False,
285285
progress_bar: bool = True,
@@ -306,7 +306,7 @@ def inspect_all(
306306
Names of functions to skip.
307307
select: list of strings, optional
308308
Names of functions to pick out of available checks.
309-
importance_threshold : string, optional
309+
importance_threshold : string or Importance, optional
310310
Ignores tests with an assigned importance below this threshold.
311311
Importance has three levels:
312312
CRITICAL
@@ -337,6 +337,9 @@ def inspect_all(
337337
Common options are 'draft' or 'published'.
338338
Defaults to the most recent published version, or if not published then the most recent draft version.
339339
"""
340+
importance_threshold = (
341+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
342+
)
340343
modules = modules or []
341344
if progress_bar_options is None:
342345
progress_bar_options = dict(position=0, leave=False)
@@ -411,7 +414,7 @@ def inspect_nwb(
411414
config: dict = None,
412415
ignore: OptionalListOfStrings = None,
413416
select: OptionalListOfStrings = None,
414-
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
417+
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
415418
driver: Optional[str] = None,
416419
skip_validate: bool = False,
417420
max_retries: int = 10,
@@ -433,7 +436,7 @@ def inspect_nwb(
433436
Names of functions to skip.
434437
select: list, optional
435438
Names of functions to pick out of available checks.
436-
importance_threshold : string, optional
439+
importance_threshold : string or Importance, optional
437440
Ignores tests with an assigned importance below this threshold.
438441
Importance has three levels:
439442
CRITICAL
@@ -454,6 +457,9 @@ def inspect_nwb(
454457
This sets a hard bound on the number of times to attempt to retry the collection of messages.
455458
Defaults to 10 (corresponds to 102.4s maximum delay on final attempt).
456459
"""
460+
importance_threshold = (
461+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
462+
)
457463
if any(x is not None for x in [config, ignore, select, importance_threshold]):
458464
checks = configure_checks(
459465
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)