Skip to content

Commit

Permalink
Test operator.index with int, float, Fraction, Decimal, None
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 24, 2024
1 parent a0279ee commit 0341f65
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Lib/test/test_operator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest
import pickle
import sys
from decimal import Decimal
from fractions import Fraction

from test import support
from test.support import import_helper
Expand Down Expand Up @@ -522,6 +524,17 @@ def __index__(self):
return 1

self.assertEqual(operator.index(X()), 1)
self.assertEqual(operator.index(0), 0)
self.assertEqual(operator.index(1), 1)
self.assertEqual(operator.index(2), 2)
with self.assertRaises((AttributeError, TypeError)):
operator.index(1.5)
with self.assertRaises((AttributeError, TypeError)):
operator.index(Fraction(3, 7))
with self.assertRaises((AttributeError, TypeError)):
operator.index(Decimal(1))
with self.assertRaises((AttributeError, TypeError)):
operator.index(None)

def test_not_(self):
operator = self.module
Expand Down

0 comments on commit 0341f65

Please sign in to comment.