-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_geojson.py
More file actions
85 lines (69 loc) · 2.53 KB
/
Copy pathtest_geojson.py
File metadata and controls
85 lines (69 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import json
import os
from fixdata import FIXTURES
from iterable.datatypes import GeoJSONIterable
# Create fixture file if it doesn't exist
FIXTURE_FILE = "fixtures/2cols6rows.geojson"
def setup_module():
"""Create fixture file if it doesn't exist"""
if not os.path.exists(FIXTURE_FILE):
# Create a simple GeoJSON FeatureCollection
features = []
for i, record in enumerate(FIXTURES):
feature = {
"type": "Feature",
"properties": record,
"geometry": {
"type": "Point",
"coordinates": [i, i], # Simple coordinates
},
}
features.append(feature)
fc = {"type": "FeatureCollection", "features": features}
with open(FIXTURE_FILE, "w", encoding="utf-8") as f:
json.dump(fc, f)
class TestGeoJSON:
def test_id(self):
datatype_id = GeoJSONIterable.id()
assert datatype_id == "geojson"
def test_flatonly(self):
flag = GeoJSONIterable.is_flatonly()
assert not flag
def test_openclose(self):
iterable = GeoJSONIterable(FIXTURE_FILE)
iterable.close()
def test_has_totals(self):
iterable = GeoJSONIterable(FIXTURE_FILE)
assert GeoJSONIterable.has_totals()
total = iterable.totals()
assert total == len(FIXTURES)
iterable.close()
def test_read(self):
iterable = GeoJSONIterable(FIXTURE_FILE)
row = iterable.read()
assert isinstance(row, dict)
assert "type" in row
assert row["type"] == "Feature"
iterable.close()
def test_read_all(self):
iterable = GeoJSONIterable(FIXTURE_FILE)
n = 0
for row in iterable:
assert isinstance(row, dict)
n += 1
assert n == len(FIXTURES)
iterable.close()
def test_write_read(self):
iterable = GeoJSONIterable("testdata/2cols6rows_test.geojson", mode="w")
# Create features
for i, record in enumerate(FIXTURES):
feature = {"type": "Feature", "properties": record, "geometry": {"type": "Point", "coordinates": [i, i]}}
iterable.write(feature)
iterable.close()
iterable = GeoJSONIterable("testdata/2cols6rows_test.geojson")
n = 0
for row in iterable:
assert isinstance(row, dict)
n += 1
assert n == len(FIXTURES)
iterable.close()