Skip to content

Commit

Permalink
repr
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Oct 23, 2023
1 parent 19d4df7 commit 927eab8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
31 changes: 23 additions & 8 deletions src/hdmf/term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,37 @@ def __init__(self,
self.sources = self.view.schema.prefixes

def __repr__(self):
terms = list(self.view_set.keys())

re = "Schema Path: %s\n" % self.term_schema_path
re += "Sources: " + ", ".join(list(self.sources.keys()))
re += "Sources: " + ", ".join(list(self.sources.keys()))+"\n"
re += "Terms: \n"
i = 0
for term in terms:
if i>4:
break

Check warning on line 68 in src/hdmf/term_set.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L68

Added line #L68 was not covered by tests
elif i==2:
re += " ... ... \n"
re += " - %s\n" % term
i += 1
re += "Number of terms: %s" % len(terms)
return re

def _repr_html_(self):
terms = list(self.view_set.keys())

re = "<b>" + "Schema Path: " + "</b>" + self.term_schema_path + "<br>"
re += "<b>" + "Sources: " + "</b>" + ", ".join(list(self.sources.keys())) + "<br>"
re += "<b> Terms: </b>"
# re += "<ul>"
re += "<li> %s </li>" % terms[0]
re += "<li> %s </li>" % terms[1]
re += "<li> %s </li>" % terms[2]
re += "<li> ... </li>"
# re += "</ul>"

i = 0
for term in terms:
if i>4:
break

Check warning on line 85 in src/hdmf/term_set.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/term_set.py#L85

Added line #L85 was not covered by tests
elif i==2:
re += "... ..."
re += "<li> %s </li>" % term
i += 1
re += "<i> Number of terms:</i> %s" % len(terms)
return re

def __perm_value_key_info(self, perm_values_dict: dict, key: str):
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/test_term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ def test_termset_setup(self):

def test_repr(self):
termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
output = 'Schema Path: tests/unit/example_test_term_set.yaml\nSources: NCBI_TAXON'
output = ('Schema Path: tests/unit/example_test_term_set.yaml\nSources: NCBI_TAXON\nTerms: \n'+
' - Homo sapiens\n - Mus musculus\n ... ... \n - Ursus arctos horribilis\n'+
' - Myrmecophaga tridactyla\nNumber of terms: 4')
self.assertEqual(repr(termset), output)

def test_repr_html(self):
termset = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
output = '<p><b>Schema Path: </b>tests/unit/example_test_term_set.yaml<br></p><p><b>Sources: </b>NCBI_TAXON</p>'
output = ('<b>Schema Path: </b>tests/unit/example_test_term_set.yaml<br><b>Sources:'+
' </b>NCBI_TAXON<br><b> Terms: </b><li> Homo sapiens </li><li> Mus musculus'+
' </li>... ...<li> Ursus arctos horribilis </li><li> Myrmecophaga tridactyla'+
' </li><i> Number of terms:</i> 4')
self.assertEqual(termset._repr_html_(), output)

def test_view_set(self):
Expand Down

0 comments on commit 927eab8

Please sign in to comment.