diff --git a/siphon/catalog.py b/siphon/catalog.py index b4b1039d7..d0434d2ca 100644 --- a/siphon/catalog.py +++ b/siphon/catalog.py @@ -157,7 +157,9 @@ def __str__(self): """Return a string representation of the collection.""" return str(list(self)) - __repr__ = __str__ + def __repr__(self): + """Return informative repr for DatasetCollection.""" + return str(DatasetCollection) def _try_lower(arg): @@ -297,7 +299,7 @@ def __init__(self, catalog_url): # begin parsing the xml doc root = ET.fromstring(resp.content) - self.catalog_name = root.attrib.get('name', 'No name found') + self.catalog_name = root.attrib.get('name', 'unnamed catalog') self.datasets = DatasetCollection() self.services = [] @@ -397,7 +399,9 @@ def latest(self): return TDSCatalog(latest_cat).datasets[0] raise AttributeError('"latest" not available for this catalog') - __repr__ = __str__ + def __repr__(self): + """Return informative repr for TDSCatalog.""" + return TDSCatalog.__name__ + ': ' + self.catalog_name class CatalogRef(object): @@ -449,7 +453,9 @@ def follow(self): """ return TDSCatalog(self.href) - __repr__ = __str__ + def __repr__(self): + """Return repr of CatalogRef.""" + return str(CatalogRef) + ' ' + str(self.title) class Dataset(object): diff --git a/siphon/tests/fixtures/unnamed_catalog_test b/siphon/tests/fixtures/unnamed_catalog_test new file mode 100644 index 000000000..d53c489d2 --- /dev/null +++ b/siphon/tests/fixtures/unnamed_catalog_test @@ -0,0 +1,108 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - Siphon (0.8.0+46.gc0def67.dirty) + method: GET + uri: https://www.ncei.noaa.gov/thredds/catalog/avhrr-patmos-x-cloudprops-files/catalog.xml + response: + body: + string: "\r\n\r\n \r\n \r\n + \ \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n + \ fileServices\r\n \r\n \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n + \ \r\n \r\n \r\n\r\n" + headers: + Access-Control-Allow-Headers: + - X-Requested-With, Content-Type + Access-Control-Allow-Origin: + - '*' + Connection: + - close + Content-Language: + - en-US + Content-Type: + - application/xml;charset=UTF-8 + Date: + - Tue, 01 Oct 2019 20:23:57 GMT + Server: + - Apache-Coyote/1.1 + Strict-Transport-Security: + - max-age=31536000 + Transfer-Encoding: + - chunked + status: + code: 200 + message: OK +version: 1 diff --git a/siphon/tests/test_catalog.py b/siphon/tests/test_catalog.py index 98747070b..b46a88797 100644 --- a/siphon/tests/test_catalog.py +++ b/siphon/tests/test_catalog.py @@ -397,3 +397,14 @@ def test_latest_resolver_fail(): assert latest == '' assert '"latest" not available for this catalog' in str(excinfo.value) + + +@recorder.use_cassette('unnamed_catalog_test') +def test_no_catalog_name(): + """Test the repr of an unnamed catalog.""" + cat_url = ('https://www.ncei.noaa.gov/thredds/catalog/' + 'avhrr-patmos-x-cloudprops-files/catalog.xml') + cat = TDSCatalog(cat_url) + assert cat.__repr__() == 'TDSCatalog: unnamed catalog' + assert cat.catalog_refs.__repr__() == "" + assert cat.catalog_refs['1979'].__repr__() == " 1979"