Skip to content

Commit dabe300

Browse files
committed
Added test for nested panics
1 parent 872aa7b commit dabe300

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/bd2k/util/test/test_panic.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from bd2k.util.exceptions import panic
77

88
log = logging.getLogger( __name__ )
9-
logging.basicConfig()
9+
logging.basicConfig( )
10+
1011

1112
class TestPanic( unittest.TestCase ):
1213
def test_panic_by_hand( self ):
@@ -27,6 +28,12 @@ def test_panic_with_secondary( self ):
2728
except:
2829
self.__assert_raised_exception_is_primary( )
2930

31+
def test_nested_panic( self ):
32+
try:
33+
self.try_and_nested_panic_with_secondary( )
34+
except:
35+
self.__assert_raised_exception_is_primary( )
36+
3037
def try_and_panic_by_hand( self ):
3138
try:
3239
self.line_of_primary_exc = inspect.currentframe( ).f_lineno + 1
@@ -55,12 +62,19 @@ def try_and_panic_with_secondary( self ):
5562
with panic( log ):
5663
raise RuntimeError( "secondary" )
5764

65+
def try_and_nested_panic_with_secondary( self ):
66+
try:
67+
self.line_of_primary_exc = inspect.currentframe( ).f_lineno + 1
68+
raise ValueError( "primary" )
69+
except:
70+
with panic( log ):
71+
with panic( log ):
72+
raise RuntimeError( "secondary" )
73+
5874
def __assert_raised_exception_is_primary( self ):
5975
exc_type, exc_value, exc_traceback = sys.exc_info( )
6076
self.assertEquals( exc_type, ValueError )
6177
self.assertEquals( exc_value.message, "primary" )
6278
while exc_traceback.tb_next is not None:
6379
exc_traceback = exc_traceback.tb_next
6480
self.assertEquals( exc_traceback.tb_lineno, self.line_of_primary_exc )
65-
66-

0 commit comments

Comments
 (0)