#NEWLINE# def test_compare_values( self ) : #NEWLINE# #INDENT# def assert_ge_0( obj ) : #NEWLINE# #INDENT# if isinstance ( obj , tuple ) : #NEWLINE# #INDENT# for value in obj : #NEWLINE# #INDENT# assert ( value >= 0 ) , value #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , ( int , long , float ) ) : #NEWLINE# #INDENT# assert ( obj >= 0 ) , obj #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert 0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# def compare_with_tolerance( ret1 , ret2 , tolerance ) : #NEWLINE# #INDENT# if ( ret1 == ret2 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( ret2 , ( int , long , float ) ) : #NEWLINE# #INDENT# diff = abs ( ( ret1 - ret2 ) ) #NEWLINE# assert ( diff <= tolerance ) , diff #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( ret2 , tuple ) : #NEWLINE# #INDENT# for ( a , b ) in zip ( ret1 , ret2 ) : #NEWLINE# #INDENT# diff = abs ( ( a - b ) ) #NEWLINE# assert ( diff <= tolerance ) , diff #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# failures = [ ] #NEWLINE# for ( name , tolerance ) in self . fun_names : #NEWLINE# #INDENT# meth1 = wrap_exceptions ( getattr ( _psutil_mswindows , name ) ) #NEWLINE# meth2 = wrap_exceptions ( getattr ( _psutil_mswindows , ( name + '_2' ) ) ) #NEWLINE# for p in psutil . process_iter ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ret1 = meth1 ( p . pid ) #NEWLINE# #UNINDENT# except psutil . NoSuchProcess : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# except psutil . AccessDenied : #NEWLINE# #INDENT# ret1 = None #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ret2 = meth2 ( p . pid ) #NEWLINE# #UNINDENT# except psutil . NoSuchProcess : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( ret1 is None ) : #NEWLINE# #INDENT# assert_ge_0 ( ret2 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# compare_with_tolerance ( ret1 , ret2 , tolerance ) #NEWLINE# assert_ge_0 ( ret1 ) #NEWLINE# assert_ge_0 ( ret2 ) #NEWLINE# #UNINDENT# #UNINDENT# except AssertionError : #NEWLINE# #INDENT# err = sys . exc_info ( ) [ 1 ] #NEWLINE# trace = traceback . format_exc ( ) #NEWLINE# msg = ( '%s\npid=%s, method=%r, ret_1=%r, ret_2=%r' % ( trace , p . pid , name , ret1 , ret2 ) ) #NEWLINE# failures . append ( msg ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if failures : #NEWLINE# #INDENT# self . fail ( '\n\n' . join ( failures ) )