TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using

assertRaises.  Fixed a repeated subtle bug in the inplace tests by
removing the possibilty that a self.fail() call could raise a
TypeError that the test catches by mistake.
This commit is contained in:
Tim Peters 2003-03-02 00:36:10 +00:00
parent b7bfe4bea4
commit 6cca754c20
1 changed files with 16 additions and 44 deletions

View File

@ -506,78 +506,50 @@ class TestOnlySetsInBinaryOps(unittest.TestCase):
def test_union_update(self):
try:
self.set |= self.other
self.fail("expected TypeError")
except TypeError:
pass
else:
self.fail("expected TypeError")
def test_union(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
self.assertRaises(TypeError, lambda: self.set | self.other)
self.assertRaises(TypeError, lambda: self.other | self.set)
def test_intersection_update(self):
try:
self.set &= self.other
self.fail("expected TypeError")
except TypeError:
pass
else:
self.fail("expected TypeError")
def test_intersection(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
self.assertRaises(TypeError, lambda: self.set & self.other)
self.assertRaises(TypeError, lambda: self.other & self.set)
def test_sym_difference_update(self):
try:
self.set ^= self.other
self.fail("expected TypeError")
except TypeError:
pass
else:
self.fail("expected TypeError")
def test_sym_difference(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
self.assertRaises(TypeError, lambda: self.set ^ self.other)
self.assertRaises(TypeError, lambda: self.other ^ self.set)
def test_difference_update(self):
try:
self.set -= self.other
self.fail("expected TypeError")
except TypeError:
pass
else:
self.fail("expected TypeError")
def test_difference(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
self.assertRaises(TypeError, lambda: self.set - self.other)
self.assertRaises(TypeError, lambda: self.other - self.set)
#------------------------------------------------------------------------------