Skip to content

Commit ea7ad3e

Browse files
author
Michael Johansen
committed
Add set and frozenset tests.
Signed-off-by: Michael Johansen <[email protected]>
1 parent 2a0bb54 commit ea7ad3e

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/nipanel/_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _get_best_matching_type(python_value: object) -> str:
9292
underlying_parents = type(working_python_value).mro()
9393

9494
# If this element is a collection, we want to continue traversing. Once we find a
95-
# non-collection, underlying_elements will refer to the candidates for the non-
95+
# non-collection, underlying_parents will refer to the candidates for the non-
9696
# collection type.
9797
value_is_collection = any(
9898
_CONVERTIBLE_COLLECTION_TYPES.intersection(underlying_parents)

tests/unit/test_convert.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
(((1.0, 2.0), (3.0, 4.0)), "Collection.Collection.float"),
8787
((set([1.0, 2.0]), set([3.0, 4.0])), "Collection.Collection.float"),
8888
((frozenset([1.0, 2.0]), frozenset([3.0, 4.0])), "Collection.Collection.float"),
89+
(set([(1.0, 2.0), (3.0, 4.0)]), "Collection.Collection.float"),
90+
(set([frozenset([1.0, 2.0]), frozenset([3.0, 4.0])]), "Collection.Collection.float"),
91+
(frozenset([(1.0, 2.0), (3.0, 4.0)]), "Collection.Collection.float"),
92+
(frozenset([frozenset([1.0, 2.0]), frozenset([3.0, 4.0])]), "Collection.Collection.float"),
8993
],
9094
)
9195
def test___various_python_objects___get_best_matching_type___returns_correct_type_string(
@@ -224,8 +228,6 @@ def test___python_analog_waveform___to_any___valid_double_analog_waveform() -> N
224228
(((1.0, 2.0), (3.0, 4.0))),
225229
((set([1.0, 2.0]), set([3.0, 4.0]))),
226230
((frozenset([1.0, 2.0]), frozenset([3.0, 4.0]))),
227-
# sets and frozensets of collections don't preserve order,
228-
# so they need to be tested separately.
229231
],
230232
)
231233
def test___python_2dcollection_of_float___to_any___valid_double2darray(
@@ -244,6 +246,32 @@ def test___python_2dcollection_of_float___to_any___valid_double2darray(
244246
assert unpack_dest.data == expected_data
245247

246248

249+
@pytest.mark.parametrize(
250+
"python_value",
251+
[
252+
(set([(1.0, 2.0), (3.0, 4.0)])),
253+
(set([frozenset([1.0, 2.0]), frozenset([3.0, 4.0])])),
254+
(frozenset([(1.0, 2.0), (3.0, 4.0)])),
255+
(frozenset([frozenset([1.0, 2.0]), frozenset([3.0, 4.0])])),
256+
],
257+
)
258+
def test___python_set_of_collection_of_float___to_any___valid_double2darray(
259+
python_value: Collection[Collection[float]],
260+
) -> None:
261+
expected_data = [1.0, 2.0, 3.0, 4.0]
262+
expected_rows = 2
263+
expected_columns = 2
264+
result = nipanel._convert.to_any(python_value)
265+
unpack_dest = Double2DArray()
266+
_assert_any_and_unpack(result, unpack_dest)
267+
268+
assert isinstance(unpack_dest, Double2DArray)
269+
assert unpack_dest.rows == expected_rows
270+
assert unpack_dest.columns == expected_columns
271+
# Sets and frozensets don't maintain order, so sort before comparing.
272+
assert sorted(unpack_dest.data) == sorted(expected_data)
273+
274+
247275
# ========================================================
248276
# Protobuf Types: Protobuf to Python
249277
# ========================================================

0 commit comments

Comments
 (0)