For Make Benefit Glorious Nation of Backwards Compatibility,

bytes objects can now be compared to anything that supports the buffer API.
This commit is contained in:
Guido van Rossum 2007-04-09 00:43:24 +00:00
parent 62cbc8a261
commit 343e97ff7f
2 changed files with 48 additions and 10 deletions

View file

@ -99,6 +99,21 @@ class BytesTest(unittest.TestCase):
self.failIf(b3 < b2)
self.failIf(b3 <= b2)
def test_compare_to_str(self):
self.assertEqual(b"abc" == "abc", True)
self.assertEqual(b"ab" != "abc", True)
self.assertEqual(b"ab" <= "abc", True)
self.assertEqual(b"ab" < "abc", True)
self.assertEqual(b"abc" >= "ab", True)
self.assertEqual(b"abc" > "ab", True)
self.assertEqual(b"abc" != "abc", False)
self.assertEqual(b"ab" == "abc", False)
self.assertEqual(b"ab" > "abc", False)
self.assertEqual(b"ab" >= "abc", False)
self.assertEqual(b"abc" < "ab", False)
self.assertEqual(b"abc" <= "ab", False)
def test_nohash(self):
self.assertRaises(TypeError, hash, bytes())