def test_to_bbox_dict_from_sequence_mismatch(self): with pytest.raises(ValueError, match="Expected sequence with 4 items, but got 3."): to_bbox_dict([1, 2, 3]) with pytest.raises(ValueError, match="Expected sequence with 4 items, but got 5."): to_bbox_dict([1, 2, 3, 4, 5])
def test_to_bbox_dict_from_dict(self): assert to_bbox_dict({ "west": 1, "south": 2, "east": 3, "north": 4 }) == { "west": 1, "south": 2, "east": 3, "north": 4 } assert to_bbox_dict({ "west": 1, "south": 2, "east": 3, "north": 4, "crs": "EPSG:4326" }) == { "west": 1, "south": 2, "east": 3, "north": 4, "crs": "EPSG:4326" } assert to_bbox_dict({ "west": 1, "south": 2, "east": 3, "north": 4 }, crs="EPSG:4326") == { "west": 1, "south": 2, "east": 3, "north": 4, "crs": "EPSG:4326", } assert to_bbox_dict({ "west": 1, "south": 2, "east": 3, "north": 4, "crs": "EPSG:4326", "color": "red", "other": "garbage", }) == { "west": 1, "south": 2, "east": 3, "north": 4, "crs": "EPSG:4326" }
def test_to_bbox_dict_from_geometry(self): geometry = shapely.geometry.Polygon([(4, 2), (7, 4), (5, 8), (3, 3), (4, 2)]) assert to_bbox_dict(geometry) == { "west": 3, "south": 2, "east": 7, "north": 8 }
def test_to_bbox_dict_from_sequence(self): assert to_bbox_dict([1, 2, 3, 4]) == { "west": 1, "south": 2, "east": 3, "north": 4 } assert to_bbox_dict((1, 2, 3, 4)) == { "west": 1, "south": 2, "east": 3, "north": 4 } assert to_bbox_dict([1, 2, 3, 4], crs="EPSG:4326") == { "west": 1, "south": 2, "east": 3, "north": 4, "crs": "EPSG:4326", }
def test_to_bbox_dict_from_dict_missing_field(self): with pytest.raises(ValueError, match="but only found {'east'}"): to_bbox_dict({"east": 3})