diff options
author | Georg Brandl <georg@python.org> | 2008-02-23 23:02:23 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-02-23 23:02:23 +0000 |
commit | e2065c65d345866f2f88f55e68c1135a167b2077 (patch) | |
tree | 5faf4eeb488e0ee807a86ff702692a41e5fb36d4 /Lib/test | |
parent | b0b0317ba2d46ba38973a4c4cf24f6dec054ca38 (diff) | |
download | cpython-git-e2065c65d345866f2f88f55e68c1135a167b2077.tar.gz |
#1826: allow dotted attribute paths in operator.attrgetter.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_operator.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index a60ceb609e..3f3ea0033e 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -386,6 +386,26 @@ class OperatorTestCase(unittest.TestCase): raise SyntaxError self.failUnlessRaises(SyntaxError, operator.attrgetter('foo'), C()) + # recursive gets + a = A() + a.name = 'arthur' + a.child = A() + a.child.name = 'thomas' + f = operator.attrgetter('child.name') + self.assertEqual(f(a), 'thomas') + self.assertRaises(AttributeError, f, a.child) + f = operator.attrgetter('name', 'child.name') + self.assertEqual(f(a), ('arthur', 'thomas')) + f = operator.attrgetter('name', 'child.name', 'child.child.name') + self.assertRaises(AttributeError, f, a) + + a.child.child = A() + a.child.child.name = 'johnson' + f = operator.attrgetter('child.child.name') + self.assertEqual(f(a), 'johnson') + f = operator.attrgetter('name', 'child.name', 'child.child.name') + self.assertEqual(f(a), ('arthur', 'thomas', 'johnson')) + def test_itemgetter(self): a = 'ABCDE' f = operator.itemgetter(2) |