Kaydet (Commit) a3acea3e authored tarafından Victor Stinner's avatar Victor Stinner

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

üst 342fd18f
......@@ -163,7 +163,7 @@ class Get_entityTest(unittest.TestCase):
# 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)
......
......@@ -24,6 +24,7 @@
import unittest
import sys
import sqlite3 as sqlite
from test import test_support
try:
import threading
except ImportError:
......@@ -653,6 +654,7 @@ class ConstructorTests(unittest.TestCase):
ts = sqlite.TimestampFromTicks(42)
def CheckBinary(self):
with test_support.check_py3k_warnings():
b = sqlite.Binary(chr(0) + "'")
class ExtensionTests(unittest.TestCase):
......
......@@ -24,6 +24,7 @@
import datetime
import unittest
import sqlite3 as sqlite
from test import test_support
try:
import zlib
except ImportError:
......@@ -67,6 +68,7 @@ class SqliteTypeTests(unittest.TestCase):
self.assertEqual(row[0], val)
def CheckBlob(self):
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")
......@@ -231,6 +233,7 @@ class DeclTypesTests(unittest.TestCase):
def CheckBlob(self):
# default
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")
......@@ -347,6 +350,7 @@ class BinaryConverterTests(unittest.TestCase):
def CheckBinaryInputForConverter(self):
testdata = "abcdefg" * 10
with test_support.check_py3k_warnings():
result = self.con.execute('select ? as "x [bin]"', (buffer(zlib.compress(testdata)),)).fetchone()[0]
self.assertEqual(testdata, result)
......
......@@ -24,6 +24,7 @@
import unittest
import sqlite3 as sqlite
from test import test_support
def func_returntext():
return "foo"
......@@ -36,6 +37,7 @@ def func_returnfloat():
def func_returnnull():
return None
def func_returnblob():
with test_support.check_py3k_warnings():
return buffer("blob")
def func_returnlonglong():
return 1<<31
......@@ -202,6 +204,7 @@ class FunctionTests(unittest.TestCase):
cur = self.con.cursor()
cur.execute("select returnblob()")
val = cur.fetchone()[0]
with test_support.check_py3k_warnings():
self.assertEqual(type(val), buffer)
self.assertEqual(val, buffer("blob"))
......@@ -246,6 +249,7 @@ class FunctionTests(unittest.TestCase):
def CheckParamBlob(self):
cur = self.con.cursor()
with test_support.check_py3k_warnings():
cur.execute("select isblob(?)", (buffer("blob"),))
val = cur.fetchone()[0]
self.assertEqual(val, 1)
......@@ -269,6 +273,7 @@ class AggregateTests(unittest.TestCase):
b 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"),))
......@@ -362,6 +367,7 @@ class AggregateTests(unittest.TestCase):
def CheckAggrCheckParamBlob(self):
cur = self.con.cursor()
with test_support.check_py3k_warnings():
cur.execute("select checkType('blob', ?)", (buffer("blob"),))
val = cur.fetchone()[0]
self.assertEqual(val, 1)
......
......@@ -8,13 +8,14 @@ import pickle, cPickle, copy
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,6 +714,8 @@ class TestCollectionABCs(ABCTestCase):
self.assertTrue(r1 < r3)
self.assertFalse(r1 < r1)
self.assertFalse(r1 < r2)
with test_support.check_py3k_warnings():
# python 2 only, cross-type compares will succeed
f1 < l3
f1 < l1
......@@ -728,6 +731,8 @@ class TestCollectionABCs(ABCTestCase):
self.assertTrue(r1 <= r3)
self.assertTrue(r1 <= r1)
self.assertFalse(r1 <= r2)
with test_support.check_py3k_warnings():
# python 2 only, cross-type compares will succeed
f1 <= l3
f1 <= l1
......@@ -743,6 +748,8 @@ class TestCollectionABCs(ABCTestCase):
self.assertTrue(r3 > r1)
self.assertFalse(r1 > r1)
self.assertFalse(r2 > r1)
with test_support.check_py3k_warnings():
# python 2 only, cross-type compares will succeed
f1 > l3
f1 > l1
......@@ -758,6 +765,8 @@ class TestCollectionABCs(ABCTestCase):
self.assertTrue(r3 >= r1)
self.assertTrue(r1 >= r1)
self.assertFalse(r2 >= r1)
with test_support.check_py3k_warnings():
# python 2 only, cross-type compares will succeed
f1 >= l3
f1 >=l1
......
......@@ -215,6 +215,7 @@ class BufferHashRandomizationTests(StringlikeHashRandomizationTests):
repr_ = 'buffer("abc")'
def test_empty_string(self):
with test_support.check_py3k_warnings():
self.assertEqual(hash(buffer("")), 0)
class DatetimeTests(HashRandomizationTests):
......
......@@ -389,6 +389,7 @@ class CompareDigestTestCase(unittest.TestCase):
a, b = "fooä", "fooä"
self.assertTrue(hmac.compare_digest(a, b))
with test_support.check_py3k_warnings():
# subclasses are supported by ignore __eq__
class mystr(str):
def __eq__(self, other):
......@@ -401,6 +402,7 @@ class CompareDigestTestCase(unittest.TestCase):
a, b = mystr("foobar"), mystr("foobaz")
self.assertFalse(hmac.compare_digest(a, b))
with test_support.check_py3k_warnings():
class mybytes(bytes):
def __eq__(self, other):
return False
......
......@@ -2365,6 +2365,7 @@ else:
# now fetch the same data from the HTTPS server
url = 'https://%s:%d/%s' % (
HOST, server.port, os.path.split(CERTFILE)[1])
with support.check_py3k_warnings():
f = urllib.urlopen(url)
try:
dlen = f.info().getheader("content-length")
......
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