|
5 | 5 | _get_api, |
6 | 6 | _get_session, |
7 | 7 | _get_token, |
| 8 | + geojson_validate, |
8 | 9 | validate_tileset_id, |
9 | 10 | _convert_precision_to_zoom, |
10 | 11 | calculate_tiles_area, |
@@ -70,6 +71,49 @@ def test_validate_tileset_id_toolong(): |
70 | 71 | assert not validate_tileset_id(tileset) |
71 | 72 |
|
72 | 73 |
|
| 74 | +def test_geojson_validate(): |
| 75 | + geometry = {"type": "Polygon", "coordinates": [[[1, 2], [3, 4], [5, 6]]]} |
| 76 | + with pytest.raises(TilesetsError) as excinfo: |
| 77 | + geojson_validate(2, geometry) |
| 78 | + |
| 79 | + assert ( |
| 80 | + str(excinfo.value) |
| 81 | + == "Error in feature number 2: Each linear ring must contain at least 4 positions" |
| 82 | + ) |
| 83 | + |
| 84 | + |
| 85 | +def test_geojson_validate_open_ring(): |
| 86 | + geometry = {"type": "Polygon", "coordinates": [[[1, 2], [3, 4], [5, 6], [7, 8]]]} |
| 87 | + with pytest.raises(TilesetsError) as excinfo: |
| 88 | + geojson_validate(2, geometry) |
| 89 | + |
| 90 | + assert ( |
| 91 | + str(excinfo.value) |
| 92 | + == "Error in feature number 2: Each linear ring must end where it started" |
| 93 | + ) |
| 94 | + |
| 95 | + |
| 96 | +def test_geojson_validate_closed_ring(): |
| 97 | + geometry = {"type": "Polygon", "coordinates": [[[1, 2], [3, 4], [5, 6], [1, 2]]]} |
| 98 | + assert geojson_validate(2, geometry) is None |
| 99 | + |
| 100 | + |
| 101 | +def test_geojson_validate_closed_ring_correct_winding_order(): |
| 102 | + geometry = { |
| 103 | + "type": "Polygon", |
| 104 | + "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], |
| 105 | + } |
| 106 | + assert geojson_validate(2, geometry) is None |
| 107 | + |
| 108 | + |
| 109 | +def test_geojson_validate_closed_ring_incorrect_winding_order(): |
| 110 | + geometry = { |
| 111 | + "type": "Polygon", |
| 112 | + "coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], |
| 113 | + } |
| 114 | + assert geojson_validate(2, geometry) is None |
| 115 | + |
| 116 | + |
73 | 117 | def test_convert_precision_to_zoom_10m(): |
74 | 118 | precision = "10m" |
75 | 119 | assert _convert_precision_to_zoom(precision) == 6 |
|
0 commit comments