Issue #23681: The -b option now affects comparisons of bytes with int.

This commit is contained in:
Serhiy Storchaka 2015-03-20 16:54:57 +02:00
parent ee4c0b9dcf
commit 1dd49824df
5 changed files with 53 additions and 22 deletions

View file

@ -1338,20 +1338,35 @@ class AssortedBytesTest(unittest.TestCase):
b = bytearray()
self.assertFalse(b.replace(b'', b'') is b)
@unittest.skipUnless(sys.flags.bytes_warning,
"BytesWarning is needed for this test: use -bb option")
def test_compare(self):
if sys.flags.bytes_warning:
def bytes_warning():
return test.support.check_warnings(('', BytesWarning))
with bytes_warning():
b'' == ''
with bytes_warning():
b'' != ''
with bytes_warning():
bytearray(b'') == ''
with bytes_warning():
bytearray(b'') != ''
else:
self.skipTest("BytesWarning is needed for this test: use -bb option")
def bytes_warning():
return test.support.check_warnings(('', BytesWarning))
with bytes_warning():
b'' == ''
with bytes_warning():
'' == b''
with bytes_warning():
b'' != ''
with bytes_warning():
'' != b''
with bytes_warning():
bytearray(b'') == ''
with bytes_warning():
'' == bytearray(b'')
with bytes_warning():
bytearray(b'') != ''
with bytes_warning():
'' != bytearray(b'')
with bytes_warning():
b'\0' == 0
with bytes_warning():
0 == b'\0'
with bytes_warning():
b'\0' != 0
with bytes_warning():
0 != b'\0'
# Optimizations:
# __iter__? (optimization)