File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 3636if PY2 :
3737 # Importing ABCs from collections is deprecated, and will stop working in 3.8
3838 # https://github.com/python/cpython/blob/master/Lib/collections/__init__.py#L49
39- from collections import Mapping , Sequence
39+ from collections import Mapping , Sequence , Set
4040
4141 serializable_str_types = string_types
4242
4343else :
4444 # New in 3.3
4545 # https://docs.python.org/3/library/collections.abc.html
46- from collections .abc import Mapping , Sequence
46+ from collections .abc import Mapping , Sequence , Set
4747
4848 # Bytes are technically not strings in Python 3, but we can serialize them
4949 serializable_str_types = (str , bytes )
@@ -291,7 +291,9 @@ def _serialize_node_impl(
291291
292292 return rv_dict
293293
294- elif not isinstance (obj , serializable_str_types ) and isinstance (obj , Sequence ):
294+ elif not isinstance (obj , serializable_str_types ) and isinstance (
295+ obj , (Set , Sequence )
296+ ):
295297 rv_list = []
296298
297299 for i , v in enumerate (obj ):
Original file line number Diff line number Diff line change @@ -55,6 +55,19 @@ def inner(message, **kwargs):
5555 return inner
5656
5757
58+ @pytest .fixture
59+ def extra_normalizer (relay_normalize ):
60+ if relay_normalize ({"test" : "test" }) is None :
61+ pytest .skip ("no relay available" )
62+
63+ def inner (message , ** kwargs ):
64+ event = serialize ({"extra" : {"foo" : message }}, ** kwargs )
65+ normalized = relay_normalize (event )
66+ return normalized ["extra" ]["foo" ]
67+
68+ return inner
69+
70+
5871def test_bytes_serialization_decode (message_normalizer ):
5972 binary = b"abc123\x80 \xf0 \x9f \x8d \x95 "
6073 result = message_normalizer (binary , should_repr_strings = False )
@@ -66,3 +79,8 @@ def test_bytes_serialization_repr(message_normalizer):
6679 binary = b"abc123\x80 \xf0 \x9f \x8d \x95 "
6780 result = message_normalizer (binary , should_repr_strings = True )
6881 assert result == r"b'abc123\x80\xf0\x9f\x8d\x95'"
82+
83+
84+ def test_serialize_sets (extra_normalizer ):
85+ result = extra_normalizer ({1 , 2 , 3 })
86+ assert result == [1 , 2 , 3 ]
You can’t perform that action at this time.
0 commit comments