@@ -256,12 +256,8 @@ def test_pack_exceptions(self):
256256 for (name , obj , exception ) in pack_exception_test_vectors :
257257 obj_repr = repr (obj )
258258 print ("\t Testing %s: object %s" % (name , obj_repr if len (obj_repr ) < 24 else obj_repr [0 :24 ] + "..." ))
259- try :
259+ with self . assertRaises ( exception ) :
260260 umsgpack .packb (obj )
261- except Exception as e :
262- self .assertTrue (isinstance (e , exception ))
263- continue
264- self .assertTrue (False )
265261
266262 def test_unpack_single (self ):
267263 for (name , obj , data ) in single_test_vectors :
@@ -292,12 +288,8 @@ def test_unpack_composite(self):
292288 def test_unpack_exceptions (self ):
293289 for (name , data , exception ) in unpack_exception_test_vectors :
294290 print ("\t Testing %s" % name )
295- try :
291+ with self . assertRaises ( exception ) :
296292 umsgpack .unpackb (data )
297- except Exception as e :
298- self .assertTrue (isinstance (e , exception ))
299- continue
300- self .assertTrue (False )
301293
302294 def test_pack_compatibility (self ):
303295 umsgpack .compatibility = True
@@ -332,18 +324,14 @@ def test_unpack_compatibility(self):
332324 umsgpack .compatibility = False
333325
334326 def test_ext_exceptions (self ):
335- try :
327+ with self . assertRaises ( TypeError ) :
336328 _ = umsgpack .Ext (- 1 , b"" )
337- except Exception as e :
338- self .assertTrue (isinstance (e , TypeError ))
339- try :
329+
330+ with self .assertRaises (TypeError ):
340331 _ = umsgpack .Ext (128 , b"" )
341- except Exception as e :
342- self .assertTrue (isinstance (e , TypeError ))
343- try :
332+
333+ with self .assertRaises (TypeError ):
344334 _ = umsgpack .Ext (0 , u"unicode string" )
345- except Exception as e :
346- self .assertTrue (isinstance (e , TypeError ))
347335
348336 def test_namespacing (self ):
349337 # Get a list of global variables from umsgpack module
0 commit comments