Skip to content

Commit

Permalink
Merge pull request #634 from VisLab/dev_refactor
Browse files Browse the repository at this point in the history
Updated bids tests
  • Loading branch information
VisLab authored Mar 23, 2023
2 parents a1e61df + bc5c949 commit f2455d8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
10 changes: 3 additions & 7 deletions hed/tools/bids/bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,14 @@ def validate(self, types=None, check_for_warnings=True):
list: List of issues encountered during validation. Each issue is a dictionary.
"""
validator = HedValidator(hed_schema=self.schema)
error_handler = ErrorHandler()

if not types:
types = list(self.tabular_files.keys())
issues = []
for tab_type in types:
files = self.tabular_files[tab_type]
issues += files.validate_sidecars(self.schema,
check_for_warnings=check_for_warnings, error_handler=error_handler)
issues += files.validate_datafiles(self.schema,
check_for_warnings=check_for_warnings,
error_handler=error_handler)
issues += files.validate_sidecars(self.schema, check_for_warnings=check_for_warnings)
issues += files.validate_datafiles(self.schema, check_for_warnings=check_for_warnings)
return issues

def get_summary(self):
Expand Down
5 changes: 3 additions & 2 deletions hed/tools/bids/bids_file_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def validate_sidecars(self, hed_schema, extra_def_dicts=None, check_for_warnings

for sidecar in self.sidecar_dict.values():
name = os.path.basename(sidecar.file_path)
issues += validator.validate(extra_def_dicts=extra_def_dicts, name=name, error_handler=error_handler)
issues += validator.validate(sidecar.contents, extra_def_dicts=extra_def_dicts, name=name,
error_handler=error_handler)
return issues

def validate_datafiles(self, hed_schema, extra_def_dicts=None, check_for_warnings=True, keep_contents=False):
Expand All @@ -154,7 +155,7 @@ def validate_datafiles(self, hed_schema, extra_def_dicts=None, check_for_warning
for data_obj in self.datafile_dict.values():
data_obj.set_contents(overwrite=False)
name = os.path.basename(data_obj.file_path)
issues += data_obj.contents.validate(data_obj.contents, extra_def_dicts=None, name=name,
issues += data_obj.contents.validate(hed_schema, extra_def_dicts=None, name=name,
error_handler=error_handler)
if not keep_contents:
data_obj.clear_contents()
Expand Down
1 change: 0 additions & 1 deletion tests/tools/analysis/test_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def test_constructor(self):
self.assertEqual(event.start_time, manager1.data.dataframe.loc[index, "onset"])
if not event.end_time:
self.assertEqual(event.end_index, len(manager1.data.dataframe))
print("to here")

# def test_constructor(self):
# with self.assertRaises(ValueError) as cont:
Expand Down
15 changes: 6 additions & 9 deletions tests/tools/bids/test_bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,18 @@ def test_validator(self):
self.assertTrue(issues, "BidsDataset validate should return issues when the default check_for_warnings is used")
issues = bids.validate(check_for_warnings=True)
self.assertTrue(issues, "BidsDataset validate should return issues when check_for_warnings is True")
# ToDO
# issues = bids.validate(check_for_warnings=False)
# self.assertFalse(issues, "BidsDataset validate should return no issues when check_for_warnings is False")
issues = bids.validate(check_for_warnings=False)
self.assertFalse(issues, "BidsDataset validate should return no issues when check_for_warnings is False")

def test_validator_libraries(self):
bids = BidsDataset(self.library_path)
# ToDO check_for_warnings
# issues = bids.validate(check_for_warnings=False)
# self.assertFalse(issues, "BidsDataset with libraries should validate")
issues = bids.validate(check_for_warnings=False)
self.assertFalse(issues, "BidsDataset with libraries should validate")

def test_validator_types(self):
bids = BidsDataset(self.root_path, tabular_types=None)
# ToDO: check_for_warnings
# issues = bids.validate(check_for_warnings=False)
# self.assertFalse(issues, "BidsDataset with participants and events validates")
issues = bids.validate(check_for_warnings=False)
self.assertFalse(issues, "BidsDataset with participants and events validates")

def test_with_schema_group(self):
base_version = '8.0.0'
Expand Down
4 changes: 1 addition & 3 deletions tests/tools/remodeling/cli/test_run_remodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def test_main_bids_no_sidecar_with_hed(self):
os.remove(self.sidecar_path)
with patch('sys.stdout', new=io.StringIO()) as fp:
main(arg_list)
a = fp.getvalue()
print("to here")
#self.assertFalse(fp.getvalue())
self.assertFalse(fp.getvalue())

def test_main_direct_no_sidecar(self):
arg_list = [self.data_root, self.model_path, '-x', 'derivatives', 'stimuli']
Expand Down

0 comments on commit f2455d8

Please sign in to comment.