def test_from_dict(self): data = [('layers', 'foo,bar'), ('laYERs', 'baz'), ('crs', 'EPSG:4326')] nc_dict = NoCaseMultiDict(data) print(nc_dict) for name in ('layers', 'LAYERS', 'lAYeRS'): assert name in nc_dict, name + ' not found' assert nc_dict.get_all('layers') == ['foo,bar', 'baz'] assert nc_dict.get_all('crs') == ['EPSG:4326']
def test_from_dict(self): data = [("layers", "foo,bar"), ("laYERs", "baz"), ("crs", "EPSG:4326")] nc_dict = NoCaseMultiDict(data) print(nc_dict) for name in ("layers", "LAYERS", "lAYeRS"): assert name in nc_dict, name + " not found" assert nc_dict.get_all("layers") == ["foo,bar", "baz"] assert nc_dict.get_all("crs") == ["EPSG:4326"]
def test_iteritems(self): data = dict([('LAYERS', 'foo,bar'), ('laYERs', 'baz'), ('crs', 'EPSG:4326')]) nc_dict = NoCaseMultiDict(data) print nc_dict itr = nc_dict.iteritems() key, values = itr.next() assert key == 'LAYERS' and values == ['foo,bar', 'baz'] key, values = itr.next() assert key == 'crs' and values == ['EPSG:4326']
def test_iteritems(self): data = [("LAYERS", "foo,bar"), ("laYERs", "baz"), ("crs", "EPSG:4326")] nc_dict = NoCaseMultiDict(data) for key, values in nc_dict.iteritems(): if key in ("LAYERS", "laYERs"): assert values == ["foo,bar", "baz"] elif key == "crs": assert values == ["EPSG:4326"] else: assert False, "unexpected key " + key
def test_iteritems(self): data = [('LAYERS', 'foo,bar'), ('laYERs', 'baz'), ('crs', 'EPSG:4326')] nc_dict = NoCaseMultiDict(data) for key, values in nc_dict.iteritems(): if key in ('LAYERS', 'laYERs'): assert values == ['foo,bar', 'baz'] elif key == 'crs': assert values == ['EPSG:4326'] else: assert False, 'unexpected key ' + key
def dimensions_part(dimensionlist, dimensions): """ Return the subpath where all tiles for `dimensions` will be stored. >>> dimensions_part(['reference-time', 'time'], {"time": "2016-11-24T18:00Z", "reference-time": "2016-11-24T00:00Z"}) '2016-11-24T00:00Z/2016-11-24T18:00Z' """ if dimensionlist: dims = NoCaseMultiDict(dimensions) return os.path.join(*(map(lambda k: str(dims.get(k, 'default')), dimensionlist))) else: return ""
def test_missing_key(self): nc_dict = NoCaseMultiDict([('foo', 'bar')]) try: nc_dict['bar'] assert False, 'Did not throw KeyError exception.' except KeyError: pass
def test_missing_key(self): nc_dict = NoCaseMultiDict([("foo", "bar")]) try: nc_dict["bar"] assert False, "Did not throw KeyError exception." except KeyError: pass
def test_get(self): nc_dict = NoCaseMultiDict([('foo', 'bar'), ('num', '42')]) assert nc_dict.get('bar') == None assert nc_dict.get('bar', 'default_bar') == 'default_bar' assert nc_dict.get('num') == '42' assert nc_dict.get('num', type_func=int) == 42 assert nc_dict.get('foo') == 'bar'
def test_get(self): nc_dict = NoCaseMultiDict([("foo", "bar"), ("num", "42")]) assert nc_dict.get("bar") == None assert nc_dict.get("bar", "default_bar") == "default_bar" assert nc_dict.get("num") == "42" assert nc_dict.get("num", type_func=int) == 42 assert nc_dict.get("foo") == "bar"
def test_setitem(self): nc_dict = NoCaseMultiDict() nc_dict['foo'] = 'bar' assert nc_dict['foo'] == 'bar' nc_dict['foo'] = 'buz' assert nc_dict['foo'] == 'buz' nc_dict['bar'] = nc_dict['foo'] assert nc_dict['bar'] == 'buz' nc_dict['bing'] = '1' nc_dict['bong'] = '2' nc_dict['bing'] = nc_dict['bong'] assert nc_dict['bing'] == '2' assert nc_dict['bong'] == '2'
def test_setitem(self): nc_dict = NoCaseMultiDict() nc_dict["foo"] = "bar" assert nc_dict["foo"] == "bar" nc_dict["foo"] = "buz" assert nc_dict["foo"] == "buz" nc_dict["bar"] = nc_dict["foo"] assert nc_dict["bar"] == "buz" nc_dict["bing"] = "1" nc_dict["bong"] = "2" nc_dict["bing"] = nc_dict["bong"] assert nc_dict["bing"] == "2" assert nc_dict["bong"] == "2"
def test_multiple_sets(self): nc_dict = NoCaseMultiDict() nc_dict['foo'] = 'bar' assert nc_dict['FOO'] == 'bar' nc_dict['foo'] = 'baz' assert nc_dict['FOO'] == 'baz'
def test_get_all(self): nc_dict = NoCaseMultiDict([("foo", "bar"), ("num", "42"), ("foo", "biz")]) assert nc_dict.get_all("bar") == [] assert nc_dict.get_all("foo") == ["bar", "biz"] assert nc_dict.get_all("num") == ["42"]
def test_del(self): nc_dict = NoCaseMultiDict([('foo', 'bar'), ('num', '42')]) assert nc_dict['fOO'] == 'bar' del nc_dict['FOO'] assert nc_dict.get('foo') == None
def test_set(self): nc_dict = NoCaseMultiDict() nc_dict.set('foo', 'bar') assert nc_dict.get_all('fOO') == ['bar'] nc_dict.set('fOo', 'buzz', append=True) assert nc_dict.get_all('FOO') == ['bar', 'buzz'] nc_dict.set('foO', 'bizz') assert nc_dict.get_all('FOO') == ['bizz'] nc_dict.set('foO', ['ham', 'spam'], unpack=True) assert nc_dict.get_all('FOO') == ['ham', 'spam'] nc_dict.set('FoO', ['egg', 'bacon'], append=True, unpack=True) assert nc_dict.get_all('FOo') == ['ham', 'spam', 'egg', 'bacon']
def test_get_all(self): nc_dict = NoCaseMultiDict([('foo', 'bar'), ('num', '42'), ('foo', 'biz')]) assert nc_dict.get_all('bar') == [] assert nc_dict.get_all('foo') == ['bar', 'biz'] assert nc_dict.get_all('num') == ['42']
def test_set(self): nc_dict = NoCaseMultiDict() nc_dict.set("foo", "bar") assert nc_dict.get_all("fOO") == ["bar"] nc_dict.set("fOo", "buzz", append=True) assert nc_dict.get_all("FOO") == ["bar", "buzz"] nc_dict.set("foO", "bizz") assert nc_dict.get_all("FOO") == ["bizz"] nc_dict.set("foO", ["ham", "spam"], unpack=True) assert nc_dict.get_all("FOO") == ["ham", "spam"] nc_dict.set("FoO", ["egg", "bacon"], append=True, unpack=True) assert nc_dict.get_all("FOo") == ["ham", "spam", "egg", "bacon"]
def test_del(self): nc_dict = NoCaseMultiDict([("foo", "bar"), ("num", "42")]) assert nc_dict["fOO"] == "bar" del nc_dict["FOO"] assert nc_dict.get("foo") == None
def test_multiple_sets(self): nc_dict = NoCaseMultiDict() nc_dict["foo"] = "bar" assert nc_dict["FOO"] == "bar" nc_dict["foo"] = "baz" assert nc_dict["FOO"] == "baz"