summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2003-02-04 17:04:01 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2003-02-04 17:04:01 (GMT)
commit5e61e24d5527246e1602ce6ad428248f5f4eda94 (patch)
treedefb4d8b7048f7a741eccc73dea707f7920c1d1c /Lib/test/test_builtin.py
parent531e000d2e6c15b7a83018d8c663770c012ee98e (diff)
downloadcpython-5e61e24d5527246e1602ce6ad428248f5f4eda94.zip
cpython-5e61e24d5527246e1602ce6ad428248f5f4eda94.tar.gz
cpython-5e61e24d5527246e1602ce6ad428248f5f4eda94.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 6e13050..2b0c017 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -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)