Skip to content

Commit bee8aa7

Browse files
committed
parameterize test_non_numpy_inputs
1 parent 72b5833 commit bee8aa7

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

numcodecs/tests/test_json.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
import numpy as np
5-
5+
import pytest
66

77
from numcodecs.json import JSON
88
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
@@ -53,21 +53,23 @@ def test_backwards_compatibility():
5353
check_backwards_compatibility(JSON.codec_id, arrays, codecs)
5454

5555

56-
def test_non_numpy_inputs():
56+
@pytest.mark.parametrize(
57+
"input_data, dtype",
58+
[
59+
([0, 1], None),
60+
([[0, 1], [2, 3]], None),
61+
([[0], [1], [2, 3]], object),
62+
([[[0, 0]], [[1, 1]], [[2, 3]]], None),
63+
(["1"], None),
64+
(["11", "11"], None),
65+
(["11", "1", "1"], None),
66+
([{}], None),
67+
([{"key": "value"}, ["list", "of", "strings"]], object),
68+
]
69+
)
70+
def test_non_numpy_inputs(input_data, dtype):
5771
# numpy will infer a range of different shapes and dtypes for these inputs.
5872
# Make sure that round-tripping through encode preserves this.
59-
data = [
60-
[0, 1],
61-
[[0, 1], [2, 3]],
62-
[[0], [1], [2, 3]],
63-
[[[0, 0]], [[1, 1]], [[2, 3]]],
64-
["1"],
65-
["11", "11"],
66-
["11", "1", "1"],
67-
[{}],
68-
[{"key": "value"}, ["list", "of", "strings"]],
69-
]
70-
for input_data in data:
71-
for codec in codecs:
72-
output_data = codec.decode(codec.encode(input_data))
73-
assert np.array_equal(np.array(input_data), output_data)
73+
for codec in codecs:
74+
output_data = codec.decode(codec.encode(input_data))
75+
assert np.array_equal(np.array(input_data, dtype=dtype), output_data)

numcodecs/tests/test_msgpacks.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import numpy as np
5+
import pytest
56

67

78
try:
@@ -52,30 +53,32 @@ def test_backwards_compatibility():
5253
check_backwards_compatibility(codec.codec_id, arrays, [codec])
5354

5455

55-
def test_non_numpy_inputs():
56+
@pytest.mark.parametrize(
57+
"input_data, dtype",
58+
[
59+
([0, 1], None),
60+
([[0, 1], [2, 3]], None),
61+
([[0], [1], [2, 3]], object),
62+
([[[0, 0]], [[1, 1]], [[2, 3]]], None),
63+
(["1"], None),
64+
(["11", "11"], None),
65+
(["11", "1", "1"], None),
66+
([{}], None),
67+
([{"key": "value"}, ["list", "of", "strings"]], object),
68+
([b"1"], None),
69+
([b"11", b"11"], None),
70+
([b"11", b"1", b"1"], None),
71+
([{b"key": b"value"}, [b"list", b"of", b"strings"]], object),
72+
]
73+
)
74+
def test_non_numpy_inputs(input_data, dtype):
5675
codec = MsgPack()
5776
# numpy will infer a range of different shapes and dtypes for these inputs.
5877
# Make sure that round-tripping through encode preserves this.
59-
data = [
60-
[0, 1],
61-
[[0, 1], [2, 3]],
62-
[[0], [1], [2, 3]],
63-
[[[0, 0]], [[1, 1]], [[2, 3]]],
64-
["1"],
65-
["11", "11"],
66-
["11", "1", "1"],
67-
[{}],
68-
[{"key": "value"}, ["list", "of", "strings"]],
69-
[b"1"],
70-
[b"11", b"11"],
71-
[b"11", b"1", b"1"],
72-
[{b"key": b"value"}, [b"list", b"of", b"strings"]],
73-
]
74-
for input_data in data:
75-
actual = codec.decode(codec.encode(input_data))
76-
expect = np.array(input_data)
77-
assert expect.shape == actual.shape
78-
assert np.array_equal(expect, actual)
78+
actual = codec.decode(codec.encode(input_data))
79+
expect = np.array(input_data, dtype=dtype)
80+
assert expect.shape == actual.shape
81+
assert np.array_equal(expect, actual)
7982

8083

8184
def test_encode_decode_shape_dtype_preserved():

0 commit comments

Comments
 (0)