summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_operator.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-01-07 16:38:41 (GMT)
committerGitHub <noreply@github.com>2019-01-07 16:38:41 (GMT)
commit2d53bed79c1953390f85b191c72855e457e09305 (patch)
treedf79f1a9e928b5883e6d26b8c579721becb47e1c /Lib/test/test_operator.py
parent3f7983a25a3d19779283c707fbdd5bc91b1587ef (diff)
downloadcpython-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.py13
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)