diff options
author | Georg Brandl <georg@python.org> | 2008-02-23 23:04:35 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-02-23 23:04:35 (GMT) |
commit | ebcfd11c164d7783de183e40217a5fd39a2c891e (patch) | |
tree | 7f5eec1c9d075bd27d959c63de75201f2c8ab8f4 /Lib/test/test_operator.py | |
parent | e2065c65d345866f2f88f55e68c1135a167b2077 (diff) | |
download | cpython-ebcfd11c164d7783de183e40217a5fd39a2c891e.zip cpython-ebcfd11c164d7783de183e40217a5fd39a2c891e.tar.gz cpython-ebcfd11c164d7783de183e40217a5fd39a2c891e.tar.bz2 |
#1506171: added operator.methodcaller().
Diffstat (limited to 'Lib/test/test_operator.py')
-rw-r--r-- | Lib/test/test_operator.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index 3f3ea00..1c3fda3 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -440,6 +440,24 @@ class OperatorTestCase(unittest.TestCase): self.assertEqual(operator.itemgetter(2,10,5)(data), ('2', '10', '5')) self.assertRaises(TypeError, operator.itemgetter(2, 'x', 5), data) + def test_methodcaller(self): + self.assertRaises(TypeError, operator.methodcaller) + class A: + def foo(self, *args, **kwds): + return args[0] + args[1] + def bar(self, f=42): + return f + a = A() + f = operator.methodcaller('foo') + self.assertRaises(IndexError, f, a) + f = operator.methodcaller('foo', 1, 2) + self.assertEquals(f(a), 3) + f = operator.methodcaller('bar') + self.assertEquals(f(a), 42) + self.assertRaises(TypeError, f, a, a) + f = operator.methodcaller('bar', f=5) + self.assertEquals(f(a), 5) + def test_inplace(self): class C(object): def __iadd__ (self, other): return "iadd" |