Skip to content

Commit

Permalink
Use OrderedDict for catalog refs and datasets (Fixes Unidata#80)
Browse files Browse the repository at this point in the history
This is more intuitive for these items. I've left metadata alone, since
that doesn't have as expected an ordering.
  • Loading branch information
dopplershift committed Apr 4, 2016
1 parent eeac967 commit e83089f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions siphon/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import logging
import xml.etree.ElementTree as ET
from collections import OrderedDict

from .metadata import TDSCatalogMetadata
from .http_util import create_http_session, urlopen
Expand Down Expand Up @@ -80,9 +81,9 @@ def __init__(self, catalog_url):
else:
self.catalog_name = "No name found"

self.datasets = {}
self.datasets = OrderedDict()
self.services = []
self.catalog_refs = {}
self.catalog_refs = OrderedDict()
self.metadata = {}
service_skip_count = 0
service_skip = 0
Expand Down
18 changes: 18 additions & 0 deletions siphon/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ def test_catalog_follow(self):
ref_name = 'Forecast Model Data'
cat = TDSCatalog(url).catalog_refs[ref_name].follow()
assert cat

@recorder.use_cassette('top_level_20km_rap_catalog')
def test_datasets_order(self):
url = ('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/NAM/'
'CONUS_20km/noaaport/catalog.xml')
cat = TDSCatalog(url)
assert list(cat.datasets) == ['Full Collection (Reference / Forecast Time) Dataset',
'Best NAM CONUS 20km Time Series',
'Latest Collection for NAM CONUS 20km']

@recorder.use_cassette('top_level_cat')
def test_catalog_ref_order(self):
url = 'http://thredds.ucar.edu/thredds/catalog.xml'
cat = TDSCatalog(url)
assert list(cat.catalog_refs) == ['Forecast Model Data',
'Forecast Products and Analyses', 'Observation Data',
'Radar Data', 'Satellite Data',
'Unidata case studies']

0 comments on commit e83089f

Please sign in to comment.