-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_geopackage.py
executable file
·81 lines (63 loc) · 2 KB
/
test_geopackage.py
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
"""
Get a package path and check its content.
The package content checking is processed by a series/pipeline of tasks
on specific request or automatically (if None asked) after parsing/interpreting
the package name, or greedly inpecting any of the expected directories.
"""
import os
import sys
import pytest
import gpt
import check
_data = {
'gpkg': None,
'schema': None
}
# def find_gpkg(pkg_path):
# pkg_name = os.path.basename(os.path.abspath(pkg_path))
# pkg_specs = parse_package_name(pkg_name)
# pkg_specs['name'] = pkg_name
# return os.path.join(pkg_path, 'vector', pkg_specs['name']+'.gpkg')
@pytest.fixture()
def geopkg_path(pytestconfig):
return pytestconfig.getoption('pkgpath')
@pytest.fixture()
def schema_name(pytestconfig):
return pytestconfig.getoption('schema')
@pytest.fixture()
def gpkg():
return _data['gpkg']
@pytest.fixture()
def schema():
return _data['schema']
@pytest.fixture()
def layer_names():
layers_defs = _data['schema']['layers']
return layers_defs.keys()
@pytest.fixture()
def layers_columns():
layers_defs = _data['schema']['layers']
return {l:defs['columns'] for l,defs in layers_defs.items()}
def test_00(geopkg_path, schema_name):
assert os.path.exists(geopkg_path), "Geopackage file/path NOT found."
gpkg = gpt.read_file(geopkg_path)
assert gpkg, "Geopackage is apparently empty/null."
_data['gpkg'] = gpkg
print("\nGeopackage loaded ({})".format(geopkg_path))
import schema
gpkg_schema = getattr(schema,schema_name)
_data['schema'] = gpkg_schema
def test_layer_names(gpkg, layer_names):
print("\n* Layer names")
res = check.check_layer_names(gpkg, layer_names)
assert res is True
def test_field_names(gpkg, layers_columns):
print("\n* Field names")
res = check.check_field_names(gpkg, layers_columns)
assert res is True
def test_geometry(gpkg):
res = check.check_geometry(gpkg)
assert res is True
def test_crs(gpkg):
res = check.check_crs(gpkg)
assert res is True