Back to index

python3.2  3.2.2
Public Member Functions
test.test_traceback.CExcReportingTests Class Reference
Inheritance diagram for test.test_traceback.CExcReportingTests:
Inheritance graph
[legend]
Collaboration diagram for test.test_traceback.CExcReportingTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def get_report
def get_exception
def zero_div
def check_zero_div
def test_simple
def test_cause
def test_context
def test_cause_and_context
def test_cause_recursive
def test_syntax_error_offset_at_eol

Detailed Description

Definition at line 320 of file test_traceback.py.


Member Function Documentation

Definition at line 203 of file test_traceback.py.

00203 
00204     def check_zero_div(self, msg):
00205         lines = msg.splitlines()
00206         self.assertTrue(lines[-3].startswith('  File'))
00207         self.assertIn('1/0 # In zero_div', lines[-2])
00208         self.assertTrue(lines[-1].startswith('ZeroDivisionError'), lines[-1])

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_traceback.BaseExceptionReportingTests.get_exception (   self,
  exception_or_callable 
) [inherited]

Definition at line 192 of file test_traceback.py.

00192 
00193     def get_exception(self, exception_or_callable):
00194         if isinstance(exception_or_callable, Exception):
00195             return exception_or_callable
00196         try:
00197             exception_or_callable()
00198         except Exception as e:
00199             return e

Here is the caller graph for this function:

Definition at line 325 of file test_traceback.py.

00325 
00326     def get_report(self, e):
00327         e = self.get_exception(e)
00328         with captured_output("stderr") as s:
00329             exception_print(e)
00330         return s.getvalue()
00331 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 221 of file test_traceback.py.

00221 
00222     def test_cause(self):
00223         def inner_raise():
00224             try:
00225                 self.zero_div()
00226             except ZeroDivisionError as e:
00227                 raise KeyError from e
00228         def outer_raise():
00229             inner_raise() # Marker
00230         blocks = boundaries.split(self.get_report(outer_raise))
00231         self.assertEqual(len(blocks), 3)
00232         self.assertEqual(blocks[1], cause_message)
00233         self.check_zero_div(blocks[0])
00234         self.assertIn('inner_raise() # Marker', blocks[2])

Here is the call graph for this function:

Definition at line 249 of file test_traceback.py.

00249 
00250     def test_cause_and_context(self):
00251         # When both a cause and a context are set, only the cause should be
00252         # displayed and the context should be muted.
00253         def inner_raise():
00254             try:
00255                 self.zero_div()
00256             except ZeroDivisionError as _e:
00257                 e = _e
00258             try:
00259                 xyzzy
00260             except NameError:
00261                 raise KeyError from e
00262         def outer_raise():
00263             inner_raise() # Marker
00264         blocks = boundaries.split(self.get_report(outer_raise))
00265         self.assertEqual(len(blocks), 3)
00266         self.assertEqual(blocks[1], cause_message)
00267         self.check_zero_div(blocks[0])
00268         self.assertIn('inner_raise() # Marker', blocks[2])

Here is the call graph for this function:

Definition at line 269 of file test_traceback.py.

00269 
00270     def test_cause_recursive(self):
00271         def inner_raise():
00272             try:
00273                 try:
00274                     self.zero_div()
00275                 except ZeroDivisionError as e:
00276                     z = e
00277                     raise KeyError from e
00278             except KeyError as e:
00279                 raise z from e
00280         def outer_raise():
00281             inner_raise() # Marker
00282         blocks = boundaries.split(self.get_report(outer_raise))
00283         self.assertEqual(len(blocks), 3)
00284         self.assertEqual(blocks[1], cause_message)
00285         # The first block is the KeyError raised from the ZeroDivisionError
00286         self.assertIn('raise KeyError from e', blocks[0])
00287         self.assertNotIn('1/0', blocks[0])
00288         # The second block (apart from the boundary) is the ZeroDivisionError
00289         # re-raised from the KeyError
00290         self.assertIn('inner_raise() # Marker', blocks[2])
00291         self.check_zero_div(blocks[2])

Here is the call graph for this function:

Definition at line 235 of file test_traceback.py.

00235 
00236     def test_context(self):
00237         def inner_raise():
00238             try:
00239                 self.zero_div()
00240             except ZeroDivisionError:
00241                 raise KeyError
00242         def outer_raise():
00243             inner_raise() # Marker
00244         blocks = boundaries.split(self.get_report(outer_raise))
00245         self.assertEqual(len(blocks), 3)
00246         self.assertEqual(blocks[1], context_message)
00247         self.check_zero_div(blocks[0])
00248         self.assertIn('inner_raise() # Marker', blocks[2])

Here is the call graph for this function:

Definition at line 209 of file test_traceback.py.

00209 
00210     def test_simple(self):
00211         try:
00212             1/0 # Marker
00213         except ZeroDivisionError as _:
00214             e = _
00215         lines = self.get_report(e).splitlines()
00216         self.assertEqual(len(lines), 4)
00217         self.assertTrue(lines[0].startswith('Traceback'))
00218         self.assertTrue(lines[1].startswith('  File'))
00219         self.assertIn('1/0 # Marker', lines[2])
00220         self.assertTrue(lines[3].startswith('ZeroDivisionError'))

Here is the call graph for this function:

Definition at line 292 of file test_traceback.py.

00292 
00293     def test_syntax_error_offset_at_eol(self):
00294         # See #10186.
00295         def e():
00296             raise SyntaxError('', ('', 0, 5, 'hello'))
00297         msg = self.get_report(e).splitlines()
00298         self.assertEqual(msg[-2], "        ^")
00299         def e():
00300             exec("x = 5 | 4 |")
00301         msg = self.get_report(e).splitlines()
00302         self.assertEqual(msg[-2], '              ^')
00303 

Here is the call graph for this function:

Definition at line 200 of file test_traceback.py.

00200 
00201     def zero_div(self):
00202         1/0 # In zero_div

Here is the caller graph for this function:


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