From 5e61e24d5527246e1602ce6ad428248f5f4eda94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Tue, 4 Feb 2003 17:04:01 +0000 Subject: 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. --- Lib/test/test_builtin.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) -- cgit v0.12