[Python-checkins] python/dist/src/Lib/test test_sets.py,1.20,1.21
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sat, 01 Mar 2003 16:19:51 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv24329/Lib/test
Modified Files:
test_sets.py
Log Message:
SF bug 693121: Set == non-Set is a TypeError.
Allow mixed-type __eq__ and __ne__ for Set objects. This is messier than
I'd like because Set *also* implements __cmp__. I know of one glitch now:
cmp(s, t) returns 0 now when s and t are both Sets and s == t, despite
that Set.__cmp__ unconditionally raises TypeError (and by intent). The
rub is that __eq__ gets tried first, and the x.__eq__(y) True result
convinces Python that cmp(x, y) is 0 without even calling Set.__cmp__.
Index: test_sets.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sets.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** test_sets.py 1 Mar 2003 23:33:34 -0000 1.20
--- test_sets.py 2 Mar 2003 00:19:49 -0000 1.21
***************
*** 233,237 ****
def test_cmp(self):
a, b = Set('a'), Set('b')
! self.assertRaises(TypeError, cmp, (a,b))
#==============================================================================
--- 233,246 ----
def test_cmp(self):
a, b = Set('a'), Set('b')
! self.assertRaises(TypeError, cmp, a, b)
!
! # You can view this as a buglet: cmp(a, a) does not raise TypeError,
! # because __eq__ is tried before __cmp__, and a.__eq__(a) returns,
! # which Python thinks is good enough to synthesize a cmp() result
! # without calling __cmp__.
! self.assertEqual(cmp(a, a), 0)
!
! self.assertRaises(TypeError, cmp, a, 12)
! self.assertRaises(TypeError, cmp, "abc", a)
#==============================================================================
***************
*** 477,491 ****
class TestOnlySetsInBinaryOps(unittest.TestCase):
! def test_cmp(self):
! try:
! self.other == self.set
! self.fail("expected TypeError")
! except TypeError:
! pass
! try:
! self.set != self.other
! self.fail("expected TypeError")
! except TypeError:
! pass
def test_union_update(self):
--- 486,502 ----
class TestOnlySetsInBinaryOps(unittest.TestCase):
! def test_eq_ne(self):
! # Unlike the others, this is testing that == and != *are* allowed.
! self.assertEqual(self.other == self.set, False)
! self.assertEqual(self.set == self.other, False)
! self.assertEqual(self.other != self.set, True)
! self.assertEqual(self.set != self.other, True)
!
! def test_ge_gt_lt_le(self):
! # Unlike the others, this is testing that == and != *are* allowed.
! self.assertRaises(TypeError, lambda: self.set < self.other)
! self.assertRaises(TypeError, lambda: self.set <= self.other)
! self.assertRaises(TypeError, lambda: self.set > self.other)
! self.assertRaises(TypeError, lambda: self.set >= self.other)
def test_union_update(self):