|
14 | 14 |
|
15 | 15 |
|
16 | 16 | _data = { |
17 | | - 'gpkg': None |
| 17 | + 'gpkg': None, |
| 18 | + 'schema': None |
18 | 19 | } |
19 | 20 |
|
20 | | - |
21 | 21 | # def find_gpkg(pkg_path): |
22 | 22 | # pkg_name = os.path.basename(os.path.abspath(pkg_path)) |
23 | 23 | # pkg_specs = parse_package_name(pkg_name) |
|
28 | 28 | def geopkg_path(pytestconfig): |
29 | 29 | return pytestconfig.getoption('pkgpath') |
30 | 30 |
|
| 31 | +@pytest.fixture() |
| 32 | +def schema_name(pytestconfig): |
| 33 | + return pytestconfig.getoption('schema') |
| 34 | + |
31 | 35 | @pytest.fixture() |
32 | 36 | def gpkg(): |
33 | 37 | return _data['gpkg'] |
34 | 38 |
|
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): |
36 | 55 | assert os.path.exists(geopkg_path), "Geopackage file/path NOT found." |
37 | 56 | gpkg = gpt.read_file(geopkg_path) |
38 | 57 | assert gpkg, "Geopackage is apparently empty/null." |
39 | 58 | _data['gpkg'] = gpkg |
40 | 59 | print("\nGeopackage loaded ({})".format(geopkg_path)) |
| 60 | + import schema |
| 61 | + gpkg_schema = getattr(schema,schema_name) |
| 62 | + _data['schema'] = gpkg_schema |
41 | 63 |
|
42 | | -# def test_geopackage(): |
43 | | -# out = check.geopackage(_data['gpkg']) |
44 | 64 |
|
45 | | -def test_layer_names(gpkg): |
| 65 | +def test_layer_names(gpkg, layer_names): |
46 | 66 | 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 |
51 | 69 |
|
52 | | -def test_field_names(gpkg): |
| 70 | +def test_field_names(gpkg, layers_columns): |
53 | 71 | 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 |
58 | 74 |
|
59 | 75 | def test_geometry(gpkg): |
60 | 76 | 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 |
65 | 78 |
|
66 | 79 | def test_crs(gpkg): |
67 | 80 | 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