diff options
author | Thomas Wouters <thomas@python.org> | 2007-02-23 20:24:22 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2007-02-23 20:24:22 (GMT) |
commit | fa353657f0da969eb6bc1cf62fb3c69dd036463a (patch) | |
tree | 2769a9368b55a79eee27fe488d0b0c24287b3eb3 /Lib/test/test_pep352.py | |
parent | 7ea15d091008f9297e03e2b8897f56aef1e2aa7d (diff) | |
download | cpython-fa353657f0da969eb6bc1cf62fb3c69dd036463a.zip cpython-fa353657f0da969eb6bc1cf62fb3c69dd036463a.tar.gz cpython-fa353657f0da969eb6bc1cf62fb3c69dd036463a.tar.bz2 |
Merged revisions 53859-53874 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53861 | neal.norwitz | 2007-02-23 01:22:39 +0100 (Fri, 23 Feb 2007) | 1 line
Fix typo in comment
........
r53864 | brett.cannon | 2007-02-23 15:28:25 +0100 (Fri, 23 Feb 2007) | 3 lines
Refactor PEP 352 tests to make it easier in the future to make sure certain
things cannot be raised or caught.
........
Diffstat (limited to 'Lib/test/test_pep352.py')
-rw-r--r-- | Lib/test/test_pep352.py | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py index 7f4a3dc..15f1101 100644 --- a/Lib/test/test_pep352.py +++ b/Lib/test/test_pep352.py @@ -113,6 +113,37 @@ class UsageTests(unittest.TestCase): """Test usage of exceptions""" + def raise_fails(self, object_): + """Make sure that raising 'object_' triggers a TypeError.""" + try: + raise object_ + except TypeError: + return # What is expected. + self.fail("TypeError expected for raising %s" % type(object_)) + + def catch_fails(self, object_): + """Catching 'object_' should raise a TypeError.""" + try: + try: + raise StandardError + except object_: + pass + except TypeError: + pass + except StandardError: + self.fail("TypeError expected when catching %s" % type(object_)) + + try: + try: + raise StandardError + except (object_,): + pass + except TypeError: + return + except StandardError: + self.fail("TypeError expected when catching %s as specified in a " + "tuple" % type(object_)) + def test_raise_new_style_non_exception(self): # You cannot raise a new-style class that does not inherit from # BaseException; the ability was not possible until BaseException's @@ -120,27 +151,12 @@ class UsageTests(unittest.TestCase): # inherit from it. class NewStyleClass(object): pass - try: - raise NewStyleClass - except TypeError: - pass - except: - self.fail("able to raise new-style class") - try: - raise NewStyleClass() - except TypeError: - pass - except: - self.fail("able to raise new-style class instance") + self.raise_fails(NewStyleClass) + self.raise_fails(NewStyleClass()) def test_raise_string(self): # Raising a string raises TypeError. - try: - raise "spam" - except TypeError: - pass - except: - self.fail("was able to raise a string exception") + self.raise_fails("spam") def test_catch_string(self): # Catching a string should trigger a DeprecationWarning. |