Skip to content

Commit 61a1a7c

Browse files
author
Stevenray Janke
committed
Add unit tests for 1d funcs
1 parent 2d28525 commit 61a1a7c

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tests/test_geom.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import h5py
44
from geopandas import GeoDataFrame
55
from pyproj import CRS
6+
import json
67
from pathlib import Path
78

89
from . import _create_hdf_with_group_attrs
910

1011
TEST_DATA = Path("./tests/data")
1112
MUNCIE_G05 = TEST_DATA / "ras/Muncie.g05.hdf"
13+
BAXTER_P01 = TEST_DATA / "ras_1d/Baxter.p01.hdf"
1214
TEST_JSON = TEST_DATA / "json"
1315

1416
TEST_ATTRS = {"test_attribute1": "test_str1", "test_attribute2": 500}
@@ -30,6 +32,11 @@ def _gdf_matches_json(gdf: GeoDataFrame, json_file: Path) -> bool:
3032
return gdf.to_json() == j.read()
3133

3234

35+
def _gdf_matches_json_alt(gdf: GeoDataFrame, json_file: Path) -> bool:
36+
with open(json_file) as j:
37+
return json.loads(gdf.to_json()) == json.load(j)
38+
39+
3340
def test_mesh_area_names():
3441
with RasGeomHdf(MUNCIE_G05) as ghdf:
3542
assert ghdf.mesh_area_names() == ["2D Interior Area", "Perimeter_NW"]
@@ -104,3 +111,46 @@ def test_structs():
104111
structs_json = TEST_JSON / "structures.json"
105112
with RasGeomHdf(MUNCIE_G05) as ghdf:
106113
assert _gdf_matches_json(ghdf.structures(datetime_to_str=True), structs_json)
114+
115+
116+
def test_cross_sections():
117+
cross_section_json = TEST_JSON / "cross_sections.json"
118+
with RasGeomHdf(BAXTER_P01) as ghdf:
119+
assert _gdf_matches_json_alt(
120+
ghdf.cross_sections(datetime_to_str=True), cross_section_json
121+
)
122+
123+
124+
def test_river_reaches():
125+
river_reaches_json = TEST_JSON / "river_reaches.json"
126+
with RasGeomHdf(BAXTER_P01) as ghdf:
127+
assert _gdf_matches_json_alt(ghdf.river_reaches(), river_reaches_json)
128+
129+
130+
def test_steady_flow_names():
131+
with RasGeomHdf(BAXTER_P01) as ghdf:
132+
assert ghdf.steady_flow_names() == ["Big"]
133+
134+
135+
def test_cross_sections_wsel():
136+
xs_wsel_json = TEST_JSON / "xc_wsel.json"
137+
with RasGeomHdf(BAXTER_P01) as ghdf:
138+
assert _gdf_matches_json_alt(ghdf.cross_sections_wsel(), xs_wsel_json)
139+
140+
141+
def test_cross_sections_elevations():
142+
xs_elevs_json = TEST_JSON / "xs_elevations.json"
143+
with RasGeomHdf(BAXTER_P01) as ghdf:
144+
assert _gdf_matches_json_alt(ghdf.cross_sections_elevations(), xs_elevs_json)
145+
146+
147+
def test_cross_sections_area():
148+
xs_area_json = TEST_JSON / "xs_area.json"
149+
with RasGeomHdf(BAXTER_P01) as ghdf:
150+
assert _gdf_matches_json_alt(ghdf.cross_sections_area(), xs_area_json)
151+
152+
153+
def test_cross_sections_velocity():
154+
xs_velocity_json = TEST_JSON / "xs_velocity.json"
155+
with RasGeomHdf(BAXTER_P01) as ghdf:
156+
assert _gdf_matches_json_alt(ghdf.cross_sections_velocity(), xs_velocity_json)

0 commit comments

Comments
 (0)