aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-05-31 11:29:39 +0300
committerGitHub <noreply@github.com>2019-05-31 11:29:39 +0300
commit38ab7d4721b422547f7b46b9d68968863fa70573 (patch)
treeaac2c1543f721338b6cf665e9d289ccad43a8af6 /Lib/test/pickletester.py
parentba0430211f5101c9d748d72b03926ca79c5252a8 (diff)
downloadcpython-38ab7d4721b422547f7b46b9d68968863fa70573.tar.gz
cpython-38ab7d4721b422547f7b46b9d68968863fa70573.zip
bpo-31829: Make protocol 0 pickles be loadable in text mode in Python 2. (GH-11859)
Escape ``\r``, ``\0`` and ``\x1a`` (end-of-file on Windows) in Unicode strings.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index f6fda9ee6d8..f8f3bc92e7f 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -3067,22 +3067,20 @@ class BadGetattr:
class AbstractPickleModuleTests(unittest.TestCase):
def test_dump_closed_file(self):
- import os
f = open(TESTFN, "wb")
try:
f.close()
self.assertRaises(ValueError, self.dump, 123, f)
finally:
- os.remove(TESTFN)
+ support.unlink(TESTFN)
def test_load_closed_file(self):
- import os
f = open(TESTFN, "wb")
try:
f.close()
self.assertRaises(ValueError, self.dump, 123, f)
finally:
- os.remove(TESTFN)
+ support.unlink(TESTFN)
def test_load_from_and_dump_to_file(self):
stream = io.BytesIO()
@@ -3106,6 +3104,19 @@ class AbstractPickleModuleTests(unittest.TestCase):
self.Pickler(f, -1)
self.Pickler(f, protocol=-1)
+ def test_dump_text_file(self):
+ f = open(TESTFN, "w")
+ try:
+ for proto in protocols:
+ self.assertRaises(TypeError, self.dump, 123, f, proto)
+ finally:
+ f.close()
+ support.unlink(TESTFN)
+
+ def test_incomplete_input(self):
+ s = io.BytesIO(b"X''.")
+ self.assertRaises((EOFError, struct.error, pickle.UnpicklingError), self.load, s)
+
def test_bad_init(self):
# Test issue3664 (pickle can segfault from a badly initialized Pickler).
# Override initialization without calling __init__() of the superclass.