Back to index

python3.2  3.2.2
Public Member Functions
test.test_pep352.UsageTests Class Reference

List of all members.

Public Member Functions

def raise_fails
def catch_fails
def test_raise_new_style_non_exception
def test_raise_string
def test_catch_non_BaseException
def test_catch_BaseException_instance
def test_catch_string

Detailed Description

Test usage of exceptions

Definition at line 118 of file test_pep352.py.


Member Function Documentation

def test.test_pep352.UsageTests.catch_fails (   self,
  object_ 
)
Catching 'object_' should raise a TypeError.

Definition at line 130 of file test_pep352.py.

00130 
00131     def catch_fails(self, object_):
00132         """Catching 'object_' should raise a TypeError."""
00133         try:
00134             try:
00135                 raise Exception
00136             except object_:
00137                 pass
00138         except TypeError:
00139             pass
00140         except Exception:
00141             self.fail("TypeError expected when catching %s" % type(object_))
00142 
00143         try:
00144             try:
00145                 raise Exception
00146             except (object_,):
00147                 pass
00148         except TypeError:
00149             return
00150         except Exception:
00151             self.fail("TypeError expected when catching %s as specified in a "
00152                         "tuple" % type(object_))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_pep352.UsageTests.raise_fails (   self,
  object_ 
)
Make sure that raising 'object_' triggers a TypeError.

Definition at line 122 of file test_pep352.py.

00122 
00123     def raise_fails(self, object_):
00124         """Make sure that raising 'object_' triggers a TypeError."""
00125         try:
00126             raise object_
00127         except TypeError:
00128             return  # What is expected.
00129         self.fail("TypeError expected for raising %s" % type(object_))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 175 of file test_pep352.py.

00175 
00176     def test_catch_BaseException_instance(self):
00177         # Catching an instance of a BaseException subclass won't work.
00178         self.catch_fails(BaseException())

Here is the call graph for this function:

Definition at line 167 of file test_pep352.py.

00167 
00168     def test_catch_non_BaseException(self):
00169         # Tryinng to catch an object that does not inherit from BaseException
00170         # is not allowed.
00171         class NonBaseException(object):
00172             pass
00173         self.catch_fails(NonBaseException)
00174         self.catch_fails(NonBaseException())

Definition at line 179 of file test_pep352.py.

00179 
00180     def test_catch_string(self):
00181         # Catching a string is bad.
00182         self.catch_fails("spam")

Here is the call graph for this function:

Definition at line 153 of file test_pep352.py.

00153 
00154     def test_raise_new_style_non_exception(self):
00155         # You cannot raise a new-style class that does not inherit from
00156         # BaseException; the ability was not possible until BaseException's
00157         # introduction so no need to support new-style objects that do not
00158         # inherit from it.
00159         class NewStyleClass(object):
00160             pass
00161         self.raise_fails(NewStyleClass)
00162         self.raise_fails(NewStyleClass())

Definition at line 163 of file test_pep352.py.

00163 
00164     def test_raise_string(self):
00165         # Raising a string raises TypeError.
00166         self.raise_fails("spam")

Here is the call graph for this function:


The documentation for this class was generated from the following file: