Skip to content

Commit ccaefd0

Browse files
author
Cody Baker
committed
simplify other PR
1 parent 8037569 commit ccaefd0

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

nwbinspector/nwbinspector.py

Lines changed: 12 additions & 9 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
@@ -153,10 +153,7 @@ def configure_checks(
153153
@click.argument("path")
154154
@click.option("--modules", help="Modules to import prior to reading the file(s).")
155155
@click.option(
156-
"--report-file-path",
157-
default=None,
158-
help="Save path for the report file.",
159-
type=click.Path(writable=True),
156+
"--report-file-path", default=None, help="Save path for the report file.", type=click.Path(writable=True),
160157
)
161158
@click.option("--overwrite", help="Overwrite an existing report file at the location.", is_flag=True)
162159
@click.option("--levels", help="Comma-separated names of InspectorMessage attributes to organize by.")
@@ -278,7 +275,7 @@ def inspect_all(
278275
config: Optional[dict] = None,
279276
ignore: OptionalListOfStrings = None,
280277
select: OptionalListOfStrings = None,
281-
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
278+
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
282279
n_jobs: int = 1,
283280
skip_validate: bool = False,
284281
progress_bar: bool = True,
@@ -305,7 +302,7 @@ def inspect_all(
305302
Names of functions to skip.
306303
select: list of strings, optional
307304
Names of functions to pick out of available checks.
308-
importance_threshold : string, optional
305+
importance_threshold : string or Importance, optional
309306
Ignores tests with an assigned importance below this threshold.
310307
Importance has three levels:
311308
CRITICAL
@@ -336,6 +333,9 @@ def inspect_all(
336333
Common options are 'draft' or 'published'.
337334
Defaults to the most recent published version, or if not published then the most recent draft version.
338335
"""
336+
importance_threshold = (
337+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
338+
)
339339
modules = modules or []
340340
if progress_bar_options is None:
341341
progress_bar_options = dict(position=0, leave=False)
@@ -410,7 +410,7 @@ def inspect_nwb(
410410
config: dict = None,
411411
ignore: OptionalListOfStrings = None,
412412
select: OptionalListOfStrings = None,
413-
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
413+
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
414414
driver: str = None,
415415
skip_validate: bool = False,
416416
) -> List[InspectorMessage]:
@@ -431,7 +431,7 @@ def inspect_nwb(
431431
Names of functions to skip.
432432
select: list, optional
433433
Names of functions to pick out of available checks.
434-
importance_threshold : string, optional
434+
importance_threshold : string or Importance, optional
435435
Ignores tests with an assigned importance below this threshold.
436436
Importance has three levels:
437437
CRITICAL
@@ -447,6 +447,9 @@ def inspect_nwb(
447447
Skip the PyNWB validation step. This may be desired for older NWBFiles (< schema version v2.10).
448448
The default is False, which is also recommended.
449449
"""
450+
importance_threshold = (
451+
Importance[importance_threshold] if isinstance(importance_threshold, str) else importance_threshold
452+
)
450453
if any(x is not None for x in [config, ignore, select, importance_threshold]):
451454
checks = configure_checks(
452455
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)