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