Skip to content

Commit 8717c9b

Browse files
committed
Add tests for operator module.
1 parent 8af4712 commit 8717c9b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Lib/test/test_operator.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,30 @@ def __getitem__(self, other): return 5 # so that C is a sequence
474474
self.assertEqual(operator.ixor (c, 5), "ixor")
475475
self.assertEqual(operator.iconcat (c, c), "iadd")
476476

477+
def test_iconcat_without_getitem(self):
478+
operator = self.module
479+
class X: pass
480+
481+
msg = "'X' object can't be concatenated"
482+
with self.assertRaisesRegex(TypeError, msg):
483+
operator.iconcat(X(), X())
484+
485+
def test_index(self):
486+
operator = self.module
487+
class X:
488+
def __index__(self):
489+
return 1
490+
491+
self.assertEqual(operator.index(X()), 1)
492+
493+
def test_not_(self):
494+
operator = self.module
495+
class X:
496+
def __bool__(self):
497+
return False
498+
499+
self.assertEqual(operator.not_(X()), True)
500+
477501
def test_length_hint(self):
478502
operator = self.module
479503
class X(object):
@@ -499,6 +523,13 @@ def __length_hint__(self):
499523
with self.assertRaises(LookupError):
500524
operator.length_hint(X(LookupError))
501525

526+
class Y: pass
527+
528+
msg = "'str' object cannot be interpreted as an integer"
529+
with self.assertRaisesRegex(TypeError, msg):
530+
operator.length_hint(X(2), "abc")
531+
self.assertEqual(operator.length_hint(Y(), 10), 10)
532+
502533
def test_dunder_is_original(self):
503534
operator = self.module
504535

0 commit comments

Comments
 (0)