|
3 | 3 | from io import BytesIO
|
4 | 4 | import json
|
5 | 5 | import sys
|
| 6 | +from zipfile import ZipFile |
6 | 7 |
|
7 | 8 | import numpy as np
|
8 | 9 | from numpy import array_equal
|
@@ -1177,6 +1178,27 @@ def test_write_memory_existing_unsupported(naturalearth_lowres):
|
1177 | 1178 | write(buffer, geometry, field_data, driver="GeoJSON", layer="test", **meta)
|
1178 | 1179 |
|
1179 | 1180 |
|
| 1181 | +def test_write_open_file_handle(tmp_path, naturalearth_lowres): |
| 1182 | + """Verify that writing to an open file handle is not currently supported""" |
| 1183 | + |
| 1184 | + meta, _, geometry, field_data = read(naturalearth_lowres) |
| 1185 | + |
| 1186 | + # verify it fails for regular file handle |
| 1187 | + with pytest.raises( |
| 1188 | + NotImplementedError, match="writing to an open file handle is not yet supported" |
| 1189 | + ): |
| 1190 | + with open(tmp_path / "test.geojson", "wb") as f: |
| 1191 | + write(f, geometry, field_data, driver="GeoJSON", layer="test", **meta) |
| 1192 | + |
| 1193 | + # verify it fails for ZipFile |
| 1194 | + with pytest.raises( |
| 1195 | + NotImplementedError, match="writing to an open file handle is not yet supported" |
| 1196 | + ): |
| 1197 | + with ZipFile(tmp_path / "test.geojson.zip", "w") as z: |
| 1198 | + with z.open("test.geojson", "w") as f: |
| 1199 | + write(f, geometry, field_data, driver="GeoJSON", layer="test", **meta) |
| 1200 | + |
| 1201 | + |
1180 | 1202 | @pytest.mark.parametrize("ext", ["fgb", "gpkg", "geojson"])
|
1181 | 1203 | @pytest.mark.parametrize(
|
1182 | 1204 | "read_encoding,write_encoding",
|
|
0 commit comments