cpython: 694e2708b4a8 (original) (raw)
Mercurial > cpython
changeset 87520:694e2708b4a8
Issue #15204: Silence and check the 'U' mode deprecation warnings in tests. Changed deprecation message in the fileinput module. [#15204]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Sun, 24 Nov 2013 23:13:26 +0200 |
parents | ead3f5a907bd |
children | 0d2ac94fa389 |
files | Lib/fileinput.py Lib/test/test_codecs.py Lib/test/test_fileinput.py Lib/test/test_io.py Lib/test/test_zipfile.py |
diffstat | 5 files changed, 33 insertions(+), 13 deletions(-)[+] [-] Lib/fileinput.py 2 Lib/test/test_codecs.py 4 Lib/test/test_fileinput.py 8 Lib/test/test_io.py 3 Lib/test/test_zipfile.py 29 |
line wrap: on
line diff
--- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -224,7 +224,7 @@ class FileInput: "'r', 'rU', 'U' and 'rb'") if 'U' in mode: import warnings
warnings.warn("Use of 'U' mode is deprecated",[](#l1.7)
warnings.warn("'U' mode is deprecated",[](#l1.8) DeprecationWarning, 2)[](#l1.9) self._mode = mode[](#l1.10) if openhook:[](#l1.11)
--- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -602,7 +602,9 @@ class UTF16Test(ReadTest, unittest.TestC self.addCleanup(support.unlink, support.TESTFN) with open(support.TESTFN, 'wb') as fp: fp.write(s)
with codecs.open(support.TESTFN, 'U', encoding=self.encoding) as reader:[](#l2.7)
with support.check_warnings(('', DeprecationWarning)):[](#l2.8)
reader = codecs.open(support.TESTFN, 'U', encoding=self.encoding)[](#l2.9)
with reader:[](#l2.10) self.assertEqual(reader.read(), s1)[](#l2.11)
class UTF16LETest(ReadTest, unittest.TestCase):
--- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -22,7 +22,7 @@ except ImportError: from io import StringIO from fileinput import FileInput, hook_encoded -from test.support import verbose, TESTFN, run_unittest +from test.support import verbose, TESTFN, run_unittest, check_warnings from test.support import unlink as safe_unlink @@ -224,8 +224,10 @@ class FileInputTests(unittest.TestCase): try: # try opening in universal newline mode t1 = writeTmp(1, [b"A\nB\r\nC\rD"], mode="wb")
fi = FileInput(files=t1, mode="U")[](#l3.16)
lines = list(fi)[](#l3.17)
with check_warnings(('', DeprecationWarning)):[](#l3.18)
fi = FileInput(files=t1, mode="U")[](#l3.19)
with check_warnings(('', DeprecationWarning)):[](#l3.20)
lines = list(fi)[](#l3.21) self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"])[](#l3.22) finally:[](#l3.23) remove_tempfiles(t1)[](#l3.24)
--- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2777,7 +2777,8 @@ class MiscIOTest(unittest.TestCase): self.assertEqual(f.mode, "wb") f.close()
f = self.open(support.TESTFN, "U")[](#l4.7)
with support.check_warnings(('', DeprecationWarning)):[](#l4.8)
f = self.open(support.TESTFN, "U")[](#l4.9) self.assertEqual(f.name, support.TESTFN)[](#l4.10) self.assertEqual(f.buffer.name, support.TESTFN)[](#l4.11) self.assertEqual(f.buffer.raw.name, support.TESTFN)[](#l4.12)
--- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -14,7 +14,7 @@ from random import randint, random, getr from test.support import (TESTFN, findfile, unlink, requires_zlib, requires_bz2, requires_lzma,
captured_stdout)[](#l5.7)
captured_stdout, check_warnings)[](#l5.8)
TESTFN2 = TESTFN + "2" TESTFNDIR = TESTFN + "d" @@ -35,6 +35,10 @@ def get_files(test): yield f test.assertFalse(f.closed) +def openU(zipfp, fn):
+ class AbstractTestsWithSourceFile: @classmethod def setUpClass(cls): @@ -875,6 +879,17 @@ class OtherTests(unittest.TestCase): data += zipfp.read(info) self.assertIn(data, {b"foobar", b"barfoo"})
- def test_universal_deprecation(self):
f = io.BytesIO()[](#l5.28)
with zipfile.ZipFile(f, "w") as zipfp:[](#l5.29)
zipfp.writestr('spam.txt', b'ababagalamaga')[](#l5.30)
with zipfile.ZipFile(f, "r") as zipfp:[](#l5.32)
for mode in 'U', 'rU':[](#l5.33)
with self.assertWarns(DeprecationWarning):[](#l5.34)
zipopen = zipfp.open('spam.txt', mode)[](#l5.35)
zipopen.close()[](#l5.36)
+ def test_universal_readaheads(self): f = io.BytesIO() @@ -884,7 +899,7 @@ class OtherTests(unittest.TestCase): data2 = b'' with zipfile.ZipFile(f, 'r') as zipfp, [](#l5.44)
zipfp.open(TESTFN, 'rU') as zipopen:[](#l5.45)
openU(zipfp, TESTFN) as zipopen:[](#l5.46) for line in zipopen:[](#l5.47) data2 += line[](#l5.48)
@@ -1613,7 +1628,7 @@ class AbstractUniversalNewlineTests: # Read the ZIP archive with zipfile.ZipFile(f, "r") as zipfp: for sep, fn in self.arcfiles.items():
with zipfp.open(fn, "rU") as fp:[](#l5.54)
with openU(zipfp, fn) as fp:[](#l5.55) zipdata = fp.read()[](#l5.56) self.assertEqual(self.arcdata[sep], zipdata)[](#l5.57)
@@ -1627,7 +1642,7 @@ class AbstractUniversalNewlineTests: # Read the ZIP archive with zipfile.ZipFile(f, "r") as zipfp: for sep, fn in self.arcfiles.items():
with zipfp.open(fn, "rU") as zipopen:[](#l5.63)
with openU(zipfp, fn) as zipopen:[](#l5.64) data = b''[](#l5.65) while True:[](#l5.66) read = zipopen.readline()[](#l5.67)
@@ -1652,7 +1667,7 @@ class AbstractUniversalNewlineTests: # Read the ZIP archive with zipfile.ZipFile(f, "r") as zipfp: for sep, fn in self.arcfiles.items():
with zipfp.open(fn, "rU") as zipopen:[](#l5.72)
with openU(zipfp, fn) as zipopen:[](#l5.73) for line in self.line_gen:[](#l5.74) linedata = zipopen.readline()[](#l5.75) self.assertEqual(linedata, line + b'\n')[](#l5.76)
@@ -1667,7 +1682,7 @@ class AbstractUniversalNewlineTests: # Read the ZIP archive with zipfile.ZipFile(f, "r") as zipfp: for sep, fn in self.arcfiles.items():
with zipfp.open(fn, "rU") as fp:[](#l5.81)
with openU(zipfp, fn) as fp:[](#l5.82) ziplines = fp.readlines()[](#l5.83) for line, zipline in zip(self.line_gen, ziplines):[](#l5.84) self.assertEqual(zipline, line + b'\n')[](#l5.85)
@@ -1682,7 +1697,7 @@ class AbstractUniversalNewlineTests: # Read the ZIP archive with zipfile.ZipFile(f, "r") as zipfp: for sep, fn in self.arcfiles.items():
with zipfp.open(fn, "rU") as fp:[](#l5.90)
with openU(zipfp, fn) as fp:[](#l5.91) for line, zipline in zip(self.line_gen, fp):[](#l5.92) self.assertEqual(zipline, line + b'\n')[](#l5.93)