mirror of
https://github.com/python/cpython.git
synced 2025-09-28 03:13:48 +00:00
Clean up warnings filter use in test_bytes.
This commit is contained in:
parent
776289934c
commit
41a08bcb83
1 changed files with 41 additions and 42 deletions
|
@ -27,12 +27,6 @@ class Indexable:
|
|||
|
||||
class BaseBytesTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.warning_filters = warnings.filters[:]
|
||||
|
||||
def tearDown(self):
|
||||
warnings.filters = self.warning_filters
|
||||
|
||||
def test_basics(self):
|
||||
b = self.type2test()
|
||||
self.assertEqual(type(b), self.type2test)
|
||||
|
@ -127,13 +121,17 @@ class BaseBytesTest(unittest.TestCase):
|
|||
self.assertFalse(b3 <= b2)
|
||||
|
||||
def test_compare_to_str(self):
|
||||
with test.support.check_warnings():
|
||||
warnings.simplefilter('ignore', BytesWarning)
|
||||
# Byte comparisons with unicode should always fail!
|
||||
# Test this for all expected byte orders and Unicode character sizes
|
||||
# Test this for all expected byte orders and Unicode character
|
||||
# sizes.
|
||||
self.assertEqual(self.type2test(b"\0a\0b\0c") == "abc", False)
|
||||
self.assertEqual(self.type2test(b"\0\0\0a\0\0\0b\0\0\0c") == "abc", False)
|
||||
self.assertEqual(self.type2test(b"\0\0\0a\0\0\0b\0\0\0c") == "abc",
|
||||
False)
|
||||
self.assertEqual(self.type2test(b"a\0b\0c\0") == "abc", False)
|
||||
self.assertEqual(self.type2test(b"a\0\0\0b\0\0\0c\0\0\0") == "abc", False)
|
||||
self.assertEqual(self.type2test(b"a\0\0\0b\0\0\0c\0\0\0") == "abc",
|
||||
False)
|
||||
self.assertEqual(self.type2test() == str(), False)
|
||||
self.assertEqual(self.type2test() != str(), True)
|
||||
|
||||
|
@ -829,13 +827,8 @@ class AssortedBytesTest(unittest.TestCase):
|
|||
# Test various combinations of bytes and bytearray
|
||||
#
|
||||
|
||||
def setUp(self):
|
||||
self.warning_filters = warnings.filters[:]
|
||||
|
||||
def tearDown(self):
|
||||
warnings.filters = self.warning_filters
|
||||
|
||||
def test_repr_str(self):
|
||||
with test.support.check_warnings():
|
||||
warnings.simplefilter('ignore', BytesWarning)
|
||||
for f in str, repr:
|
||||
self.assertEqual(f(bytearray()), "bytearray(b'')")
|
||||
|
@ -888,6 +881,7 @@ class AssortedBytesTest(unittest.TestCase):
|
|||
self.assertEqual(b, bytearray(sample))
|
||||
|
||||
def test_to_str(self):
|
||||
with test.support.check_warnings():
|
||||
warnings.simplefilter('ignore', BytesWarning)
|
||||
self.assertEqual(str(b''), "b''")
|
||||
self.assertEqual(str(b'x'), "b'x'")
|
||||
|
@ -940,11 +934,16 @@ class AssortedBytesTest(unittest.TestCase):
|
|||
|
||||
def test_compare(self):
|
||||
if sys.flags.bytes_warning:
|
||||
with test.support.check_warnings():
|
||||
warnings.simplefilter('error', BytesWarning)
|
||||
self.assertRaises(BytesWarning, operator.eq, b'', '')
|
||||
self.assertRaises(BytesWarning, operator.ne, b'', '')
|
||||
self.assertRaises(BytesWarning, operator.eq, bytearray(b''), '')
|
||||
self.assertRaises(BytesWarning, operator.ne, bytearray(b''), '')
|
||||
with self.assertRaises(BytesWarning):
|
||||
b'' == ''
|
||||
with self.assertRaises(BytesWarning):
|
||||
b'' != ''
|
||||
with self.assertRaises(BytesWarning):
|
||||
bytearray(b'') == ''
|
||||
with self.assertRaises(BytesWarning):
|
||||
bytearray(b'') != ''
|
||||
else:
|
||||
# self.skipTest("BytesWarning is needed for this test: use -bb option")
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue