Issue #22340: Fix Python 3 warnings in Python 2 tests
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index de4ba86..6c9c407 100644
--- 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
index dec7dcb..c4f7c66 100644
--- 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
index 839d019..8f639a3 100644
--- 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
index 351925e..eac994f 100644
--- 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):