示例#1
0
 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)
示例#2
0
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
示例#3
0
    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
示例#4
0
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
示例#5
0
 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
示例#6
0
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
示例#7
0
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
示例#8
0
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
示例#9
0
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
示例#10
0
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
示例#11
0
    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)
示例#12
0
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
示例#13
0
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
示例#14
0
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
示例#15
0
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
示例#16
0
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
示例#17
0
 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)
示例#18
0
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
示例#19
0
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
示例#20
0
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
示例#21
0
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
示例#22
0
 def test_time_reset2(self):
     dr = DataQuery().time(datetime.utcnow()).all_times()
     eq_(str(dr), 'temporal=all')
示例#23
0
def test_data_query_add():
    """Test adding custom parameters to a query."""
    dr = DataQuery().add_query_parameter(foo='bar')
    assert str(dr) == 'foo=bar'
示例#24
0
 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)
示例#25
0
 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')
示例#26
0
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)
示例#27
0
def test_data_query_add():
    dr = DataQuery().add_query_parameter(foo='bar')
    assert str(dr) == 'foo=bar'
示例#28
0
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
示例#29
0
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'
示例#30
0
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
示例#31
0
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'
示例#32
0
def test_data_query_time_reset2():
    dr = DataQuery().time(datetime.utcnow()).all_times()
    assert str(dr) == 'temporal=all'
示例#33
0
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'
示例#34
0
 def test_add(self):
     dr = DataQuery().add_query_parameter(foo='bar')
     eq_(str(dr), 'foo=bar')