Skip to content

Commit

Permalink
Merge pull request #351 from scott-huberty/derivatives_repr
Browse files Browse the repository at this point in the history
ENH: better repr for Derivatives class
  • Loading branch information
mgxd authored Mar 27, 2024
2 parents 1829514 + de12306 commit 653491e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nibabies/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def __init__(self, bids_root: Path | str, spec: dict | Path | str | None = None,
setattr(self, name, None)

def __repr__(self):
return '\n'.join([name for name in self.names if getattr(self, name)])
output = ["Derivatives |"]
output.extend([f" {attr}: {getattr(self, attr)}" for attr in self.names])
return '\n'.join(output)

def __contains__(self, val: str):
return val in self.names
Expand Down
3 changes: 3 additions & 0 deletions nibabies/utils/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_derivatives(
assert derivatives.aseg is None
assert derivatives.t1w_aseg is None
assert derivatives.t2w_aseg is None
assert "t1w_mask" in repr(derivatives)

derivatives.populate(deriv_dir, subject_id='01')
if mask:
Expand All @@ -111,3 +112,5 @@ def test_derivatives(
assert derivatives.references[aseg]
else:
assert derivatives.aseg == None
if t1w_mask:
assert "sub-01_space-T1w_desc-brain_mask.nii.gz" in repr(derivatives)

0 comments on commit 653491e

Please sign in to comment.