]> granicus.if.org Git - python/commitdiff
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
authorTim Peters <tim.peters@gmail.com>
Sun, 2 Mar 2003 00:36:10 +0000 (00:36 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 2 Mar 2003 00:36:10 +0000 (00:36 +0000)
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.

Lib/test/test_sets.py

index f1bd3b8ac29c5d1fe660de405dac6adaaa52f3d8..d5c886a72801e37cfe944c64a2963a6290fbe965 100644 (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)
 
 #------------------------------------------------------------------------------