diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-01-07 16:38:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-07 16:38:41 (GMT) |
commit | 2d53bed79c1953390f85b191c72855e457e09305 (patch) | |
tree | df79f1a9e928b5883e6d26b8c579721becb47e1c /Lib/test/test_operator.py | |
parent | 3f7983a25a3d19779283c707fbdd5bc91b1587ef (diff) | |
download | cpython-2d53bed79c1953390f85b191c72855e457e09305.zip cpython-2d53bed79c1953390f85b191c72855e457e09305.tar.gz cpython-2d53bed79c1953390f85b191c72855e457e09305.tar.bz2 |
bpo-35664: Optimize operator.itemgetter (GH-11435)
Diffstat (limited to 'Lib/test/test_operator.py')
-rw-r--r-- | Lib/test/test_operator.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index 6254091..f46d94a 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -401,6 +401,19 @@ class OperatorTestCase: self.assertEqual(operator.itemgetter(2,10,5)(data), ('2', '10', '5')) self.assertRaises(TypeError, operator.itemgetter(2, 'x', 5), data) + # interesting indices + t = tuple('abcde') + self.assertEqual(operator.itemgetter(-1)(t), 'e') + self.assertEqual(operator.itemgetter(slice(2, 4))(t), ('c', 'd')) + + # interesting sequences + class T(tuple): + 'Tuple subclass' + pass + self.assertEqual(operator.itemgetter(0)(T('abc')), 'a') + self.assertEqual(operator.itemgetter(0)(['a', 'b', 'c']), 'a') + self.assertEqual(operator.itemgetter(0)(range(100, 200)), 100) + def test_methodcaller(self): operator = self.module self.assertRaises(TypeError, operator.methodcaller) |