pickle: test_pickle.py: Turn into real test, add more cases.

Including a test for arbitrary statement execution.
pull/255/head
Paul Sokolovsky 2018-01-21 14:45:12 +02:00
rodzic 4328dde8f8
commit 66f147a761
1 zmienionych plików z 19 dodań i 2 usunięć

Wyświetl plik

@ -2,6 +2,23 @@ import pickle
import sys
import io
pickle.dump({1:2}, sys.stdout)
print(pickle.loads("{4:5}"))
def roundtrip(val):
t = pickle.dumps(val)
t = pickle.loads(t)
assert t == val
roundtrip(1)
roundtrip(1.0)
roundtrip("str")
roundtrip(b"bytes")
roundtrip((1,))
roundtrip([1, 2])
roundtrip({1:2, 3: 4})
try:
pickle.loads("1; import micropython")
assert 0, "SyntaxError expected"
except SyntaxError:
pass