Skip to content

Commit

Permalink
ENH resource representation
Browse files Browse the repository at this point in the history
  • Loading branch information
xgrg committed Oct 8, 2020
1 parent b8a84fe commit 9a60a22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions pyxnat/core/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1825,15 +1825,14 @@ def __repr__(self):
if self.exists():

# Fetch data files
files_counter = len(self.files().fetchall())
files_count = len(self.files().fetchall())

# Creating the dictionary
d = {'Resource': resource_id, 'Files': files_counter
}
# Creating the output string to be returned
output = ''
for n, v in d.items():
output = output + '\n' + "{}: {}".format(n, v)
output = '<{cl} Object> {id} `{label}` ({fc} files)'
output = output.format(label=self.label(),
cl=self.__class__.__name__,
id=resource_id,
fc=files_count)
return output
else:
return '<%s Object> %s' % (self.__class__.__name__,
Expand Down
3 changes: 2 additions & 1 deletion pyxnat/tests/repr_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@ def test_resource_not_exists():
@skip_if_no_network
def test_info_resource():
assert isinstance(resource_1, object)
expected_output = '\n' + 'Resource: obscure_algorithm_output' + '\n' + 'Files: 66'
expected_output = '<Resource Object> obscure_algorithm_output '\
'`obscure_algorithm_output` (66 files)'
assert list(sorted(str(resource_1))) == list(sorted(expected_output))

0 comments on commit 9a60a22

Please sign in to comment.