]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #15204: Silence and check the 'U' mode deprecation warnings in tests.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 24 Nov 2013 21:13:26 +0000 (23:13 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 24 Nov 2013 21:13:26 +0000 (23:13 +0200)
Changed deprecation message in the fileinput module.

Lib/fileinput.py
Lib/test/test_codecs.py
Lib/test/test_fileinput.py
Lib/test/test_io.py
Lib/test/test_zipfile.py

index 11ba82df875ac1c2fc20073dda3a00c464111b65..de2951844aef2b5831558c41d5c643cf5456b3cf 100644 (file)
@@ -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",
+            warnings.warn("'U' mode is deprecated",
                           DeprecationWarning, 2)
         self._mode = mode
         if openhook:
index 639ce9fd8522c2ff6c6fc02ceab551d88cd576be..f6823805feec828cfe1e0aabd94e14cbb64b8387 100644 (file)
@@ -602,7 +602,9 @@ class UTF16Test(ReadTest, unittest.TestCase):
         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:
+        with support.check_warnings(('', DeprecationWarning)):
+            reader = codecs.open(support.TESTFN, 'U', encoding=self.encoding)
+        with reader:
             self.assertEqual(reader.read(), s1)
 
 class UTF16LETest(ReadTest, unittest.TestCase):
index c5e57d471562c4ca3c5fb9880bd414a7410d1d84..db6082cb12e6279ac7c74a7506ca75c3826ce086 100644 (file)
@@ -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")
-            lines = list(fi)
+            with check_warnings(('', DeprecationWarning)):
+                fi = FileInput(files=t1, mode="U")
+            with check_warnings(('', DeprecationWarning)):
+                lines = list(fi)
             self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"])
         finally:
             remove_tempfiles(t1)
index c1ea6f245f35df7c2278dca9f43ca80cb1e8081f..57f3659667abebd7351c8f4d541597bdfd599dcf 100644 (file)
@@ -2777,7 +2777,8 @@ class MiscIOTest(unittest.TestCase):
         self.assertEqual(f.mode, "wb")
         f.close()
 
-        f = self.open(support.TESTFN, "U")
+        with support.check_warnings(('', DeprecationWarning)):
+            f = self.open(support.TESTFN, "U")
         self.assertEqual(f.name,            support.TESTFN)
         self.assertEqual(f.buffer.name,     support.TESTFN)
         self.assertEqual(f.buffer.raw.name, support.TESTFN)
index c15ea9fa26e58b6bb58200e15f34e30f39af404f..49eccbb1d7da83de876796be6e70f3e805794159 100644 (file)
@@ -14,7 +14,7 @@ from random import randint, random, getrandbits
 
 from test.support import (TESTFN, findfile, unlink,
                           requires_zlib, requires_bz2, requires_lzma,
-                          captured_stdout)
+                          captured_stdout, check_warnings)
 
 TESTFN2 = TESTFN + "2"
 TESTFNDIR = TESTFN + "d"
@@ -35,6 +35,10 @@ def get_files(test):
         yield f
         test.assertFalse(f.closed)
 
+def openU(zipfp, fn):
+    with check_warnings(('', DeprecationWarning)):
+        return zipfp.open(fn, 'rU')
+
 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()
+        with zipfile.ZipFile(f, "w") as zipfp:
+            zipfp.writestr('spam.txt', b'ababagalamaga')
+
+        with zipfile.ZipFile(f, "r") as zipfp:
+            for mode in 'U', 'rU':
+                with self.assertWarns(DeprecationWarning):
+                    zipopen = zipfp.open('spam.txt', mode)
+                zipopen.close()
+
     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, \
-             zipfp.open(TESTFN, 'rU') as zipopen:
+             openU(zipfp, TESTFN) as zipopen:
             for line in zipopen:
                 data2 += line
 
@@ -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:
+                with openU(zipfp, fn) as fp:
                     zipdata = fp.read()
                 self.assertEqual(self.arcdata[sep], zipdata)
 
@@ -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:
+                with openU(zipfp, fn) as zipopen:
                     data = b''
                     while True:
                         read = zipopen.readline()
@@ -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:
+                with openU(zipfp, fn) as zipopen:
                     for line in self.line_gen:
                         linedata = zipopen.readline()
                         self.assertEqual(linedata, line + b'\n')
@@ -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:
+                with openU(zipfp, fn) as fp:
                     ziplines = fp.readlines()
                 for line, zipline in zip(self.line_gen, ziplines):
                     self.assertEqual(zipline, line + b'\n')
@@ -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:
+                with openU(zipfp, fn) as fp:
                     for line, zipline in zip(self.line_gen, fp):
                         self.assertEqual(zipline, line + b'\n')