-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from fema-ffrd/release/0.1.0
Release/0.1.0
- Loading branch information
Showing
6 changed files
with
98 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import h5py | ||
|
||
from pathlib import Path | ||
|
||
|
||
def _create_hdf_with_group_attrs(path: Path, group_path: str, attrs: dict): | ||
with h5py.File(path, "w") as f: | ||
group = f.create_group(group_path) | ||
for key, value in attrs.items(): | ||
group.attrs[key] = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,51 @@ | ||
from src.rashdf import RasPlanHdf | ||
|
||
import h5py | ||
from . import _create_hdf_with_group_attrs | ||
|
||
attrs_to_set = {"test_attribute1": "test_str1", "test_attribute2": 500} | ||
TEST_ATTRS = {"test_attribute1": "test_str1", "test_attribute2": 500} | ||
|
||
|
||
def test_get_plan_info_attrs(tmp_path): | ||
with h5py.File(tmp_path / "test.hdf", "w") as f: | ||
group = f.create_group(RasPlanHdf.PLAN_INFO_PATH) | ||
for key, value in attrs_to_set.items(): | ||
group.attrs[key] = value | ||
|
||
ras_plan_hdf = RasPlanHdf(tmp_path / "test.hdf") | ||
|
||
assert ras_plan_hdf.get_plan_info_attrs() == attrs_to_set | ||
test_hdf = tmp_path / "test.hdf" | ||
_create_hdf_with_group_attrs(test_hdf, RasPlanHdf.PLAN_INFO_PATH, TEST_ATTRS) | ||
ras_plan_hdf = RasPlanHdf(test_hdf) | ||
assert ras_plan_hdf.get_plan_info_attrs() == TEST_ATTRS | ||
|
||
|
||
def test_get_plan_param_attrs(tmp_path): | ||
with h5py.File(tmp_path / "test.hdf", "w") as f: | ||
group = f.create_group(RasPlanHdf.PLAN_PARAMS_PATH) | ||
for key, value in attrs_to_set.items(): | ||
group.attrs[key] = value | ||
|
||
ras_plan_hdf = RasPlanHdf(tmp_path / "test.hdf") | ||
|
||
assert ras_plan_hdf.get_plan_param_attrs() == attrs_to_set | ||
test_hdf = tmp_path / "test.hdf" | ||
_create_hdf_with_group_attrs(test_hdf, RasPlanHdf.PLAN_PARAMS_PATH, TEST_ATTRS) | ||
ras_plan_hdf = RasPlanHdf(test_hdf) | ||
assert ras_plan_hdf.get_plan_param_attrs() == TEST_ATTRS | ||
|
||
|
||
def test_get_meteorology_precip_attrs(tmp_path): | ||
with h5py.File(tmp_path / "test.hdf", "w") as f: | ||
group = f.create_group(RasPlanHdf.PRECIP_PATH) | ||
for key, value in attrs_to_set.items(): | ||
group.attrs[key] = value | ||
|
||
ras_plan_hdf = RasPlanHdf(tmp_path / "test.hdf") | ||
|
||
assert ras_plan_hdf.get_meteorology_precip_attrs() == attrs_to_set | ||
test_hdf = tmp_path / "test.hdf" | ||
_create_hdf_with_group_attrs(test_hdf, RasPlanHdf.PRECIP_PATH, TEST_ATTRS) | ||
ras_plan_hdf = RasPlanHdf(test_hdf) | ||
assert ras_plan_hdf.get_meteorology_precip_attrs() == TEST_ATTRS | ||
|
||
|
||
def test_get_results_unsteady_attrs(tmp_path): | ||
with h5py.File(tmp_path / "test.hdf", "w") as f: | ||
group = f.create_group(RasPlanHdf.RESULTS_UNSTEADY_PATH) | ||
for key, value in attrs_to_set.items(): | ||
group.attrs[key] = value | ||
|
||
ras_plan_hdf = RasPlanHdf(tmp_path / "test.hdf") | ||
|
||
assert ras_plan_hdf.get_results_unsteady_attrs() == attrs_to_set | ||
test_hdf = tmp_path / "test.hdf" | ||
_create_hdf_with_group_attrs(test_hdf, RasPlanHdf.RESULTS_UNSTEADY_PATH, TEST_ATTRS) | ||
ras_plan_hdf = RasPlanHdf(test_hdf) | ||
assert ras_plan_hdf.get_results_unsteady_attrs() == TEST_ATTRS | ||
|
||
|
||
def test_get_results_unsteady_summary_attrs(tmp_path): | ||
with h5py.File(tmp_path / "test.hdf", "w") as f: | ||
group = f.create_group(RasPlanHdf.RESULTS_UNSTEADY_SUMMARY_PATH) | ||
for key, value in attrs_to_set.items(): | ||
group.attrs[key] = value | ||
|
||
ras_plan_hdf = RasPlanHdf(tmp_path / "test.hdf") | ||
|
||
assert ras_plan_hdf.get_results_unsteady_summary_attrs() == attrs_to_set | ||
test_hdf = tmp_path / "test.hdf" | ||
_create_hdf_with_group_attrs( | ||
test_hdf, RasPlanHdf.RESULTS_UNSTEADY_SUMMARY_PATH, TEST_ATTRS | ||
) | ||
ras_plan_hdf = RasPlanHdf(test_hdf) | ||
assert ras_plan_hdf.get_results_unsteady_summary_attrs() == TEST_ATTRS | ||
|
||
|
||
def test_get_results_volume_accounting_attrs(tmp_path): | ||
with h5py.File(tmp_path / "test.hdf", "w") as f: | ||
group = f.create_group(RasPlanHdf.VOLUME_ACCOUNTING_PATH) | ||
for key, value in attrs_to_set.items(): | ||
group.attrs[key] = value | ||
|
||
ras_plan_hdf = RasPlanHdf(tmp_path / "test.hdf") | ||
|
||
assert ras_plan_hdf.get_results_volume_accounting_attrs() == attrs_to_set | ||
test_hdf = tmp_path / "test.hdf" | ||
_create_hdf_with_group_attrs( | ||
test_hdf, RasPlanHdf.VOLUME_ACCOUNTING_PATH, TEST_ATTRS | ||
) | ||
ras_plan_hdf = RasPlanHdf(test_hdf) | ||
assert ras_plan_hdf.get_results_volume_accounting_attrs() == TEST_ATTRS |