8000 TST: Verify determinism of `savez` and `savez_compressed` by mdsmarte · Pull Request #21994 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TST: Verify determinism of savez and savez_compressed #21994

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added numpy/lib/tests/data/py3-arr-savez-compressed.npz
Binary file not shown.
Binary file added numpy/lib/tests/data/py3-arr-savez.npz
Binary file not shown.
28 changes: 28 additions & 0 deletions numpy/lib/tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import os

import numpy as np
Expand Down Expand Up @@ -245,3 +246,30 @@ class C():
raise AssertionError()
finally:
out.close()

def test_savez_deterministic(self):
# gh-9439
# Test that savez and savez_compressed are deterministic by comparing
# their results to bytes of existing files containing the same data.

data_path = os.path.join(os.path.dirname(__file__), "data")
testcases = [
("py3-arr-savez.npz", np.savez),
("py3-arr-savez-compressed.npz", np.savez_compressed),
]

for fname, save_fcn in testcases:
# Given
path = os.path.join(data_path, fname)
with open(path, "rb") as f:
expected_bytes = f.read()
with np.load(path) as f_npz:
data = dict(f_npz.items())

# When
stream = io.BytesIO()
save_fcn(stream, **data)
result_bytes = stream.getvalue()

# Then
assert result_bytes == expected_bytes
0