Пример #1
0
def test_constructor():
    # Check that only Location instances are accepted
    with pytest.raises(ValueError):
        Bounds(3, 5)

    sw = Location(latitude=49, longitude=6)
    ne = Location(latitude=51, longitude=7)
    b = Bounds(sw, ne)

    assert b.southwest.latitude == 49
    assert b.southwest.longitude == 6
    assert b.northeast.latitude == 51
    assert b.northeast.longitude == 7
Пример #2
0
def test_get_sizes():
    # Check normal size calculations
    b = Bounds.from_bbox_string("1,50,21,52")

    assert b.get_width() == 20
    assert b.get_height() == 2
    assert b.get_size() == 40

    # Check longitude wraparound and height == 0
    b = Bounds.from_bbox_string("170,50,-165,50")

    assert b.get_width() == 25
    assert b.get_height() == 0
    assert b.get_size() == 0
Пример #3
0
    def test_get_sizes(self):
        # Check normal size calculations
        b = Bounds.from_bbox_string('1,50,21,52')

        assert b.get_width() == 20
        assert b.get_height() == 2
        assert b.get_size() == 40

        # Check longitude wraparound and height == 0
        b = Bounds.from_bbox_string('170,50,-165,50')

        assert b.get_width() == 25
        assert b.get_height() == 0
        assert b.get_size() == 0
Пример #4
0
    def test_get_sizes(self):
        # Check normal size calculations
        b = Bounds.from_bbox_string('1,50,21,52')

        eq_(b.get_width(), 20)
        eq_(b.get_height(), 2)
        eq_(b.get_size(), 40)

        # Check longitude wraparound and height == 0
        b = Bounds.from_bbox_string('170,50,-165,50')

        eq_(b.get_width(), 25)
        eq_(b.get_height(), 0)
        eq_(b.get_size(), 0)
Пример #5
0
    def test_from_bbox_string(self):
        # Check that strings with more or less than 4 components
        # raise ValueError
        assert_raises(ValueError, Bounds.from_bbox_string, '1,2,3')
        Bounds.from_bbox_string('1,2,3,4')
        assert_raises(ValueError, Bounds.from_bbox_string, '1,2,3,4,5')

        # Check that non-numeric values raise ValueError
        assert_raises(ValueError, Bounds.from_bbox_string, '1,a,3,4')

        # Check that BBox strings are parsed correctly
        b = Bounds.from_bbox_string('6.05,49.5,7,51.0')

        eq_(b.southwest.latitude, 49.5)
        eq_(b.southwest.longitude, 6.05)
        eq_(b.northeast.latitude, 51)
        eq_(b.northeast.longitude, 7)
Пример #6
0
    def test_from_bbox_string(self):
        # Check that strings with more or less than 4 components
        # raise ValueError
        with pytest.raises(ValueError): Bounds.from_bbox_string('1,2,3')
        Bounds.from_bbox_string('1,2,3,4')
        with pytest.raises(ValueError): Bounds.from_bbox_string('1,2,3,4,5')

        # Check that non-numeric values raise ValueError
        with pytest.raises(ValueError): Bounds.from_bbox_string('1,a,3,4')

        # Check that BBox strings are parsed correctly
        b = Bounds.from_bbox_string('6.05,49.5,7,51.0')

        assert b.southwest.latitude == 49.5
        assert b.southwest.longitude == 6.05
        assert b.northeast.latitude == 51
        assert b.northeast.longitude == 7
Пример #7
0
    def test_constructor(self):
        # Check that only Location instances are accepted
        assert_raises(ValueError, Bounds, 3, 5)

        sw = Location(latitude=49, longitude=6)
        ne = Location(latitude=51, longitude=7)
        b = Bounds(sw, ne)

        eq_(b.southwest.latitude, 49)
        eq_(b.southwest.longitude, 6)
        eq_(b.northeast.latitude, 51)
        eq_(b.northeast.longitude, 7)
Пример #8
0
def test_from_bbox_string():
    # Check that strings with more or less than 4 components
    # raise ValueError
    with pytest.raises(ValueError):
        Bounds.from_bbox_string("1,2,3")
    Bounds.from_bbox_string("1,2,3,4")
    with pytest.raises(ValueError):
        Bounds.from_bbox_string("1,2,3,4,5")

    # Check that non-numeric values raise ValueError
    with pytest.raises(ValueError):
        Bounds.from_bbox_string("1,a,3,4")

    # Check that BBox strings are parsed correctly
    b = Bounds.from_bbox_string("6.05,49.5,7,51.0")

    assert b.southwest.latitude == 49.5
    assert b.southwest.longitude == 6.05
    assert b.northeast.latitude == 51
    assert b.northeast.longitude == 7
Пример #9
0
 def _deserialize(self, value, attr, data):
     try:
         return Bounds.from_bbox_string(value)
     except ValueError as e:
         raise ValidationError(e.message)