diff options
author | Victor Stinner <vstinner@python.org> | 2019-10-28 15:40:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 15:40:08 +0100 |
commit | e471e72977c83664f13d041c78549140c86c92de (patch) | |
tree | feddc2c15e7199122f6f59992de0dab8f73b6149 /Lib/test/test_codecs.py | |
parent | 3bfc8e0fcc707d200c267ff05b052fd6a63c985a (diff) | |
download | cpython-e471e72977c83664f13d041c78549140c86c92de.tar.gz cpython-e471e72977c83664f13d041c78549140c86c92de.zip |
bpo-37330: open() no longer accept 'U' in file mode (GH-16959)
open(), io.open(), codecs.open() and fileinput.FileInput no longer
accept "U" ("universal newline") in the file mode. This flag was
deprecated since Python 3.3.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r-- | Lib/test/test_codecs.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index b37525bf660..e1638c11168 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -712,11 +712,23 @@ class UTF16Test(ReadTest, unittest.TestCase): self.addCleanup(support.unlink, support.TESTFN) with open(support.TESTFN, 'wb') as fp: fp.write(s) - with support.check_warnings(('', DeprecationWarning)): - reader = codecs.open(support.TESTFN, 'U', encoding=self.encoding) - with reader: + with codecs.open(support.TESTFN, 'r', + encoding=self.encoding) as reader: self.assertEqual(reader.read(), s1) + def test_invalid_modes(self): + for mode in ('U', 'rU', 'r+U'): + with self.assertRaises(ValueError) as cm: + codecs.open(support.TESTFN, mode, encoding=self.encoding) + self.assertIn('invalid mode', str(cm.exception)) + + for mode in ('rt', 'wt', 'at', 'r+t'): + with self.assertRaises(ValueError) as cm: + codecs.open(support.TESTFN, mode, encoding=self.encoding) + self.assertIn("can't have text and binary mode at once", + str(cm.exception)) + + class UTF16LETest(ReadTest, unittest.TestCase): encoding = "utf-16-le" ill_formed_sequence = b"\x80\xdc" |