Skip to content

Commit 254c780

Browse files
committed
test
1 parent 29fc647 commit 254c780

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/test_serializer.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,39 @@ def test_max_value_length(body_normalizer):
180180
result = body_normalizer(data, max_value_length=max_value_length)
181181

182182
assert len(result["key"]) == max_value_length
183+
184+
185+
def test_serialize_local_vars():
186+
# This was added to make sure we don't try to iterate over instances of
187+
# custom classes with an __iter__ method due to potential side effects
188+
class Custom:
189+
def __init__(self, items):
190+
self.items = items
191+
192+
def __len__(self):
193+
return self.items.__len__()
194+
195+
def __getitem__(self, item):
196+
return self.items.__getitem__(item)
197+
198+
def __iter__(self):
199+
raise ValueError
200+
201+
local_vars = {
202+
"str": "123",
203+
"bytes": b"123",
204+
"list": [1, 2, 3],
205+
"set": {1, 2, 3},
206+
"frozenset": frozenset([1, 2, 3]),
207+
"custom": Custom([1, 2, 3]),
208+
}
209+
210+
result = serialize(local_vars, is_vars=True)
211+
assert result["str"] == "'123'"
212+
assert result["bytes"] == "b'123'"
213+
assert result["list"] == ["1", "2", "3"]
214+
assert result["set"] == ["1", "2", "3"]
215+
assert result["frozenset"] == ["1", "2", "3"]
216+
assert result["custom"].startswith(
217+
"<tests.test_serializer.test_serialize_local_vars.<locals>.Custom object at"
218+
)

0 commit comments

Comments
 (0)