def test_repeated_vars(self): dr = DataQuery() dr.variables('foo', 'bar') dr.variables('foo') query = str(dr) eq_(query.count('foo'), 1) eq_(query.count('bar'), 1)
def test_data_query_items(): dt = datetime.utcnow() dr = DataQuery().time(dt).lonlat_point(-1, -2) l = list(dr.items()) assert ('time', dt.isoformat()) in l assert ('latitude', -2) in l assert ('longitude', -1) in l
def test_items(self): dt = datetime.utcnow() dr = DataQuery().time(dt).lonlat_point(-1, -2) l = list(dr.items()) assert ('time', dt.isoformat()) in l assert ('latitude', -2) in l assert ('longitude', -1) in l
def test_data_query_repeated_vars(): """Test a query properly de-duplicates variables.""" dr = DataQuery() dr.variables('foo', 'bar') dr.variables('foo') query = str(dr) assert query.count('foo') == 1 assert query.count('bar') == 1
def test_basic(self): dr = DataQuery() dr.all_times() dr.variables('foo', 'bar') query = repr(dr) # To check repr for once assert 'temporal=all' in query assert 'var=foo' in query assert 'var=bar' in query
def test_data_query_basic(): """Test forming a basic query.""" dr = DataQuery() dr.all_times() dr.variables('foo', 'bar') query = repr(dr) # To check repr for once assert 'temporal=all' in query assert 'var=foo' in query assert 'var=bar' in query
def test_data_query_items(): """Test the items method of query.""" dt = datetime.utcnow() dr = DataQuery().time(dt).lonlat_point(-1, -2) items = list(dr.items()) assert ('time', dt.isoformat()) in items assert ('latitude', -2) in items assert ('longitude', -1) in items
def test_data_query_spatial_reset(): """Test that spatial queries reset each other.""" dr = DataQuery().lonlat_box(1, 2, 3, 4).lonlat_point(-1, -2) query = str(dr) assert 'latitude=-2' in query assert 'longitude=-1' in query assert query.count('=') == 2
def test_data_query_time_reset3(): dt = datetime(2015, 6, 12, 12, 0, 0) dt2 = datetime(2015, 6, 13, 12, 0, 0) dr = DataQuery().all_times().time_range(dt, dt2) query = str(dr) assert 'time_start=2015-06-12T12' in query, 'Bad string: ' + query assert 'time_end=2015-06-13T12' in query, 'Bad string: ' + query assert query.count('=') == 2
def test_iter(self): dt = datetime.utcnow() dr = DataQuery().time(dt).lonlat_point(-1, -2) d = dict(dr) eq_(d['time'], dt.isoformat()) eq_(d['latitude'], -2) eq_(d['longitude'], -1)
def test_data_query_iter(): dt = datetime.utcnow() dr = DataQuery().time(dt).lonlat_point(-1, -2) d = dict(dr) assert d['time'] == dt.isoformat() assert d['latitude'] == -2 assert d['longitude'] == -1
def test_data_query_spatial_reset2(): dr = DataQuery().lonlat_point(-1, -2).lonlat_box(1, 2, 3, 4) query = str(dr) assert 'south=3' in query assert 'north=4' in query assert 'west=1' in query assert 'east=2' in query assert query.count('=') == 4
def test_data_query_time_reset3(): """Test that time queries replace each other with time range.""" dt = datetime(2015, 6, 12, 12, 0, 0) dt2 = datetime(2015, 6, 13, 12, 0, 0) dr = DataQuery().all_times().time_range(dt, dt2) query = str(dr) assert 'time_start=2015-06-12T12' in query, 'Bad string: ' + query assert 'time_end=2015-06-13T12' in query, 'Bad string: ' + query assert query.count('=') == 2
def test_data_query_iter(): """Test converting a query to a dictionary.""" dt = datetime.utcnow() dr = DataQuery().time(dt).lonlat_point(-1, -2) d = dict(dr) assert d['time'] == dt.isoformat() assert d['latitude'] == -2 assert d['longitude'] == -1
def test_data_query_spatial_reset2(): """Test more that spatial queries reset each other.""" dr = DataQuery().lonlat_point(-1, -2).lonlat_box(1, 2, 3, 4) query = str(dr) assert 'south=3' in query assert 'north=4' in query assert 'west=1' in query assert 'east=2' in query assert query.count('=') == 4
def test_data_query_repeated_vars(): dr = DataQuery() dr.variables('foo', 'bar') dr.variables('foo') query = str(dr) assert query.count('foo') == 1 assert query.count('bar') == 1
def test_data_query_basic(): dr = DataQuery() dr.all_times() dr.variables('foo', 'bar') query = repr(dr) # To check repr for once assert 'temporal=all' in query assert 'var=foo' in query assert 'var=bar' in query
def test_data_query_time_reset(): dr = DataQuery().all_times().time(datetime.utcnow()) query = str(dr) assert query.startswith('time='), 'Bad string: ' + query assert query.count('=') == 1
def test_time_reset2(self): dr = DataQuery().time(datetime.utcnow()).all_times() eq_(str(dr), 'temporal=all')
def test_data_query_add(): """Test adding custom parameters to a query.""" dr = DataQuery().add_query_parameter(foo='bar') assert str(dr) == 'foo=bar'
def test_spatial_reset(self): dr = DataQuery().lonlat_box(1, 2, 3, 4).lonlat_point(-1, -2) query = str(dr) assert 'latitude=-2' in query assert 'longitude=-1' in query eq_(query.count('='), 2)
def test_time_format(self): dt = datetime(2015, 6, 15, 12, 0, 0) dr = DataQuery().time(dt) query = str(dr) eq_(query, 'time=2015-06-15T12%3A00%3A00')
def test_data_query_bad_time_range(): """Test that time queries are properly formatted.""" with pytest.warns(UserWarning): dt = datetime(2015, 6, 15, 12, 0, 0) dt2 = datetime(2015, 6, 14, 12, 0, 0) DataQuery().time_range(dt, dt2)
def test_data_query_add(): dr = DataQuery().add_query_parameter(foo='bar') assert str(dr) == 'foo=bar'
def test_data_query_time_reset(): """Test query with multiple time-type query fields.""" dr = DataQuery().all_times().time(datetime.utcnow()) query = str(dr) assert query.startswith('time='), 'Bad string: ' + query assert query.count('=') == 1
def test_data_query_time_format(): dt = datetime(2015, 6, 15, 12, 0, 0) dr = DataQuery().time(dt) query = str(dr) assert query == 'time=2015-06-15T12%3A00%3A00'
def test_data_query_spatial_reset(): dr = DataQuery().lonlat_box(1, 2, 3, 4).lonlat_point(-1, -2) query = str(dr) assert 'latitude=-2' in query assert 'longitude=-1' in query assert query.count('=') == 2
def test_data_query_time_reset2(): """Test that time queries replace each other.""" dr = DataQuery().time(datetime.utcnow()).all_times() assert str(dr) == 'temporal=all'
def test_data_query_time_reset2(): dr = DataQuery().time(datetime.utcnow()).all_times() assert str(dr) == 'temporal=all'
def test_data_query_time_format(): """Test that time queries are properly formatted.""" dt = datetime(2015, 6, 15, 12, 0, 0) dr = DataQuery().time(dt) query = str(dr) assert query == 'time=2015-06-15T12%3A00%3A00'
def test_add(self): dr = DataQuery().add_query_parameter(foo='bar') eq_(str(dr), 'foo=bar')