@@ -381,30 +381,36 @@ def test_compare(self):
381
381
self .assertEqual (type (m ), type (0 ))
382
382
result , pmsg , msgid , ctrls = l .result4 (m , _ldap .MSG_ALL , self .timeout )
383
383
self .assertEqual (result , _ldap .RES_ADD )
384
+
384
385
# try a false compare
385
386
m = l .compare_ext (dn , "userPassword" , "bad_string" )
386
- try :
387
+ with self . assertRaises ( _ldap . COMPARE_FALSE ) as e :
387
388
r = l .result4 (m , _ldap .MSG_ALL , self .timeout )
388
- except _ldap .COMPARE_FALSE :
389
- pass
390
- else :
391
- self .fail ("expected COMPARE_FALSE, got %r" % r )
389
+
390
+ self .assertEqual (e .exception .args [0 ]['msgid' ], m )
391
+ self .assertEqual (e .exception .args [0 ]['msgtype' ], _ldap .RES_COMPARE )
392
+ self .assertEqual (e .exception .args [0 ]['result' ], 5 )
393
+ self .assertFalse (e .exception .args [0 ]['ctrls' ])
394
+
392
395
# try a true compare
393
396
m = l .compare_ext (dn , "userPassword" , "the_password" )
394
- try :
397
+ with self . assertRaises ( _ldap . COMPARE_TRUE ) as e :
395
398
r = l .result4 (m , _ldap .MSG_ALL , self .timeout )
396
- except _ldap .COMPARE_TRUE :
397
- pass
398
- else :
399
- self .fail ("expected COMPARE_TRUE, got %r" % r )
399
+
400
+ self .assertEqual (e .exception .args [0 ]['msgid' ], m )
401
+ self .assertEqual (e .exception .args [0 ]['msgtype' ], _ldap .RES_COMPARE )
402
+ self .assertEqual (e .exception .args [0 ]['result' ], 6 )
403
+ self .assertFalse (e .exception .args [0 ]['ctrls' ])
404
+
400
405
# try a compare on bad attribute
401
406
m = l .compare_ext (dn , "badAttribute" , "ignoreme" )
402
- try :
407
+ with self . assertRaises ( _ldap . error ) as e :
403
408
r = l .result4 (m , _ldap .MSG_ALL , self .timeout )
404
- except _ldap .error :
405
- pass
406
- else :
407
- self .fail ("expected LDAPError, got %r" % r )
409
+
410
+ self .assertEqual (e .exception .args [0 ]['msgid' ], m )
411
+ self .assertEqual (e .exception .args [0 ]['msgtype' ], _ldap .RES_COMPARE )
412
+ self .assertEqual (e .exception .args [0 ]['result' ], 17 )
413
+ self .assertFalse (e .exception .args [0 ]['ctrls' ])
408
414
409
415
def test_delete_no_such_object (self ):
410
416
"""
0 commit comments