From a0d9e34fc9a6ebdfe88c3124f18d119c2d3e0211 Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Tue, 19 Mar 2024 17:46:12 +0000 Subject: [PATCH 01/13] add write option for geopackage and geoparquet --- src/osmox/cli.py | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/osmox/cli.py b/src/osmox/cli.py index ca4c6d3..f9e4a4d 100644 --- a/src/osmox/cli.py +++ b/src/osmox/cli.py @@ -40,6 +40,13 @@ def validate(config_path): @click.argument("config_path", type=PathPath(exists=True), nargs=1, required=True) @click.argument("input_path", type=PathPath(exists=True), nargs=1, required=True) @click.argument("output_name", nargs=1, required=True) +@click.option( + "-f", + "--format", + type=click.Choice(["geojson", "geopackage", "geoparquet"]), + default="geopackage", + help="Output file format (default: geopackage)", +) @click.option( "-crs", "--crs", @@ -59,7 +66,7 @@ def validate(config_path): is_flag=True, help="if filtered object already has a label, do not search for more (supresses multi-use)", ) -def run(config_path, input_path, output_name, crs, single_use, lazy): +def run(config_path, input_path, output_name, format, crs, single_use, lazy): logger.info(f" Loading config from {config_path}") cnfg = config.load(config_path) config.validate_activity_config(cnfg) @@ -107,17 +114,31 @@ def run(config_path, input_path, output_name, crs, single_use, lazy): gdf = handler.geodataframe(single_use=single_use) - path = path_leaf(input_path) / f"{output_name}_{crs.replace(':', '_')}.geojson" - logger.info(f" Writting objects to: {path}") - with open(path, "w") as file: - file.write(gdf.to_json()) - - if not crs == "epsg:4326": - logger.info(" Reprojecting output to epsg:4326 (lat lon)") - gdf.to_crs("epsg:4326", inplace=True) - path = path_leaf(input_path) / f"{output_name}_epsg_4326.geojson" - logger.info(f" Writting objects to: {path}") - with open(path, "w") as file: - file.write(gdf.to_json()) + if format == "geojson": + extension = "geojson" + driver = 'GeoJSON' + writer = gdf.to_file + elif format == "geopackage": + extension = "gpkg" + driver = 'GPKG' + writer = gdf.to_file + elif format == "geoparquet": + extension = "parquet" + writer = gdf.to_parquet + + logger.info(f" Writing objects to {format} format.") + output_filename = f"{output_name}_{crs.replace(':', '_')}.{extension}" + + if format != "geoparquet": + writer(output_filename, driver=driver) + else: + writer(output_filename) + + if not crs == "epsg:4326" and format != "geoparquet": + logger.info(" Reprojecting output to EPSG:4326 (lat lon)") + gdf.to_crs("epsg:4326").to_file(f"{output_name}_epsg_4326.{extension}", driver=driver) + elif not crs == "epsg:4326" and format == "geoparquet": + logger.info(" Reprojecting output to EPSG:4326 (lat lon)") + gdf.to_crs("epsg:4326").to_parquet(f"{output_name}_epsg_4326.parquet") logger.info("Done.") From dad7b140e326a7c11529daba35c55e7fe33ac5ca Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Wed, 20 Mar 2024 15:26:59 +0000 Subject: [PATCH 02/13] cli output format updates & attempt test_cli.py --- src/osmox/cli.py | 29 +++++++++++------------- tests/test_cli.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 tests/test_cli.py diff --git a/src/osmox/cli.py b/src/osmox/cli.py index f9e4a4d..6134ca8 100644 --- a/src/osmox/cli.py +++ b/src/osmox/cli.py @@ -2,6 +2,7 @@ import os import click +import pyproj from osmox import build, config from osmox.helpers import PathPath, path_leaf @@ -116,29 +117,25 @@ def run(config_path, input_path, output_name, format, crs, single_use, lazy): if format == "geojson": extension = "geojson" - driver = 'GeoJSON' - writer = gdf.to_file + writer_method = 'to_file' + kwargs = {"driver": 'GeoJSON'} elif format == "geopackage": extension = "gpkg" - driver = 'GPKG' - writer = gdf.to_file + writer_method = 'to_file' + kwargs = {"driver": 'GPKG'} elif format == "geoparquet": extension = "parquet" - writer = gdf.to_parquet + writer_method = 'to_parquet' + kwargs = {} logger.info(f" Writing objects to {format} format.") output_filename = f"{output_name}_{crs.replace(':', '_')}.{extension}" - if format != "geoparquet": - writer(output_filename, driver=driver) - else: - writer(output_filename) - - if not crs == "epsg:4326" and format != "geoparquet": - logger.info(" Reprojecting output to EPSG:4326 (lat lon)") - gdf.to_crs("epsg:4326").to_file(f"{output_name}_epsg_4326.{extension}", driver=driver) - elif not crs == "epsg:4326" and format == "geoparquet": - logger.info(" Reprojecting output to EPSG:4326 (lat lon)") - gdf.to_crs("epsg:4326").to_parquet(f"{output_name}_epsg_4326.parquet") + getattr(gdf, writer_method)(output_filename, **kwargs) + + if pyproj.CRS(crs) != pyproj.CRS("epsg:4326"): + logger.info(" Reprojecting additional output to EPSG:4326 (lat lon)") + gdf_4326 = gdf.to_crs("epsg:4326") + getattr(gdf_4326, writer_method)(f"{output_name}_epsg_4326.{extension}", **kwargs) logger.info("Done.") diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..f9f684c --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,56 @@ +import os +import logging + +import pytest +from click.testing import CliRunner + +from osmox import cli + +logging.basicConfig(level=logging.INFO) + +@pytest.fixture +def fixtures_root(): + return os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) + +@pytest.fixture +def config_path(fixtures_root): + return os.path.join(fixtures_root, "test_config.json") + +@pytest.fixture +def toy_osm_path(fixtures_root): + return os.path.join(fixtures_root, "park.osm") + +@pytest.fixture +def runner(): + return CliRunner() + +def test_cli_with_default_args(runner, config_path, toy_osm_path): + # Test the command with minimal arguments + result = runner.invoke( + cli.run, + [ + config_path, + toy_osm_path, + 'output_test' + ] + ) + #print(result.output) + assert result.exit_code == 0 + assert "geopackage" in result.exit_code + assert "epsg:4326" in result.exit_code + + +def test_cli_output_formats(runner, config_path, toy_osm_path): + for output_format in ["geojson", "geopackage", "geoparquet"]: + result = runner.invoke( + cli.run, + [ + config_path, + toy_osm_path, + 'output_test', + "-f", output_format, + "-crs", "epsg:4326" + ] + ) + print(result.output) + assert result.exit_code == 0 \ No newline at end of file From c91f98792ec72ff969ef585e7d8a6320c571812c Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Wed, 20 Mar 2024 15:31:14 +0000 Subject: [PATCH 03/13] pyarrow to requirement.txt --- requirements/base.txt | 1 + requirements/dev.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/requirements/base.txt b/requirements/base.txt index ee11284..8443004 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -2,6 +2,7 @@ click < 9 geopandas >= 0.13, < 0.15 osmium < 3.7 pandas >= 1.5, < 3 +pyarrow >= 15.0.2 pyproj >= 3.1.0, < 4 Rtree >= 1, < 2 shapely >= 1, < 3 diff --git a/requirements/dev.txt b/requirements/dev.txt index 56fc3e3..059dd91 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,6 +5,7 @@ mkdocs-material >= 9.4, < 10 mkdocs-click < 0.7 mkdocstrings-python < 2 pre-commit < 4 +pyarrow >= 15.0.2 pytest >= 8, < 9 pytest-cov < 5 pytest-mock < 4 From 8294818b7bc88ebc4b4f42a678fc44cf38126224 Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Wed, 20 Mar 2024 15:33:08 +0000 Subject: [PATCH 04/13] pinning pyarrow --- requirements/base.txt | 2 +- requirements/dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 8443004..7e45717 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -2,7 +2,7 @@ click < 9 geopandas >= 0.13, < 0.15 osmium < 3.7 pandas >= 1.5, < 3 -pyarrow >= 15.0.2 +pyarrow >= 15.0.2, < 16 pyproj >= 3.1.0, < 4 Rtree >= 1, < 2 shapely >= 1, < 3 diff --git a/requirements/dev.txt b/requirements/dev.txt index 059dd91..05e8459 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,7 +5,7 @@ mkdocs-material >= 9.4, < 10 mkdocs-click < 0.7 mkdocstrings-python < 2 pre-commit < 4 -pyarrow >= 15.0.2 +pyarrow >= 15.0.2, < 16 pytest >= 8, < 9 pytest-cov < 5 pytest-mock < 4 From 9cfd585729e089bfab0a6dfd9c677e99b6a60c6e Mon Sep 17 00:00:00 2001 From: Bryn Pickering <17178478+brynpickering@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:23:01 +0000 Subject: [PATCH 05/13] Add CLI test traceback printer --- tests/test_cli.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index f9f684c..41bb0ab 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,41 +1,46 @@ -import os import logging +import os +import traceback import pytest from click.testing import CliRunner - from osmox import cli logging.basicConfig(level=logging.INFO) + @pytest.fixture def fixtures_root(): return os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) + @pytest.fixture def config_path(fixtures_root): return os.path.join(fixtures_root, "test_config.json") + @pytest.fixture def toy_osm_path(fixtures_root): return os.path.join(fixtures_root, "park.osm") + @pytest.fixture def runner(): return CliRunner() + +def check_exit_code(result): + "Print full traceback if the CLI runner failed" + if result.exit_code != 0: + traceback.print_tb(result.exc_info[-1]) + assert result.exit_code == 0 + + def test_cli_with_default_args(runner, config_path, toy_osm_path): # Test the command with minimal arguments - result = runner.invoke( - cli.run, - [ - config_path, - toy_osm_path, - 'output_test' - ] - ) - #print(result.output) - assert result.exit_code == 0 + result = runner.invoke(cli.run, [config_path, toy_osm_path, "output_test"]) + + check_exit_code(result) assert "geopackage" in result.exit_code assert "epsg:4326" in result.exit_code @@ -44,13 +49,6 @@ def test_cli_output_formats(runner, config_path, toy_osm_path): for output_format in ["geojson", "geopackage", "geoparquet"]: result = runner.invoke( cli.run, - [ - config_path, - toy_osm_path, - 'output_test', - "-f", output_format, - "-crs", "epsg:4326" - ] + [config_path, toy_osm_path, "output_test", "-f", output_format, "-crs", "epsg:4326"], ) - print(result.output) - assert result.exit_code == 0 \ No newline at end of file + check_exit_code(result) From 86c53e877053cfa8bcc00d6fd0fb85b13791a314 Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Wed, 20 Mar 2024 17:19:18 +0000 Subject: [PATCH 06/13] test_cli update & test_config issue with transit_distance fixed --- tests/fixtures/test_config.json | 4 +++- tests/test_cli.py | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/fixtures/test_config.json b/tests/fixtures/test_config.json index c96b51c..e317025 100644 --- a/tests/fixtures/test_config.json +++ b/tests/fixtures/test_config.json @@ -37,7 +37,9 @@ ] }, - "object_features": ["units", "transit_distance", "levels", "area", "floor_area"], + "object_features": ["units", "levels", "area", "floor_area"], + + "distance_to_nearest": ["transit"], "default_tags": [["building", "residential"]], diff --git a/tests/test_cli.py b/tests/test_cli.py index 41bb0ab..43153a2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,6 +4,7 @@ import pytest from click.testing import CliRunner + from osmox import cli logging.basicConfig(level=logging.INFO) @@ -21,7 +22,7 @@ def config_path(fixtures_root): @pytest.fixture def toy_osm_path(fixtures_root): - return os.path.join(fixtures_root, "park.osm") + return os.path.join(fixtures_root, "toy.osm") @pytest.fixture @@ -41,14 +42,14 @@ def test_cli_with_default_args(runner, config_path, toy_osm_path): result = runner.invoke(cli.run, [config_path, toy_osm_path, "output_test"]) check_exit_code(result) - assert "geopackage" in result.exit_code - assert "epsg:4326" in result.exit_code + assert result.exit_code == 0 -def test_cli_output_formats(runner, config_path, toy_osm_path): - for output_format in ["geojson", "geopackage", "geoparquet"]: - result = runner.invoke( - cli.run, - [config_path, toy_osm_path, "output_test", "-f", output_format, "-crs", "epsg:4326"], - ) - check_exit_code(result) +@pytest.mark.parametrize("output_format", ["geojson", "geopackage", "geoparquet"]) +def test_cli_output_formats(runner, config_path, toy_osm_path, output_format): + result = runner.invoke( + cli.run, + [config_path, toy_osm_path, "output_test", "-f", output_format, "-crs", "epsg:4326"], + ) + check_exit_code(result) + assert result.exit_code == 0 From 6f385f521e7788c9e6bfaeafaba6e40ed7a0b7bc Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Wed, 20 Mar 2024 17:39:24 +0000 Subject: [PATCH 07/13] changelog & remove pyarrow requirement from dev.txt --- CHANGELOG.md | 1 + requirements/dev.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92f3340..3be2420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Recommended installation instructions changed from using `pip` to creating a `mamba` environment [#38](https://github.com/arup-group/osmox/pull/38). - Supported and tested Python versions updated to py3.10 - py3.12 [#38](https://github.com/arup-group/osmox/pull/38). - Majority of documentation moved from README to dedicated documentation site: https://arup-group.github.io/osmox [#40](https://github.com/arup-group/osmox/pull/40). +- Default output format changed from `.geojson` to `.gpkg` & support for multiple file formats (`.gpkg`, `.geojson`, `.parquet`) [#41](https://github.com/arup-group/osmox/issues/41) ## [v0.2.0] diff --git a/requirements/dev.txt b/requirements/dev.txt index 05e8459..56fc3e3 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,7 +5,6 @@ mkdocs-material >= 9.4, < 10 mkdocs-click < 0.7 mkdocstrings-python < 2 pre-commit < 4 -pyarrow >= 15.0.2, < 16 pytest >= 8, < 9 pytest-cov < 5 pytest-mock < 4 From 8830df3f1dd69734c15cdc53637fa916f35e18c3 Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Thu, 21 Mar 2024 09:38:18 +0000 Subject: [PATCH 08/13] pre-commit fixes --- tests/test_activityhandler.py | 3 ++- tests/test_autotree.py | 3 ++- tests/test_config.py | 1 + tests/test_helpers.py | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_activityhandler.py b/tests/test_activityhandler.py index c51d73d..ca8b6fd 100644 --- a/tests/test_activityhandler.py +++ b/tests/test_activityhandler.py @@ -1,9 +1,10 @@ import os import pytest -from osmox import build, config, helpers from shapely.geometry import Point, Polygon +from osmox import build, config, helpers + fixtures_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) toy_osm_path = os.path.join(fixtures_root, "toy.osm") park_osm_path = os.path.join(fixtures_root, "park.osm") diff --git a/tests/test_autotree.py b/tests/test_autotree.py index c14fe09..7fe7d8c 100644 --- a/tests/test_autotree.py +++ b/tests/test_autotree.py @@ -1,8 +1,9 @@ import os -from osmox import build, helpers from shapely.geometry import Point, Polygon +from osmox import build, helpers + root = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) test_osm_path = os.path.join(root, "isle-of-man-latest.osm.pbf") diff --git a/tests/test_config.py b/tests/test_config.py index 3538d3c..f193704 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,6 +1,7 @@ import os import pytest + from osmox import config root = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 1afe5bf..1c40feb 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,7 +1,8 @@ import pytest -from osmox import helpers from shapely.geometry import Polygon +from osmox import helpers + @pytest.mark.parametrize( "a,b,expected", From c0b151b9f8fdd7947640d30f7c0bf682b29a49d4 Mon Sep 17 00:00:00 2001 From: Bryn Pickering <17178478+brynpickering@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:16:43 +0000 Subject: [PATCH 09/13] Run pre-commit --- tests/test_activityhandler.py | 3 +-- tests/test_autotree.py | 3 +-- tests/test_cli.py | 1 - tests/test_config.py | 1 - tests/test_helpers.py | 3 +-- 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/test_activityhandler.py b/tests/test_activityhandler.py index ca8b6fd..c51d73d 100644 --- a/tests/test_activityhandler.py +++ b/tests/test_activityhandler.py @@ -1,9 +1,8 @@ import os import pytest -from shapely.geometry import Point, Polygon - from osmox import build, config, helpers +from shapely.geometry import Point, Polygon fixtures_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) toy_osm_path = os.path.join(fixtures_root, "toy.osm") diff --git a/tests/test_autotree.py b/tests/test_autotree.py index 7fe7d8c..c14fe09 100644 --- a/tests/test_autotree.py +++ b/tests/test_autotree.py @@ -1,8 +1,7 @@ import os -from shapely.geometry import Point, Polygon - from osmox import build, helpers +from shapely.geometry import Point, Polygon root = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) test_osm_path = os.path.join(root, "isle-of-man-latest.osm.pbf") diff --git a/tests/test_cli.py b/tests/test_cli.py index 43153a2..6d08b96 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,7 +4,6 @@ import pytest from click.testing import CliRunner - from osmox import cli logging.basicConfig(level=logging.INFO) diff --git a/tests/test_config.py b/tests/test_config.py index f193704..3538d3c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,7 +1,6 @@ import os import pytest - from osmox import config root = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 1c40feb..1afe5bf 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,7 +1,6 @@ import pytest -from shapely.geometry import Polygon - from osmox import helpers +from shapely.geometry import Polygon @pytest.mark.parametrize( From 3dc68fad02c6f42fa877fe16e239b9573535f8f3 Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Thu, 21 Mar 2024 11:20:55 +0000 Subject: [PATCH 10/13] tmp_path --- tests/test_cli.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 43153a2..e804bbc 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -25,6 +25,11 @@ def toy_osm_path(fixtures_root): return os.path.join(fixtures_root, "toy.osm") +@pytest.fixture +def path_output_dir(tmp_path): + return os.path.join(tmp_path, "output_test") + + @pytest.fixture def runner(): return CliRunner() @@ -37,19 +42,19 @@ def check_exit_code(result): assert result.exit_code == 0 -def test_cli_with_default_args(runner, config_path, toy_osm_path): +def test_cli_with_default_args(runner, config_path, toy_osm_path, path_output_dir): # Test the command with minimal arguments - result = runner.invoke(cli.run, [config_path, toy_osm_path, "output_test"]) + result = runner.invoke(cli.run, [config_path, toy_osm_path, path_output_dir]) check_exit_code(result) assert result.exit_code == 0 @pytest.mark.parametrize("output_format", ["geojson", "geopackage", "geoparquet"]) -def test_cli_output_formats(runner, config_path, toy_osm_path, output_format): +def test_cli_output_formats(runner, config_path, toy_osm_path, path_output_dir, output_format): result = runner.invoke( cli.run, - [config_path, toy_osm_path, "output_test", "-f", output_format, "-crs", "epsg:4326"], + [config_path, toy_osm_path, path_output_dir, "-f", output_format, "-crs", "epsg:4326"], ) check_exit_code(result) assert result.exit_code == 0 From 37b0d285848e4baf5f651f04ca4588cb764c9e2b Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Thu, 21 Mar 2024 11:41:45 +0000 Subject: [PATCH 11/13] pre-commit --- tests/test_cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index e804bbc..1f68028 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,7 +4,6 @@ import pytest from click.testing import CliRunner - from osmox import cli logging.basicConfig(level=logging.INFO) From f10f4a1d6051c9974d94479555b58a98ebaa52a8 Mon Sep 17 00:00:00 2001 From: val-ismaili Date: Thu, 21 Mar 2024 16:27:54 +0000 Subject: [PATCH 12/13] cli crs test and file writing --- tests/test_cli.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1f68028..870d325 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,7 @@ import logging import os import traceback +from pathlib import Path import pytest from click.testing import CliRunner @@ -34,6 +35,16 @@ def runner(): return CliRunner() +@pytest.fixture +def default_output_file_ending(): + return "_epsg_4326.gpkg" + + +@pytest.fixture +def default_output_file_path(path_output_dir, default_output_file_ending): + return Path(path_output_dir + default_output_file_ending) + + def check_exit_code(result): "Print full traceback if the CLI runner failed" if result.exit_code != 0: @@ -41,12 +52,15 @@ def check_exit_code(result): assert result.exit_code == 0 -def test_cli_with_default_args(runner, config_path, toy_osm_path, path_output_dir): +def test_cli_with_default_args( + runner, config_path, toy_osm_path, path_output_dir, default_output_file_path +): # Test the command with minimal arguments result = runner.invoke(cli.run, [config_path, toy_osm_path, path_output_dir]) check_exit_code(result) assert result.exit_code == 0 + assert default_output_file_path.exists() @pytest.mark.parametrize("output_format", ["geojson", "geopackage", "geoparquet"]) @@ -57,3 +71,18 @@ def test_cli_output_formats(runner, config_path, toy_osm_path, path_output_dir, ) check_exit_code(result) assert result.exit_code == 0 + + +@pytest.mark.parametrize("crs", ["epsg:27700"]) +def test_cli_output_crs( + runner, config_path, toy_osm_path, path_output_dir, crs, default_output_file_path +): + result = runner.invoke(cli.run, [config_path, toy_osm_path, path_output_dir, "-crs", crs]) + check_exit_code(result) + assert result.exit_code == 0 + + # test that file with default crs is still produced + assert default_output_file_path.exists() + + out_path = Path(path_output_dir + "_epsg_27700.gpkg") + assert out_path.exists() From a9d53b0dd5c1ee46e6de932dcc9146844e968e87 Mon Sep 17 00:00:00 2001 From: Bryn Pickering <17178478+brynpickering@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:44:33 +0000 Subject: [PATCH 13/13] Add file check in changing file extension; update min coverage --- pyproject.toml | 2 +- tests/test_cli.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2e2fcca..2fbfb9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ branch = true source = ["src/"] [tool.coverage.report] -fail_under = 62 +fail_under = 84 [tool.coverage.html] directory = "reports/coverage" diff --git a/tests/test_cli.py b/tests/test_cli.py index 870d325..d086030 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -9,6 +9,8 @@ logging.basicConfig(level=logging.INFO) +MAP_EXTENSIONS = {"geopackage": ".gpkg", "geojson": ".geojson", "geoparquet": ".parquet"} + @pytest.fixture def fixtures_root(): @@ -59,18 +61,20 @@ def test_cli_with_default_args( result = runner.invoke(cli.run, [config_path, toy_osm_path, path_output_dir]) check_exit_code(result) - assert result.exit_code == 0 assert default_output_file_path.exists() @pytest.mark.parametrize("output_format", ["geojson", "geopackage", "geoparquet"]) -def test_cli_output_formats(runner, config_path, toy_osm_path, path_output_dir, output_format): +def test_cli_output_formats( + runner, config_path, toy_osm_path, path_output_dir, default_output_file_path, output_format +): result = runner.invoke( cli.run, [config_path, toy_osm_path, path_output_dir, "-f", output_format, "-crs", "epsg:4326"], ) check_exit_code(result) - assert result.exit_code == 0 + + assert default_output_file_path.with_suffix(MAP_EXTENSIONS[output_format]).exists() @pytest.mark.parametrize("crs", ["epsg:27700"]) @@ -79,7 +83,6 @@ def test_cli_output_crs( ): result = runner.invoke(cli.run, [config_path, toy_osm_path, path_output_dir, "-crs", crs]) check_exit_code(result) - assert result.exit_code == 0 # test that file with default crs is still produced assert default_output_file_path.exists()