diff --git a/pyvo/registry/regtap.py b/pyvo/registry/regtap.py index a17d75567..f736cb3c3 100644 --- a/pyvo/registry/regtap.py +++ b/pyvo/registry/regtap.py @@ -855,13 +855,16 @@ def describe(self, verbose=False, width=78, file=None): if verbose: if self.source_value: print(f"\nSource: {self.source_value}", file=file) - # don't print creators if its first value is overly long - if self.creators and len(self.creators[0]) < width: + if self.creators: + # if any creator has a name longer than 70 characters, we + # truncate it. + creators = [f"{creator[:70]}..." if len(creator) > 70 + else creator for creator in self.creators] nmax_authors = 5 - if len(self.creators) <= nmax_authors: - print(f"Authors: {', '.join(self.creators)}", file=file) + if len(creators) <= nmax_authors: + print(f"Authors: {', '.join(creators)}", file=file) else: - print(f"Authors: {', '.join(self.creators[:nmax_authors])} et al.\n" + print(f"Authors: {', '.join(creators[:nmax_authors])} et al.\n" "See creators attribute for the complete list of authors.", file=file) if self.alt_identifier: print(f"Alternative identifier: {self.alt_identifier}", file=file) diff --git a/pyvo/registry/tests/test_regtap.py b/pyvo/registry/tests/test_regtap.py index 2720c34bf..78216332b 100644 --- a/pyvo/registry/tests/test_regtap.py +++ b/pyvo/registry/tests/test_regtap.py @@ -736,9 +736,7 @@ def test_describe_multi(self, flash_service): assert "More info: http://dc.zah" in output def test_describe_long_authors_list(self): - # generate a registry record with minimum - # information for the describe method and - # a long list of authors + """Check that long list of authors use et al..""" rsc = _makeRegistryRecord( access_urls=[], standard_ids=["ivo://pyvo/test"], @@ -754,6 +752,23 @@ def test_describe_long_authors_list(self): # output should cut at 5 authors assert "Authors: a, a, a, a, a et al." in output + def test_describe_long_author_name(self): + """Check that long author names are truncated.""" + rsc = _makeRegistryRecord( + access_urls=[], + standard_ids=["ivo://pyvo/test"], + short_name=["name"], + intf_types=[], + intf_roles=[], + creator_seq=["a" * 71], + res_title=["title"] + ) + out = io.StringIO() + rsc.describe(verbose=True, file=out) + output = out.getvalue() + # should cut the long author name at 70 characters + assert f"Authors: {'a'*70}..." in output + def test_no_access_url(self): rsc = _makeRegistryRecord( access_urls=[],