Skip to content

Commit

Permalink
turn on gdal exceptions in some test_table_definitions_check
Browse files Browse the repository at this point in the history
PDOK-16629
  • Loading branch information
roelarents committed Nov 18, 2024
1 parent 9e0cceb commit eb21949
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions geopackage_validator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def generate_table_definitions(
return result


def get_datasource_for_path(gpkg_path: str) -> DataSource:
def get_datasource_for_path(gpkg_path: str, error_handler=None) -> DataSource:
"""Starts the geopackage validation."""
utils.check_gdal_version()
return utils.open_dataset(gpkg_path)
return utils.open_dataset(gpkg_path, error_handler)


def generate_definitions_for_path(
Expand Down
2 changes: 1 addition & 1 deletion geopackage_validator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}


def open_dataset(filename=None, error_handler=None) -> DataSource:
def open_dataset(filename: str = None, error_handler: Callable = None) -> DataSource:
if error_handler is not None:
gdal.UseExceptions()
gdal.PushErrorHandler(error_handler)
Expand Down
11 changes: 9 additions & 2 deletions tests/validations/test_table_definitions_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ def test_legacy_table_definitions_check_table_changed():
]


def gdal_error_handler_print_err(err_level, err_no, err_msg):
print(f"GDAL error: err_level: {err_level}\nerr_no: {err_no}\nerr_msg: {err_msg}")


def test_table_definitions_check_changed_indexes_and_fks():
datasource = get_datasource_for_path(
"tests/data/test_allcorrect_with_indexes_and_fks.gpkg"
"tests/data/test_allcorrect_with_indexes_and_fks.gpkg",
gdal_error_handler_print_err,
)
table_definitions = load_table_definitions(
"tests/data/test_changed_indexes_and_fks_definition.yml"
Expand All @@ -194,7 +199,9 @@ def test_table_definitions_check_changed_indexes_and_fks():


def test_table_definitions_check_fk_violation():
datasource = get_datasource_for_path("tests/data/test_foreign_key_violation.gpkg")
datasource = get_datasource_for_path(
"tests/data/test_foreign_key_violation.gpkg", gdal_error_handler_print_err
)
table_definitions = load_table_definitions(
"tests/data/test_allcorrect_with_indexes_and_fks_definition.yml"
)
Expand Down

0 comments on commit eb21949

Please sign in to comment.