From ac4379e93de708e255529c3b7daece4899cc0b17 Mon Sep 17 00:00:00 2001 From: Malcolm Greaves Date: Thu, 10 Jun 2021 13:19:24 -0700 Subject: [PATCH] add roundtrip serialization test for List[List[Dict[int, np.ndarray]]] --- tests/test_custom_serialization.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_custom_serialization.py b/tests/test_custom_serialization.py index 56565bf..579fcaa 100644 --- a/tests/test_custom_serialization.py +++ b/tests/test_custom_serialization.py @@ -149,3 +149,24 @@ def check(*, actual, expected): _roundtrip(mnt, custom_serialize, custom_deserialize, check) _roundtrip(mdc, custom_serialize, custom_deserialize, check) + + +def test_nested_array_dict_int_keys(custom_serialize, custom_deserialize): + N = 4 + M = 3 + + def check(*, actual, expected): + assert isinstance(actual, type(expected)) + assert len(actual) == N + for xs in actual: + assert len(xs) == M + for i, arr in xs.items(): + assert isinstance(i, int) + _check_array_like(actual=arr, expected=np.ones(i)) + + m: List[List[Dict[int, np.ndarray]]] = [[ + [{i:np.ones(i) for i in range(M)] + for _ in range(N) + ]] + + _roundtrip(m, custom_serialize, custom_deserialize, check)