mirror of https://github.com/python/cpython
Add a test that checks that filter() honors the sq_item slot for
str and unicode subclasses not just for generating the output but for testing too.
This commit is contained in:
parent
531e000d2e
commit
5e61e24d55
|
@ -377,6 +377,11 @@ class BuiltinTest(unittest.TestCase):
|
|||
return weirdstr(2*str.__getitem__(self, index))
|
||||
self.assertEqual(filter(lambda x: x>="33", weirdstr("1234")), "3344")
|
||||
|
||||
class shiftstr(str):
|
||||
def __getitem__(self, index):
|
||||
return chr(ord(str.__getitem__(self, index))+1)
|
||||
self.assertEqual(filter(lambda x: x>="3", shiftstr("1234")), "345")
|
||||
|
||||
if have_unicode:
|
||||
# test bltinmodule.c::filterunicode()
|
||||
self.assertEqual(filter(None, unicode("12")), unicode("12"))
|
||||
|
@ -395,6 +400,14 @@ class BuiltinTest(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
filter(lambda x: x>=unicode("33"), weirdunicode("1234")), unicode("3344"))
|
||||
|
||||
class shiftunicode(unicode):
|
||||
def __getitem__(self, index):
|
||||
return unichr(ord(unicode.__getitem__(self, index))+1)
|
||||
self.assertEqual(
|
||||
filter(lambda x: x>=unicode("3"), shiftunicode("1234")),
|
||||
unicode("345")
|
||||
)
|
||||
|
||||
def test_float(self):
|
||||
self.assertEqual(float(3.14), 3.14)
|
||||
self.assertEqual(float(314), 314.0)
|
||||
|
|
Loading…
Reference in New Issue