summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_operator.py
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2012-10-06 12:03:24 (GMT)
committerArmin Ronacher <armin.ronacher@active-4.com>2012-10-06 12:03:24 (GMT)
commitaa9a79d27958ae5afb6c8769a2b342d98677c091 (patch)
tree24d49f530111a345c57f053a7f40652fa51d27a3 /Lib/test/test_operator.py
parentef08fb1f040cb51e752c6b1322008714262fbf3e (diff)
downloadcpython-aa9a79d27958ae5afb6c8769a2b342d98677c091.zip
cpython-aa9a79d27958ae5afb6c8769a2b342d98677c091.tar.gz
cpython-aa9a79d27958ae5afb6c8769a2b342d98677c091.tar.bz2
Issue #16148: implemented PEP 424
Diffstat (limited to 'Lib/test/test_operator.py')
-rw-r--r--Lib/test/test_operator.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
index fa608b9..b445ee0 100644
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -410,6 +410,31 @@ class OperatorTestCase(unittest.TestCase):
self.assertEqual(operator.__ixor__ (c, 5), "ixor")
self.assertEqual(operator.__iconcat__ (c, c), "iadd")
+ def test_length_hint(self):
+ class X(object):
+ def __init__(self, value):
+ self.value = value
+
+ def __length_hint__(self):
+ if type(self.value) is type:
+ raise self.value
+ else:
+ return self.value
+
+ self.assertEqual(operator.length_hint([], 2), 0)
+ self.assertEqual(operator.length_hint(iter([1, 2, 3])), 3)
+
+ self.assertEqual(operator.length_hint(X(2)), 2)
+ self.assertEqual(operator.length_hint(X(NotImplemented), 4), 4)
+ self.assertEqual(operator.length_hint(X(TypeError), 12), 12)
+ with self.assertRaises(TypeError):
+ operator.length_hint(X("abc"))
+ with self.assertRaises(ValueError):
+ operator.length_hint(X(-2))
+ with self.assertRaises(LookupError):
+ operator.length_hint(X(LookupError))
+
+
def test_main(verbose=None):
import sys
test_classes = (