mirror of
https://github.com/python/cpython.git
synced 2025-12-05 00:52:25 +00:00
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
1 changed files with 13 additions and 0 deletions
|
|
@ -377,6 +377,11 @@ class BuiltinTest(unittest.TestCase):
|
||||||
return weirdstr(2*str.__getitem__(self, index))
|
return weirdstr(2*str.__getitem__(self, index))
|
||||||
self.assertEqual(filter(lambda x: x>="33", weirdstr("1234")), "3344")
|
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:
|
if have_unicode:
|
||||||
# test bltinmodule.c::filterunicode()
|
# test bltinmodule.c::filterunicode()
|
||||||
self.assertEqual(filter(None, unicode("12")), unicode("12"))
|
self.assertEqual(filter(None, unicode("12")), unicode("12"))
|
||||||
|
|
@ -395,6 +400,14 @@ class BuiltinTest(unittest.TestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
filter(lambda x: x>=unicode("33"), weirdunicode("1234")), unicode("3344"))
|
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):
|
def test_float(self):
|
||||||
self.assertEqual(float(3.14), 3.14)
|
self.assertEqual(float(3.14), 3.14)
|
||||||
self.assertEqual(float(314), 314.0)
|
self.assertEqual(float(314), 314.0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue