File tree 2 files changed +23
-3
lines changed
2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 36
36
if PY2 :
37
37
# Importing ABCs from collections is deprecated, and will stop working in 3.8
38
38
# 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
40
40
41
41
serializable_str_types = string_types
42
42
43
43
else :
44
44
# New in 3.3
45
45
# https://docs.python.org/3/library/collections.abc.html
46
- from collections .abc import Mapping , Sequence
46
+ from collections .abc import Mapping , Sequence , Set
47
47
48
48
# Bytes are technically not strings in Python 3, but we can serialize them
49
49
serializable_str_types = (str , bytes )
@@ -291,7 +291,9 @@ def _serialize_node_impl(
291
291
292
292
return rv_dict
293
293
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
+ ):
295
297
rv_list = []
296
298
297
299
for i , v in enumerate (obj ):
Original file line number Diff line number Diff line change @@ -55,6 +55,19 @@ def inner(message, **kwargs):
55
55
return inner
56
56
57
57
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
+
58
71
def test_bytes_serialization_decode (message_normalizer ):
59
72
binary = b"abc123\x80 \xf0 \x9f \x8d \x95 "
60
73
result = message_normalizer (binary , should_repr_strings = False )
@@ -66,3 +79,8 @@ def test_bytes_serialization_repr(message_normalizer):
66
79
binary = b"abc123\x80 \xf0 \x9f \x8d \x95 "
67
80
result = message_normalizer (binary , should_repr_strings = True )
68
81
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