[Python-checkins] r46251 - python/branches/sreifschneider-newnewexcept/Lib/test/test_exceptions.py

Brett Cannon brett at python.org
Thu May 25 22:35:25 CEST 2006


This is actually unneeded; see test_pep352.py for the test of the
hierarchy.  it reads Lib/test/exception_hierarchy.txt and checks that the
hierarchy in that file matches what is in Python.

-Brett

On 5/25/06, sean.reifschneider <python-checkins at python.org> wrote:
>
> Author: sean.reifschneider
> Date: Thu May 25 22:21:20 2006
> New Revision: 46251
>
> Modified:
>    python/branches/sreifschneider-newnewexcept/Lib/test/test_exceptions.py
> Log:
> Adding Exception heirarchy test.
>
>
> Modified:
> python/branches/sreifschneider-newnewexcept/Lib/test/test_exceptions.py
>
> ==============================================================================
> ---
> python/branches/sreifschneider-newnewexcept/Lib/test/test_exceptions.py
> (original)
> +++
> python/branches/sreifschneider-newnewexcept/Lib/test/test_exceptions.py
> Thu May 25 22:21:20 2006
> @@ -247,7 +247,7 @@
>                      'print_file_and_line' : None, 'msg' : 'msgStr',
>                      'filename' : None, 'lineno' : None, 'offset' : None,
>                      'text' : None }),
> -        ( UnicodeError, ( ),
> +        ( UnicodeError, (),
>                  { 'message' : '', 'args' : (), }),
>          ( sampleUnicodeEncodeError,
>                  { 'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7,
> @@ -286,3 +286,70 @@
>                          ( repr(e), checkArgName,
>                              repr(expected[checkArgName]),
>                              repr(getattr(e, checkArgName)) ))
> +
> +
> +#  test exception heirarchy
> +osErrorChildren = []
> +try: osErrorChildren.append(VMSError)
> +except: pass
> +try: osErrorChildren.append(WindowsError)
> +except: pass
> +osErrorChildren = tuple(osErrorChildren)
> +exceptionHeirarchy = \
> +    ( SystemExit,
> +    KeyboardInterrupt,
> +    Exception,
> +       (  GeneratorExit,
> +        StopIteration,
> +        StandardError,
> +            ( ArithmeticError,
> +                ( FloatingPointError,
> +                OverflowError,
> +                ZeroDivisionError, ),
> +            AssertionError,
> +            AttributeError,
> +            EnvironmentError,
> +                ( IOError,
> +                OSError,
> +                    osErrorChildren, ),
> +            EOFError,
> +            ImportError,
> +            LookupError,
> +                ( IndexError,
> +                KeyError, ),
> +            MemoryError,
> +            NameError,
> +                ( UnboundLocalError, ),
> +            ReferenceError,
> +            RuntimeError,
> +                ( NotImplementedError, ),
> +            SyntaxError,
> +                ( IndentationError,
> +                    ( TabError, ), ),
> +            SystemError,
> +            TypeError,
> +            ValueError,
> +                ( UnicodeError,
> +                    ( UnicodeDecodeError,
> +                    UnicodeEncodeError,
> +                    UnicodeTranslateError, ), ), ),
> +        Warning,
> +            ( DeprecationWarning,
> +            PendingDeprecationWarning,
> +            RuntimeWarning,
> +            SyntaxWarning,
> +            UserWarning,
> +            FutureWarning,
> +            OverflowWarning,
> +            ImportWarning, ), ), )
> +def checkChildren(parent, children):
> +    lastChild = None
> +    for child in children:
> +        if type(child) == type(tuple()):
> +            checkChildren(lastChild, child)
> +        else:
> +            if not issubclass(child, parent):
> +                raise TestFailed('Exception "%s" is not a subclass of
> "%s"'
> +                        % ( repr(child), repr(parent) ))
> +        lastChild = child
> +checkChildren(BaseException, exceptionHeirarchy)
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-checkins/attachments/20060525/a244cc02/attachment.html 


More information about the Python-checkins mailing list