about summary refs log tree commit diff
path: root/tests/test_serialization.py
diff options
context:
space:
mode:
authorArun Isaac2025-08-04 14:48:27 +0100
committerArun Isaac2025-08-06 22:40:42 +0100
commitbc046a25f1531386293a470e21b569f8411f2235 (patch)
tree0b28824677dc7240d7290ae494827014a1ff3f67 /tests/test_serialization.py
parent925bb7d67bcd7e5b756987093b15d21426852ba1 (diff)
downloadpyhegp-bc046a25f1531386293a470e21b569f8411f2235.tar.gz
pyhegp-bc046a25f1531386293a470e21b569f8411f2235.tar.lz
pyhegp-bc046a25f1531386293a470e21b569f8411f2235.zip
Standardize key files.
* doc/file-formats.md (File formats)[key file]: New section.
* pyhegp/serialization.py: Import numpy.
(read_key, write_key): New functions.
* pyhegp/pyhegp.py: Import write_key from pyhegp.serialization.
(encrypt): Use write_key.
* tests/test_serialization.py: Import arrays and array_shapes from
hypothesis.extra.numpy; approx from pytest; read_key and write_key
from pyhegp.serialization.
(test_read_write_key_are_inverses): New test.
Diffstat (limited to 'tests/test_serialization.py')
-rw-r--r--tests/test_serialization.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/test_serialization.py b/tests/test_serialization.py
index 15de278..a473796 100644
--- a/tests/test_serialization.py
+++ b/tests/test_serialization.py
@@ -19,10 +19,12 @@
 import tempfile
 
 from hypothesis import given, strategies as st
+from hypothesis.extra.numpy import arrays, array_shapes
 from hypothesis.extra.pandas import column, columns, data_frames
 import pandas as pd
+from pytest import approx
 
-from pyhegp.serialization import Summary, read_summary, write_summary, read_summary_headers, read_genotype, write_genotype
+from pyhegp.serialization import Summary, read_summary, write_summary, read_summary_headers, read_genotype, write_genotype, read_key, write_key
 from pyhegp.utils import negate
 
 tabless_printable_ascii_text = st.text(
@@ -115,3 +117,11 @@ def test_read_write_genotype_are_inverses(genotype):
         write_genotype(file, genotype)
         file.seek(0)
         pd.testing.assert_frame_equal(genotype, read_genotype(file))
+
+@given(arrays("float64",
+              array_shapes(min_dims=2, max_dims=2)))
+def test_read_write_key_are_inverses(key):
+    with tempfile.TemporaryFile() as file:
+        write_key(file, key)
+        file.seek(0)
+        assert key == approx(read_key(file), nan_ok=True)