#NEWLINE# def test_write_errors( self ) : #NEWLINE# #INDENT# coll = self . client . pymongo_test . test #NEWLINE# coll . drop ( ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# try : #NEWLINE# #INDENT# coll . bulk_write ( [ InsertOne ( { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) , InsertOne ( { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) , InsertOne ( { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) , DeleteOne ( { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) ] , ordered = False ) #NEWLINE# #UNINDENT# except OperationFailure : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# results = self . listener . results #NEWLINE# started = results [ 'started' ] #NEWLINE# succeeded = results [ 'succeeded' ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# operation_id = started [ 0 ] . operation_id #NEWLINE# pairs = list ( zip ( started , succeeded ) ) #NEWLINE# errors = [ ] #NEWLINE# for ( start , succeed ) in pairs : #NEWLINE# #INDENT# self . assertIsInstance ( start , monitoring . CommandStartedEvent ) #NEWLINE# self . assertEqual ( 'pymongo_test' , start . database_name ) #NEWLINE# self . assertIsInstance ( start . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , start . connection_id ) #NEWLINE# self . assertIsInstance ( succeed , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeed . duration_micros , int ) #NEWLINE# self . assertEqual ( start . command_name , succeed . command_name ) #NEWLINE# self . assertEqual ( start . request_id , succeed . request_id ) #NEWLINE# self . assertEqual ( start . connection_id , succeed . connection_id ) #NEWLINE# self . assertEqual ( start . operation_id , operation_id ) #NEWLINE# self . assertEqual ( succeed . operation_id , operation_id ) #NEWLINE# if ( 'writeErrors' in succeed . reply ) : #NEWLINE# #INDENT# errors . extend ( start . reply [ 'writeErrors' ] ) #NEWLINE# #UNINDENT# #UNINDENT# self . assertEqual ( 2 , len ( errors ) ) #NEWLINE# fields = set ( [ 'index' , 'code' , 'errmsg' ] ) #NEWLINE# for error in errors : #NEWLINE# #INDENT# self . assertEqual ( fields , set ( error ) )