Skip to content

Commit c6bff67

Browse files
committed
split dummy schema from code
1 parent 3fd5961 commit c6bff67

4 files changed

Lines changed: 62 additions & 53 deletions

File tree

check.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
import gpt
22

33

4-
planmap = {
5-
'layers': {
6-
'geologic_units': {
7-
'columns': ['name','rgb','geo_type','geo_code'],
8-
'geometry': 'Polygon'
9-
},
10-
'geologic_contacts': {
11-
'columns': ['geo_type'],
12-
'geometry': 'Linestring'
13-
},
14-
'surface_features': {
15-
'columns': ['geo_type'],
16-
'geometry': 'Polygon'
17-
},
18-
'linear_features': {
19-
'columns': ['geo_type'],
20-
'geometry': 'Linestring'
21-
},
22-
'layer_styles': {
23-
'columns': ['styleQML','styleSLD']
24-
}
25-
}
26-
}
27-
284
def check_layer_names(pkg, layers):
295
"""
306
Return True/False if all 'layers' were found/not
@@ -140,7 +116,7 @@ def check_crs(pkg):
140116
return len(CRSs) == 1
141117

142118

143-
def geopackage(gpkg):
119+
def geopackage(gpkg, schema_name='planmap'):
144120
"""
145121
Checks to be done:
146122
- check layer names
@@ -150,13 +126,12 @@ def geopackage(gpkg):
150126
- check if there are multiple "shape" and "id" columns
151127
"""
152128
pkg = gpt.read_file(gpkg)
153-
# # make it "case insensitive" (lower the keys)
154-
# for lname in list(pkg.keys()):
155-
# pkg[lname.lower()] = pkg[lname]
156-
# del pkg[lname]
129+
130+
import schema
131+
gpkg_schema = getattr(schema,schema_name)
157132

158133
# Check layer names
159-
layers_defs = planmap['layers']
134+
layers_defs = gpkg_schema['layers']
160135
layer_columns = {l:defs['columns'] for l,defs in layers_defs.items()}
161136

162137
ok = check_layer_names(pkg, layers_defs.keys())

conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
def pytest_addoption(parser):
22
parser.addoption("--pkgpath", action="store", default="path/to/PMID")
3+
parser.addoption("--schema", action="store", default="planmap")

schema.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
planmap = {
2+
'layers': {
3+
'geologic_units': {
4+
'columns': ['name','rgb','geo_type','geo_code'],
5+
'geometry': 'Polygon'
6+
},
7+
'geologic_contacts': {
8+
'columns': ['geo_type'],
9+
'geometry': 'Linestring'
10+
},
11+
'surface_features': {
12+
'columns': ['geo_type'],
13+
'geometry': 'Polygon'
14+
},
15+
'linear_features': {
16+
'columns': ['geo_type'],
17+
'geometry': 'Linestring'
18+
},
19+
'layer_styles': {
20+
'columns': ['styleQML','styleSLD']
21+
}
22+
}
23+
}

test_geopackage.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515

1616
_data = {
17-
'gpkg': None
17+
'gpkg': None,
18+
'schema': None
1819
}
1920

20-
2121
# def find_gpkg(pkg_path):
2222
# pkg_name = os.path.basename(os.path.abspath(pkg_path))
2323
# pkg_specs = parse_package_name(pkg_name)
@@ -28,44 +28,54 @@
2828
def geopkg_path(pytestconfig):
2929
return pytestconfig.getoption('pkgpath')
3030

31+
@pytest.fixture()
32+
def schema_name(pytestconfig):
33+
return pytestconfig.getoption('schema')
34+
3135
@pytest.fixture()
3236
def gpkg():
3337
return _data['gpkg']
3438

35-
def test_00(geopkg_path):
39+
@pytest.fixture()
40+
def schema():
41+
return _data['schema']
42+
43+
@pytest.fixture()
44+
def layer_names():
45+
layers_defs = _data['schema']['layers']
46+
return layers_defs.keys()
47+
48+
@pytest.fixture()
49+
def layers_columns():
50+
layers_defs = _data['schema']['layers']
51+
return {l:defs['columns'] for l,defs in layers_defs.items()}
52+
53+
54+
def test_00(geopkg_path, schema_name):
3655
assert os.path.exists(geopkg_path), "Geopackage file/path NOT found."
3756
gpkg = gpt.read_file(geopkg_path)
3857
assert gpkg, "Geopackage is apparently empty/null."
3958
_data['gpkg'] = gpkg
4059
print("\nGeopackage loaded ({})".format(geopkg_path))
60+
import schema
61+
gpkg_schema = getattr(schema,schema_name)
62+
_data['schema'] = gpkg_schema
4163

42-
# def test_geopackage():
43-
# out = check.geopackage(_data['gpkg'])
4464

45-
def test_layer_names(gpkg):
65+
def test_layer_names(gpkg, layer_names):
4666
print("\n* Layer names")
47-
res = check.check_layer_names(gpkg)
48-
if res:
49-
print("\n".join(res))
50-
assert len(res) == 0
67+
res = check.check_layer_names(gpkg, layer_names)
68+
assert res is True
5169

52-
def test_field_names(gpkg):
70+
def test_field_names(gpkg, layers_columns):
5371
print("\n* Field names")
54-
res = check.check_field_names(gpkg)
55-
if res:
56-
print("\n".join(res))
57-
assert len(res) == 0
72+
res = check.check_field_names(gpkg, layers_columns)
73+
assert res is True
5874

5975
def test_geometry(gpkg):
6076
res = check.check_geometry(gpkg)
61-
if res:
62-
print("\n* Geometry")
63-
print("\n".join(res))
64-
assert len(res) == 0
77+
assert res is True
6578

6679
def test_crs(gpkg):
6780
res = check.check_crs(gpkg)
68-
if res:
69-
print("\n* CRS")
70-
print("\n".join(res))
71-
assert len(res) == 0
81+
assert res is True

0 commit comments

Comments
 (0)