Skip to content

Commit 66f147a

Browse files
committed
pickle: test_pickle.py: Turn into real test, add more cases.
Including a test for arbitrary statement execution.
1 parent 4328dde commit 66f147a

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

pickle/test_pickle.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
import sys
33
import io
44

5-
pickle.dump({1:2}, sys.stdout)
65

7-
print(pickle.loads("{4:5}"))
6+
def roundtrip(val):
7+
t = pickle.dumps(val)
8+
t = pickle.loads(t)
9+
assert t == val
10+
11+
12+
roundtrip(1)
13+
roundtrip(1.0)
14+
roundtrip("str")
15+
roundtrip(b"bytes")
16+
roundtrip((1,))
17+
roundtrip([1, 2])
18+
roundtrip({1:2, 3: 4})
19+
20+
try:
21+
pickle.loads("1; import micropython")
22+
assert 0, "SyntaxError expected"
23+
except SyntaxError:
24+
pass

0 commit comments

Comments
 (0)