diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-03-02 00:36:10 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-03-02 00:36:10 (GMT) |
commit | 6cca754c2085e4eb203855b7d67df4a11ff0f534 (patch) | |
tree | 43b8c7b16517b54587024e2d6c1abe610017feed /Lib/test | |
parent | b7bfe4bea458a4a934ac12214e1a403eca1ce7ac (diff) | |
download | cpython-6cca754c2085e4eb203855b7d67df4a11ff0f534.zip cpython-6cca754c2085e4eb203855b7d67df4a11ff0f534.tar.gz cpython-6cca754c2085e4eb203855b7d67df4a11ff0f534.tar.bz2 |
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.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_sets.py | 60 |
1 files changed, 16 insertions, 44 deletions
diff --git a/Lib/test/test_sets.py b/Lib/test/test_sets.py index f1bd3b8..d5c886a 100644 --- a/Lib/test/test_sets.py +++ b/Lib/test/test_sets.py @@ -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) #------------------------------------------------------------------------------ |