Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use context manager for file handles in case assertions fail #23

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ def test_access_array_h5():
attrs = {"resolution": "1000"}
with tempfile.TemporaryFile(suffix=".h5") as store:
arr = access_h5(store, key, data=data, attrs=attrs, mode="w")
assert dict(arr.attrs) == attrs
assert np.array_equal(arr[:], data)
arr.file.close()
with arr.file:
assert dict(arr.attrs) == attrs
assert np.array_equal(arr[:], data)

arr2 = access_h5(store, key, mode="r")
assert dict(arr2.attrs) == attrs
assert np.array_equal(arr2[:], data)
arr2.file.close()
with arr2.file:
assert dict(arr2.attrs) == attrs
assert np.array_equal(arr2[:], data)


def test_access_group_h5():
Expand All @@ -127,12 +127,12 @@ def test_access_group_h5():

with tempfile.TemporaryFile(suffix=".h5") as store:
grp = access_h5(store, key, attrs=attrs, mode="w")
assert dict(grp.attrs) == attrs
grp.file.close()
with grp.file:
assert dict(grp.attrs) == attrs

grp2 = access_h5(store, key, mode="r")
assert dict(grp2.attrs) == attrs
grp2.file.close()
with grp2.file:
assert dict(grp2.attrs) == attrs


def test_list_files():
Expand Down