summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-06-12 04:50:11 -0700
committerGitHub <noreply@github.com>2019-06-12 04:50:11 -0700
commitd561f848b235f2011a43b705d112055b92fa2366 (patch)
tree17367ffd5a657840af191bbedb1b99befbf8d38e /Lib/test
parent534136ac6790a701e24f364a9b7f1e34bf5f3ce7 (diff)
downloadcpython-git-d561f848b235f2011a43b705d112055b92fa2366.tar.gz
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. (cherry picked from commit 38ab7d4721b422547f7b46b9d68968863fa70573) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-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 5540d0015e..1d88fcb859 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -2709,22 +2709,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()
@@ -2748,6 +2746,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.