<s> from nova import test <EOL> from nova import exception <EOL> class ApiErrorTestCase ( test . TestCase ) : <EOL> def test_return_valid_error ( self ) : <EOL> err = exception . ApiError ( '<STR_LIT>' ) <EOL> self . assertEqual ( err . __str__ ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( err . code , None ) <EOL> self . assertEqual ( err . msg , '<STR_LIT>' ) <EOL> err = exception . ApiError ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( err . __str__ ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( err . code , '<STR_LIT>' ) <EOL> self . assertEqual ( err . msg , '<STR_LIT>' ) <EOL> class FakeNotifier ( object ) : <EOL> """<STR_LIT>""" <EOL> ERROR = <NUM_LIT> <EOL> def __init__ ( self ) : <EOL> self . provided_publisher = None <EOL> self . provided_event = None <EOL> self . provided_priority = None <EOL> self . provided_payload = None <EOL> def notify ( self , publisher , event , priority , payload ) : <EOL> self . provided_publisher = publisher <EOL> self . provided_event = event <EOL> self . provided_priority = priority <EOL> self . provided_payload = payload <EOL> def good_function ( ) : <EOL> return <NUM_LIT> <EOL> def bad_function_error ( ) : <EOL> raise exception . Error ( ) <EOL> def bad_function_exception ( ) : <EOL> raise Exception ( ) <EOL> class WrapExceptionTestCase ( test . TestCase ) : <EOL> def test_wrap_exception_good_return ( self ) : <EOL> wrapped = exception . wrap_exception ( ) <EOL> self . assertEquals ( <NUM_LIT> , wrapped ( good_function ) ( ) ) <EOL> def test_wrap_exception_throws_error ( self ) : <EOL> wrapped = exception . wrap_exception ( ) <EOL> self . assertRaises ( exception . Error , wrapped ( bad_function_error ) ) <EOL> def test_wrap_exception_throws_exception ( self ) : <EOL> wrapped = exception . wrap_exception ( ) <EOL> self . assertRaises ( exception . Error , wrapped ( bad_function_exception ) ) <EOL> def test_wrap_exception_with_notifier ( self ) : <EOL> notifier = FakeNotifier ( ) <EOL> wrapped = exception . wrap_exception ( notifier , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> self . assertRaises ( exception . Error , wrapped ( bad_function_exception ) ) <EOL> self . assertEquals ( notifier . provided_publisher , "<STR_LIT>" ) <EOL> self . assertEquals ( notifier . provided_event , "<STR_LIT>" ) <EOL> self . assertEquals ( notifier . provided_priority , "<STR_LIT>" ) <EOL> for key in [ '<STR_LIT>' , '<STR_LIT:args>' ] : <EOL> self . assertTrue ( key in notifier . provided_payload . keys ( ) ) <EOL> def test_wrap_exception_with_notifier_defaults ( self ) : <EOL> notifier = FakeNotifier ( ) <EOL> wrapped = exception . wrap_exception ( notifier ) <EOL> self . assertRaises ( exception . Error , wrapped ( bad_function_exception ) ) <EOL> self . assertEquals ( notifier . provided_publisher , None ) <EOL> self . assertEquals ( notifier . provided_event , "<STR_LIT>" ) <EOL> self . assertEquals ( notifier . provided_priority , notifier . ERROR ) </s>
