[Python-checkins] r46251 - python/branches/sreifschneider-newnewexcept/Lib/test/test_exceptions.py
sean.reifschneider
python-checkins at python.org
Thu May 25 22:21:21 CEST 2006
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)
More information about the Python-checkins
mailing list