-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert to changing how unit_system_name is saved
- Loading branch information
1 parent
50b31d9
commit 03144f3
Showing
3 changed files
with
20 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import numpy as np | ||
|
||
from yt.loaders import load, load_uniform_grid | ||
from yt.loaders import load_uniform_grid | ||
from yt.testing import requires_module_pytest | ||
from yt.utilities.on_demand_imports import _h5py as h5py | ||
|
||
|
||
@requires_module_pytest("h5py") | ||
def test_save_as_data_unit_system(tmp_path): | ||
|
||
# This test loads in a DataContainer saved with save_as_dataset and checks | ||
# for the "code" string in the unit_system name. Added to help | ||
# avoid regressions with https://github.com/yt-project/yt/issues/4315 The | ||
# test here is not a complete test as that bug manifests when restarting | ||
# the python kernel. | ||
# This test checks that the file saved with calling save_as_dataset | ||
# for a ds with a "code" unit system contains the proper "unit_system_name". | ||
# It checks the hdf5 file directly rather than using yt.load(), because | ||
# https://github.com/yt-project/yt/issues/4315 only manifested restarting | ||
# the python kernel (because the unit registry is state dependent). | ||
|
||
fi = tmp_path / "output_data.h5" | ||
shp = (4, 4, 4) | ||
data = {"density": np.random.random(shp)} | ||
ds = load_uniform_grid(data, shp, unit_system="code") | ||
assert "code" in ds.unit_system.name | ||
assert "code" in ds._unit_system_name | ||
|
||
sp = ds.sphere(ds.domain_center, ds.domain_width[0] / 2.0) | ||
sp.save_as_dataset(fi) | ||
|
||
ds_new = load(fi, unit_system="code") | ||
assert "code" in ds_new.unit_system.name | ||
with h5py.File(fi, mode="r") as f: | ||
assert f.attrs["unit_system_name"] == "code" |
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