Skip to content

Commit

Permalink
add extra test for type type check
Browse files Browse the repository at this point in the history
  • Loading branch information
KasiaKoz committed May 28, 2024
1 parent 967b698 commit 68b723a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
29 changes: 0 additions & 29 deletions tests/test_output_sanitiser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import os

import genet.utils.io
from genet import Network
from genet.output import sanitiser
from genet.output import spatial as spatial_output
from geopandas import GeoDataFrame
from shapely.geometry import Point


def test_sanitising_list():
Expand Down Expand Up @@ -56,27 +51,3 @@ def test_sanitising_geodataframes_with_ids_list(assert_semantically_equal):
assert_semantically_equal(
links[["length", "from", "to", "id", "ids", "u", "v", "modes"]].to_dict(), correct_links
)


def test_saving_geodataframe_with_missing_geometry_produces_file(tmpdir):
expected_file_name = "tmp"
expected_output_path = tmpdir / expected_file_name + ".parquet"
assert not os.path.exists(expected_output_path)

data = {"id": ["1", "2"], "geometry": [float("nan"), Point(2, 1)]}
gdf = GeoDataFrame(data, crs="EPSG:4326")
genet.utils.io.save_geodataframe(gdf, filename=expected_file_name, output_dir=tmpdir)

assert os.path.exists(expected_output_path)


def test_saving_geodataframe_with_missing_data_in_string_column_produces_file(tmpdir):
expected_file_name = "tmp"
expected_output_path = tmpdir / expected_file_name + ".parquet"
assert not os.path.exists(expected_output_path)

data = {"id": ["1", float("nan")], "geometry": [Point(2, 1), Point(2, 1)]}
gdf = GeoDataFrame(data, crs="EPSG:4326")
genet.utils.io.save_geodataframe(gdf, filename=expected_file_name, output_dir=tmpdir)

assert os.path.exists(expected_output_path)
37 changes: 37 additions & 0 deletions tests/test_utils_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

import genet.utils.io
import pytest
from geopandas import GeoDataFrame
from shapely import Point


def test_throws_error_when_filetype_is_not_supported():
with pytest.raises(RuntimeError) as e:
genet.utils.io.check_file_type_is_supported("hello")

assert "is not a supported file type" in str(e.value)


def test_saving_geodataframe_with_missing_geometry_produces_file(tmpdir):
expected_file_name = "tmp"
expected_output_path = tmpdir / expected_file_name + ".parquet"
assert not os.path.exists(expected_output_path)

data = {"id": ["1", "2"], "geometry": [float("nan"), Point(2, 1)]}
gdf = GeoDataFrame(data, crs="EPSG:4326")
genet.utils.io.save_geodataframe(gdf, filename=expected_file_name, output_dir=tmpdir)

assert os.path.exists(expected_output_path)


def test_saving_geodataframe_with_missing_data_in_string_column_produces_file(tmpdir):
expected_file_name = "tmp"
expected_output_path = tmpdir / expected_file_name + ".parquet"
assert not os.path.exists(expected_output_path)

data = {"id": ["1", float("nan")], "geometry": [Point(2, 1), Point(2, 1)]}
gdf = GeoDataFrame(data, crs="EPSG:4326")
genet.utils.io.save_geodataframe(gdf, filename=expected_file_name, output_dir=tmpdir)

assert os.path.exists(expected_output_path)

0 comments on commit 68b723a

Please sign in to comment.