From 66f147a7616c73aef27977b76d977c255a3e5890 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 21 Jan 2018 14:45:12 +0200 Subject: [PATCH] pickle: test_pickle.py: Turn into real test, add more cases. Including a test for arbitrary statement execution. --- pickle/test_pickle.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pickle/test_pickle.py b/pickle/test_pickle.py index 1422c02e..1bbdd94a 100644 --- a/pickle/test_pickle.py +++ b/pickle/test_pickle.py @@ -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