MCPcopy Create free account
hub / github.com/ImageEngine/cortex / testExceptionHandling

Method testExceptionHandling

test/IECore/MessageHandler.py:232–271  ·  view source on GitHub ↗
( self )

Source from the content-addressed store, hash-verified

230 self.assertEqual( w(), None )
231
232 def testExceptionHandling( self ) :
233
234 # This is more a test of ExceptionAlgo than it is MessageHandler, but
235 # this is the most convenient place to put the test right now.
236
237 class ThrowingMessageHandler( IECore.MessageHandler ):
238
239 def __init__( self ) :
240
241 IECore.MessageHandler.__init__( self )
242
243 def handle( self, level, context, msg ):
244
245 if context == "python" :
246 raise Exception( "Test" )
247 else :
248 assert( context == "c++" )
249 # This will raise a C++ exception that gets translated to a
250 # Python exception, and then gets translated back to a C++
251 # exception by the MessageHandlerWrapper, before finally
252 # being converted back to another Python exception by the
253 # binding for `IECore.msg()`.
254 IECore.StringAlgo.substitute( "##", { "frame" : IECore.BoolData( False ) } )
255
256 for exceptionType in [ "python", "c++" ] :
257
258 with self.subTest( exceptionType = exceptionType ) :
259
260 while gc.collect() :
261 pass
262
263 expected = "Test" if exceptionType == "python" else "Unexpected data type"
264 with self.assertRaisesRegex( Exception, expected ) :
265 with ThrowingMessageHandler() :
266 IECore.msg( IECore.Msg.Level.Error, exceptionType, "message" )
267
268 # There should be no Exception objects in the garbage pool. If
269 # there were, that would indicate a reference counting error in
270 # `ExceptionAlgo::translatePythonException()`.
271 self.assertEqual( [ o for o in gc.get_objects() if isinstance( o, Exception ) ], [] )
272
273 def testOStreamLineSplitting( self ) :
274

Callers

nothing calls this directly

Calls 3

collectMethod · 0.80
msgMethod · 0.80

Tested by

no test coverage detected