|
19 | 19 | check_regular_timestamps, |
20 | 20 | check_data_orientation, |
21 | 21 | check_timestamps_match_first_dimension, |
| 22 | + check_subject_exists, |
| 23 | + load_config, |
22 | 24 | ) |
23 | | -from nwbinspector.nwbinspector import inspect_all, inspect_nwb |
| 25 | +from nwbinspector import inspect_all, inspect_nwb |
24 | 26 | from nwbinspector.register_checks import Severity, InspectorMessage, register_check |
25 | 27 | from nwbinspector.utils import FilePathType, is_module_installed |
26 | 28 | from nwbinspector.tools import make_minimal_nwbfile |
@@ -146,7 +148,7 @@ def assertLogFileContentsEqual( |
146 | 148 | if ".nwb" in test_line: |
147 | 149 | # Transform temporary testing path and formatted to hardcoded fake path |
148 | 150 | str_loc = test_line.find(".nwb") |
149 | | - correction_str = test_line.replace(test_line[5 : str_loc - 8], "./") # noqa E203 (black) |
| 151 | + correction_str = test_line.replace(test_line[5 : str_loc - 8], "./") # noqa: E203 (black) |
150 | 152 | test_file_lines[line_number] = correction_str |
151 | 153 | self.assertEqual(first=test_file_lines[skip_first_n_lines:-1], second=true_file_lines) |
152 | 154 |
|
@@ -503,6 +505,71 @@ def test_inspect_nwb_manual_iteration_stop(self): |
503 | 505 | with self.assertRaises(expected_exception=StopIteration): |
504 | 506 | next(generator) |
505 | 507 |
|
| 508 | + def test_inspect_nwb_dandi_config(self): |
| 509 | + config_checks = [check_subject_exists] + self.checks |
| 510 | + test_results = list( |
| 511 | + inspect_nwb( |
| 512 | + nwbfile_path=self.nwbfile_paths[0], |
| 513 | + checks=config_checks, |
| 514 | + config=load_config(filepath_or_keyword="dandi"), |
| 515 | + ) |
| 516 | + ) |
| 517 | + true_results = [ |
| 518 | + InspectorMessage( |
| 519 | + message="Subject is missing.", |
| 520 | + importance=Importance.BEST_PRACTICE_SUGGESTION, |
| 521 | + check_function_name="check_subject_exists", |
| 522 | + object_type="NWBFile", |
| 523 | + object_name="root", |
| 524 | + location="/", |
| 525 | + file_path=self.nwbfile_paths[0], |
| 526 | + ), |
| 527 | + InspectorMessage( |
| 528 | + message="data is not compressed. Consider enabling compression when writing a dataset.", |
| 529 | + importance=Importance.BEST_PRACTICE_SUGGESTION, |
| 530 | + check_function_name="check_small_dataset_compression", |
| 531 | + object_type="TimeSeries", |
| 532 | + object_name="test_time_series_1", |
| 533 | + location="/acquisition/test_time_series_1", |
| 534 | + file_path=self.nwbfile_paths[0], |
| 535 | + ), |
| 536 | + InspectorMessage( |
| 537 | + message=( |
| 538 | + "TimeSeries appears to have a constant sampling rate. " |
| 539 | + "Consider specifying starting_time=1.2 and rate=2.0 instead of timestamps." |
| 540 | + ), |
| 541 | + importance=Importance.BEST_PRACTICE_VIOLATION, |
| 542 | + check_function_name="check_regular_timestamps", |
| 543 | + object_type="TimeSeries", |
| 544 | + object_name="test_time_series_2", |
| 545 | + location="/acquisition/test_time_series_2", |
| 546 | + file_path=self.nwbfile_paths[0], |
| 547 | + ), |
| 548 | + InspectorMessage( |
| 549 | + message=( |
| 550 | + "Data may be in the wrong orientation. " |
| 551 | + "Time should be in the first dimension, and is usually the longest dimension. " |
| 552 | + "Here, another dimension is longer." |
| 553 | + ), |
| 554 | + importance=Importance.CRITICAL, |
| 555 | + check_function_name="check_data_orientation", |
| 556 | + object_type="SpatialSeries", |
| 557 | + object_name="my_spatial_series", |
| 558 | + location="/processing/behavior/Position/my_spatial_series", |
| 559 | + file_path=self.nwbfile_paths[0], |
| 560 | + ), |
| 561 | + InspectorMessage( |
| 562 | + message="The length of the first dimension of data does not match the length of timestamps.", |
| 563 | + importance=Importance.CRITICAL, |
| 564 | + check_function_name="check_timestamps_match_first_dimension", |
| 565 | + object_type="TimeSeries", |
| 566 | + object_name="test_time_series_3", |
| 567 | + location="/acquisition/test_time_series_3", |
| 568 | + file_path=self.nwbfile_paths[0], |
| 569 | + ), |
| 570 | + ] |
| 571 | + self.assertCountEqual(first=test_results, second=true_results) |
| 572 | + |
506 | 573 |
|
507 | 574 | @pytest.mark.skipif(not HAVE_ROS3 or not HAVE_DANDI, reason="Needs h5py setup with ROS3.") |
508 | 575 | def test_dandiset_streaming(): |
|
0 commit comments