Skip to content

Commit

Permalink
TST: add test for no extent column in locations_csv (#498)
Browse files Browse the repository at this point in the history
* TST: add test for no extent for locations_csv

* CLN: remove assert locs.as_locations
  • Loading branch information
bifbof authored Aug 2, 2023
1 parent 07b201a commit 43b04d6
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/io/test_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import filecmp
import os
import pytest

import geopandas as gpd
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal
from geopandas.testing import assert_geodataframe_equal
from shapely.geometry import Point, Polygon

import trackintel as ti

Expand Down Expand Up @@ -213,6 +217,24 @@ def test_set_index(self):
assert pfs.index.name is None


@pytest.fixture
def example_locations():
"""Locations to load into the database."""
p1 = Point(8.5067847, 47.4)
p2 = Point(8.5067847, 47.5)
p3 = Point(8.5067847, 47.6)

list_dict = [
{"user_id": 0, "center": p1},
{"user_id": 0, "center": p2},
{"user_id": 1, "center": p3},
]
locs = gpd.GeoDataFrame(data=list_dict, geometry="center", crs="EPSG:4326")
locs.index.name = "id"
locs.as_locations
return locs


class TestLocations:
"""Test for 'read_locations_csv' and 'write_locations_csv' functions."""

Expand Down Expand Up @@ -253,6 +275,15 @@ def test_set_index(self):
pfs = ti.read_locations_csv(file, sep=";", index_col=None)
assert pfs.index.name is None

def test_without_extent(self, example_locations):
"""Test if without extent column data is correctly write/read."""
locs = example_locations
tmp_file = os.path.join("tests", "data", "locations_test.csv")
locs.as_locations.to_csv(tmp_file, sep=";")
locs_in = ti.read_locations_csv(tmp_file, sep=";", index_col="id", crs=4326)
assert_geodataframe_equal(locs, locs_in)
os.remove(tmp_file)


class TestTrips:
"""Test for 'read_trips_csv' and 'write_trips_csv' functions."""
Expand Down

0 comments on commit 43b04d6

Please sign in to comment.