Commit a3acea3e authored by Victor Stinner's avatar Victor Stinner

Issue #22340: Fix Python 3 warnings in Python 2 tests

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