Back to index

python3.2  3.2.2
Public Member Functions
test.test_richcmp.MiscTest Class Reference

List of all members.

Public Member Functions

def test_misbehavin
def test_not
def test_recursion

Detailed Description

Definition at line 191 of file test_richcmp.py.


Member Function Documentation

Definition at line 193 of file test_richcmp.py.

00193 
00194     def test_misbehavin(self):
00195         class Misb:
00196             def __lt__(self_, other): return 0
00197             def __gt__(self_, other): return 0
00198             def __eq__(self_, other): return 0
00199             def __le__(self_, other): self.fail("This shouldn't happen")
00200             def __ge__(self_, other): self.fail("This shouldn't happen")
00201             def __ne__(self_, other): self.fail("This shouldn't happen")
00202         a = Misb()
00203         b = Misb()
00204         self.assertEqual(a<b, 0)
00205         self.assertEqual(a==b, 0)
00206         self.assertEqual(a>b, 0)

Here is the call graph for this function:

Definition at line 207 of file test_richcmp.py.

00207 
00208     def test_not(self):
00209         # Check that exceptions in __bool__ are properly
00210         # propagated by the not operator
00211         import operator
00212         class Exc(Exception):
00213             pass
00214         class Bad:
00215             def __bool__(self):
00216                 raise Exc
00217 
00218         def do(bad):
00219             not bad
00220 
00221         for func in (do, operator.not_):
00222             self.assertRaises(Exc, func, Bad())

Definition at line 223 of file test_richcmp.py.

00223 
00224     def test_recursion(self):
00225         # Check that comparison for recursive objects fails gracefully
00226         from collections import UserList
00227         a = UserList()
00228         b = UserList()
00229         a.append(b)
00230         b.append(a)
00231         self.assertRaises(RuntimeError, operator.eq, a, b)
00232         self.assertRaises(RuntimeError, operator.ne, a, b)
00233         self.assertRaises(RuntimeError, operator.lt, a, b)
00234         self.assertRaises(RuntimeError, operator.le, a, b)
00235         self.assertRaises(RuntimeError, operator.gt, a, b)
00236         self.assertRaises(RuntimeError, operator.ge, a, b)
00237 
00238         b.append(17)
00239         # Even recursive lists of different lengths are different,
00240         # but they cannot be ordered
00241         self.assertTrue(not (a == b))
00242         self.assertTrue(a != b)
00243         self.assertRaises(RuntimeError, operator.lt, a, b)
00244         self.assertRaises(RuntimeError, operator.le, a, b)
00245         self.assertRaises(RuntimeError, operator.gt, a, b)
00246         self.assertRaises(RuntimeError, operator.ge, a, b)
00247         a.append(17)
00248         self.assertRaises(RuntimeError, operator.eq, a, b)
00249         self.assertRaises(RuntimeError, operator.ne, a, b)
00250         a.insert(0, 11)
00251         b.insert(0, 12)
00252         self.assertTrue(not (a == b))
00253         self.assertTrue(a != b)
00254         self.assertTrue(a < b)

Here is the call graph for this function:


The documentation for this class was generated from the following file: