[Python-checkins] cpython (2.7): Issue #22340: Fix Python 3 warnings in Python 2 tests

victor.stinner python-checkins at python.org
Fri Sep 5 21:09:01 CEST 2014


http://hg.python.org/cpython/rev/0675b3a55941
changeset:   92351:0675b3a55941
branch:      2.7
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Sep 05 21:05:05 2014 +0200
summary:
  Issue #22340: Fix Python 3 warnings in Python 2 tests

files:
  Lib/idlelib/idle_test/test_calltips.py |   2 +-
  Lib/sqlite3/test/dbapi.py              |   4 +-
  Lib/sqlite3/test/types.py              |  10 ++-
  Lib/sqlite3/test/userfunctions.py      |  20 ++++--
  Lib/test/test_collections.py           |  43 ++++++++-----
  Lib/test/test_hash.py                  |   3 +-
  Lib/test/test_hmac.py                  |  16 ++--
  Lib/test/test_ssl.py                   |   3 +-
  8 files changed, 63 insertions(+), 38 deletions(-)


diff --git a/Lib/idlelib/idle_test/test_calltips.py b/Lib/idlelib/idle_test/test_calltips.py
--- a/Lib/idlelib/idle_test/test_calltips.py
+++ b/Lib/idlelib/idle_test/test_calltips.py
@@ -163,7 +163,7 @@
     # In 3.x, get_entity changed from 'instance method' to module function
     # since 'self' not used. Use dummy instance until change 2.7 also.
     def test_bad_entity(self):
-        self.assertIsNone(CTi.get_entity('1/0'))
+        self.assertIsNone(CTi.get_entity('1//0'))
     def test_good_entity(self):
         self.assertIs(CTi.get_entity('int'), int)
 
diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py
--- a/Lib/sqlite3/test/dbapi.py
+++ b/Lib/sqlite3/test/dbapi.py
@@ -24,6 +24,7 @@
 import unittest
 import sys
 import sqlite3 as sqlite
+from test import test_support
 try:
     import threading
 except ImportError:
@@ -653,7 +654,8 @@
         ts = sqlite.TimestampFromTicks(42)
 
     def CheckBinary(self):
-        b = sqlite.Binary(chr(0) + "'")
+        with test_support.check_py3k_warnings():
+            b = sqlite.Binary(chr(0) + "'")
 
 class ExtensionTests(unittest.TestCase):
     def CheckScriptStringSql(self):
diff --git a/Lib/sqlite3/test/types.py b/Lib/sqlite3/test/types.py
--- a/Lib/sqlite3/test/types.py
+++ b/Lib/sqlite3/test/types.py
@@ -24,6 +24,7 @@
 import datetime
 import unittest
 import sqlite3 as sqlite
+from test import test_support
 try:
     import zlib
 except ImportError:
@@ -67,7 +68,8 @@
         self.assertEqual(row[0], val)
 
     def CheckBlob(self):
-        val = buffer("Guglhupf")
+        with test_support.check_py3k_warnings():
+            val = buffer("Guglhupf")
         self.cur.execute("insert into test(b) values (?)", (val,))
         self.cur.execute("select b from test")
         row = self.cur.fetchone()
@@ -231,7 +233,8 @@
 
     def CheckBlob(self):
         # default
-        val = buffer("Guglhupf")
+        with test_support.check_py3k_warnings():
+            val = buffer("Guglhupf")
         self.cur.execute("insert into test(bin) values (?)", (val,))
         self.cur.execute("select bin from test")
         row = self.cur.fetchone()
@@ -347,7 +350,8 @@
 
     def CheckBinaryInputForConverter(self):
         testdata = "abcdefg" * 10
-        result = self.con.execute('select ? as "x [bin]"', (buffer(zlib.compress(testdata)),)).fetchone()[0]
+        with test_support.check_py3k_warnings():
+            result = self.con.execute('select ? as "x [bin]"', (buffer(zlib.compress(testdata)),)).fetchone()[0]
         self.assertEqual(testdata, result)
 
 class DateTimeTests(unittest.TestCase):
diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py
--- a/Lib/sqlite3/test/userfunctions.py
+++ b/Lib/sqlite3/test/userfunctions.py
@@ -24,6 +24,7 @@
 
 import unittest
 import sqlite3 as sqlite
+from test import test_support
 
 def func_returntext():
     return "foo"
@@ -36,7 +37,8 @@
 def func_returnnull():
     return None
 def func_returnblob():
-    return buffer("blob")
+    with test_support.check_py3k_warnings():
+        return buffer("blob")
 def func_returnlonglong():
     return 1<<31
 def func_raiseexception():
@@ -202,8 +204,9 @@
         cur = self.con.cursor()
         cur.execute("select returnblob()")
         val = cur.fetchone()[0]
-        self.assertEqual(type(val), buffer)
-        self.assertEqual(val, buffer("blob"))
+        with test_support.check_py3k_warnings():
+            self.assertEqual(type(val), buffer)
+            self.assertEqual(val, buffer("blob"))
 
     def CheckFuncReturnLongLong(self):
         cur = self.con.cursor()
@@ -246,7 +249,8 @@
 
     def CheckParamBlob(self):
         cur = self.con.cursor()
-        cur.execute("select isblob(?)", (buffer("blob"),))
+        with test_support.check_py3k_warnings():
+            cur.execute("select isblob(?)", (buffer("blob"),))
         val = cur.fetchone()[0]
         self.assertEqual(val, 1)
 
@@ -269,8 +273,9 @@
                 b blob
                 )
             """)
-        cur.execute("insert into test(t, i, f, n, b) values (?, ?, ?, ?, ?)",
-            ("foo", 5, 3.14, None, buffer("blob"),))
+        with test_support.check_py3k_warnings():
+            cur.execute("insert into test(t, i, f, n, b) values (?, ?, ?, ?, ?)",
+                ("foo", 5, 3.14, None, buffer("blob"),))
 
         self.con.create_aggregate("nostep", 1, AggrNoStep)
         self.con.create_aggregate("nofinalize", 1, AggrNoFinalize)
@@ -362,7 +367,8 @@
 
     def CheckAggrCheckParamBlob(self):
         cur = self.con.cursor()
-        cur.execute("select checkType('blob', ?)", (buffer("blob"),))
+        with test_support.check_py3k_warnings():
+            cur.execute("select checkType('blob', ?)", (buffer("blob"),))
         val = cur.fetchone()[0]
         self.assertEqual(val, 1)
 
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -8,13 +8,14 @@
 from random import randrange, shuffle
 import keyword
 import re
-import sets
 import sys
 from collections import Hashable, Iterable, Iterator
 from collections import Sized, Container, Callable
 from collections import Set, MutableSet
 from collections import Mapping, MutableMapping
 from collections import Sequence, MutableSequence
+with test_support.check_warnings(('', DeprecationWarning)):
+    import sets
 
 TestNT = namedtuple('TestNT', 'x y z')    # type used for pickle tests
 
@@ -713,10 +714,12 @@
         self.assertTrue(r1 < r3)
         self.assertFalse(r1 < r1)
         self.assertFalse(r1 < r2)
-        # python 2 only, cross-type compares will succeed
-        f1 < l3
-        f1 < l1
-        f1 < l2
+
+        with test_support.check_py3k_warnings():
+            # python 2 only, cross-type compares will succeed
+            f1 < l3
+            f1 < l1
+            f1 < l2
 
         # any subset
         self.assertTrue(f1 <= f3)
@@ -728,10 +731,12 @@
         self.assertTrue(r1 <= r3)
         self.assertTrue(r1 <= r1)
         self.assertFalse(r1 <= r2)
-        # python 2 only, cross-type compares will succeed
-        f1 <= l3
-        f1 <= l1
-        f1 <= l2
+
+        with test_support.check_py3k_warnings():
+            # python 2 only, cross-type compares will succeed
+            f1 <= l3
+            f1 <= l1
+            f1 <= l2
 
         # proper superset
         self.assertTrue(f3 > f1)
@@ -743,10 +748,12 @@
         self.assertTrue(r3 > r1)
         self.assertFalse(r1 > r1)
         self.assertFalse(r2 > r1)
-        # python 2 only, cross-type compares will succeed
-        f1 > l3
-        f1 > l1
-        f1 > l2
+
+        with test_support.check_py3k_warnings():
+            # python 2 only, cross-type compares will succeed
+            f1 > l3
+            f1 > l1
+            f1 > l2
 
         # any superset
         self.assertTrue(f3 >= f1)
@@ -758,10 +765,12 @@
         self.assertTrue(r3 >= r1)
         self.assertTrue(r1 >= r1)
         self.assertFalse(r2 >= r1)
-        # python 2 only, cross-type compares will succeed
-        f1 >= l3
-        f1 >=l1
-        f1 >= l2
+
+        with test_support.check_py3k_warnings():
+            # python 2 only, cross-type compares will succeed
+            f1 >= l3
+            f1 >=l1
+            f1 >= l2
 
         # equality
         self.assertTrue(f1 == f1)
diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py
--- a/Lib/test/test_hash.py
+++ b/Lib/test/test_hash.py
@@ -215,7 +215,8 @@
     repr_ = 'buffer("abc")'
 
     def test_empty_string(self):
-        self.assertEqual(hash(buffer("")), 0)
+        with test_support.check_py3k_warnings():
+            self.assertEqual(hash(buffer("")), 0)
 
 class DatetimeTests(HashRandomizationTests):
     def get_hash_command(self, repr_):
diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py
--- a/Lib/test/test_hmac.py
+++ b/Lib/test/test_hmac.py
@@ -389,10 +389,11 @@
         a, b = "fooä", "fooä"
         self.assertTrue(hmac.compare_digest(a, b))
 
-        # subclasses are supported by ignore __eq__
-        class mystr(str):
-            def __eq__(self, other):
-                return False
+        with test_support.check_py3k_warnings():
+            # subclasses are supported by ignore __eq__
+            class mystr(str):
+                def __eq__(self, other):
+                    return False
 
         a, b = mystr("foobar"), mystr("foobar")
         self.assertTrue(hmac.compare_digest(a, b))
@@ -401,9 +402,10 @@
         a, b = mystr("foobar"), mystr("foobaz")
         self.assertFalse(hmac.compare_digest(a, b))
 
-        class mybytes(bytes):
-            def __eq__(self, other):
-                return False
+        with test_support.check_py3k_warnings():
+            class mybytes(bytes):
+                def __eq__(self, other):
+                    return False
 
         a, b = mybytes(b"foobar"), mybytes(b"foobar")
         self.assertTrue(hmac.compare_digest(a, b))
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -2365,7 +2365,8 @@
             # now fetch the same data from the HTTPS server
             url = 'https://%s:%d/%s' % (
                 HOST, server.port, os.path.split(CERTFILE)[1])
-            f = urllib.urlopen(url)
+            with support.check_py3k_warnings():
+                f = urllib.urlopen(url)
             try:
                 dlen = f.info().getheader("content-length")
                 if dlen and (int(dlen) > 0):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list