Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_pep352.ExceptionClassTests Class Reference

List of all members.

Public Member Functions

def test_builtins_new_style
def verify_instance_interface
def test_inheritance
def interface_test_driver
def test_interface_single_arg
def test_interface_multi_arg
def test_interface_no_arg

Static Public Attributes

tuple interface_tests = ("length", "args", "str", "repr")

Detailed Description

Tests for anything relating to exception objects themselves (e.g.,
inheritance hierarchy)

Definition at line 9 of file test_pep352.py.


Member Function Documentation

Definition at line 86 of file test_pep352.py.

00086 
00087     def interface_test_driver(self, results):
00088         for test_name, (given, expected) in zip(self.interface_tests, results):
00089             self.assertEqual(given, expected, "%s: %s != %s" % (test_name,
00090                 given, expected))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 14 of file test_pep352.py.

00014 
00015     def test_builtins_new_style(self):
00016         self.assertTrue(issubclass(Exception, object))

Here is the call graph for this function:

Definition at line 23 of file test_pep352.py.

00023 
00024     def test_inheritance(self):
00025         # Make sure the inheritance hierarchy matches the documentation
00026         exc_set = set()
00027         for object_ in builtins.__dict__.values():
00028             try:
00029                 if issubclass(object_, BaseException):
00030                     exc_set.add(object_.__name__)
00031             except TypeError:
00032                 pass
00033 
00034         inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
00035                                                 'exception_hierarchy.txt'))
00036         try:
00037             superclass_name = inheritance_tree.readline().rstrip()
00038             try:
00039                 last_exc = getattr(builtins, superclass_name)
00040             except AttributeError:
00041                 self.fail("base class %s not a built-in" % superclass_name)
00042             self.assertIn(superclass_name, exc_set,
00043                           '%s not found' % superclass_name)
00044             exc_set.discard(superclass_name)
00045             superclasses = []  # Loop will insert base exception
00046             last_depth = 0
00047             for exc_line in inheritance_tree:
00048                 exc_line = exc_line.rstrip()
00049                 depth = exc_line.rindex('-')
00050                 exc_name = exc_line[depth+2:]  # Slice past space
00051                 if '(' in exc_name:
00052                     paren_index = exc_name.index('(')
00053                     platform_name = exc_name[paren_index+1:-1]
00054                     exc_name = exc_name[:paren_index-1]  # Slice off space
00055                     if platform_system() != platform_name:
00056                         exc_set.discard(exc_name)
00057                         continue
00058                 if '[' in exc_name:
00059                     left_bracket = exc_name.index('[')
00060                     exc_name = exc_name[:left_bracket-1]  # cover space
00061                 try:
00062                     exc = getattr(builtins, exc_name)
00063                 except AttributeError:
00064                     self.fail("%s not a built-in exception" % exc_name)
00065                 if last_depth < depth:
00066                     superclasses.append((last_depth, last_exc))
00067                 elif last_depth > depth:
00068                     while superclasses[-1][0] >= depth:
00069                         superclasses.pop()
00070                 self.assertTrue(issubclass(exc, superclasses[-1][1]),
00071                 "%s is not a subclass of %s" % (exc.__name__,
00072                     superclasses[-1][1].__name__))
00073                 try:  # Some exceptions require arguments; just skip them
00074                     self.verify_instance_interface(exc())
00075                 except TypeError:
00076                     pass
00077                 self.assertIn(exc_name, exc_set)
00078                 exc_set.discard(exc_name)
00079                 last_exc = exc
00080                 last_depth = depth
00081         finally:
00082             inheritance_tree.close()
00083         self.assertEqual(len(exc_set), 0, "%s not accounted for" % exc_set)

Here is the call graph for this function:

Definition at line 100 of file test_pep352.py.

00100 
00101     def test_interface_multi_arg(self):
00102         # Make sure interface correct when multiple arguments given
00103         arg_count = 3
00104         args = tuple(range(arg_count))
00105         exc = Exception(*args)
00106         results = ([len(exc.args), arg_count], [exc.args, args],
00107                 [str(exc), str(args)],
00108                 [repr(exc), exc.__class__.__name__ + repr(exc.args)])
00109         self.interface_test_driver(results)

Here is the call graph for this function:

Definition at line 110 of file test_pep352.py.

00110 
00111     def test_interface_no_arg(self):
00112         # Make sure that with no args that interface is correct
00113         exc = Exception()
00114         results = ([len(exc.args), 0], [exc.args, tuple()],
00115                 [str(exc), ''],
00116                 [repr(exc), exc.__class__.__name__ + '()'])
00117         self.interface_test_driver(results)

Here is the call graph for this function:

Definition at line 91 of file test_pep352.py.

00091 
00092     def test_interface_single_arg(self):
00093         # Make sure interface works properly when given a single argument
00094         arg = "spam"
00095         exc = Exception(arg)
00096         results = ([len(exc.args), 1], [exc.args[0], arg],
00097                    [str(exc), str(arg)],
00098             [repr(exc), exc.__class__.__name__ + repr(exc.args)])
00099         self.interface_test_driver(results)

Here is the call graph for this function:

Definition at line 17 of file test_pep352.py.

00017 
00018     def verify_instance_interface(self, ins):
00019         for attr in ("args", "__str__", "__repr__"):
00020             self.assertTrue(hasattr(ins, attr),
00021                     "%s missing %s attribute" %
00022                         (ins.__class__.__name__, attr))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tuple test.test_pep352.ExceptionClassTests.interface_tests = ("length", "args", "str", "repr") [static]

Definition at line 84 of file test_pep352.py.


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