#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# self . assertGreaterEqual ( value , 0 , msg = obj ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , ( int , long , float ) ) : #NEWLINE# #INDENT# self . assertGreaterEqual ( obj , 0 ) #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# self . assertLessEqual ( diff , tolerance ) #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# self . assertLessEqual ( diff , tolerance ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# from psutil._pswindows import ntpinfo #NEWLINE# failures = [ ] #NEWLINE# for p in psutil . process_iter ( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# nt = ntpinfo ( * cext . proc_info ( p . pid ) ) #NEWLINE# #UNINDENT# except psutil . NoSuchProcess : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# assert_ge_0 ( nt ) #NEWLINE# for ( name , tolerance ) in self . fun_names : #NEWLINE# #INDENT# if ( ( name == 'proc_memory_info' ) and ( p . pid == os . getpid ( ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( ( name == 'proc_create_time' ) and ( p . pid in ( 0 , 4 ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# meth = wrap_exceptions ( getattr ( cext , name ) ) #NEWLINE# try : #NEWLINE# #INDENT# ret = meth ( p . pid ) #NEWLINE# #UNINDENT# except ( psutil . NoSuchProcess , psutil . AccessDenied ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( name == 'proc_cpu_times' ) : #NEWLINE# #INDENT# compare_with_tolerance ( ret [ 0 ] , nt . user_time , tolerance ) #NEWLINE# compare_with_tolerance ( ret [ 1 ] , nt . kernel_time , tolerance ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == 'proc_create_time' ) : #NEWLINE# #INDENT# compare_with_tolerance ( ret , nt . create_time , tolerance ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == 'proc_num_handles' ) : #NEWLINE# #INDENT# compare_with_tolerance ( ret , nt . num_handles , tolerance ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == 'proc_io_counters' ) : #NEWLINE# #INDENT# compare_with_tolerance ( ret [ 0 ] , nt . io_rcount , tolerance ) #NEWLINE# compare_with_tolerance ( ret [ 1 ] , nt . io_wcount , tolerance ) #NEWLINE# compare_with_tolerance ( ret [ 2 ] , nt . io_rbytes , tolerance ) #NEWLINE# compare_with_tolerance ( ret [ 3 ] , nt . io_wbytes , tolerance ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == 'proc_memory_info' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# rawtupl = cext . proc_memory_info_2 ( p . pid ) #NEWLINE# #UNINDENT# except psutil . NoSuchProcess : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# compare_with_tolerance ( ret , rawtupl , tolerance ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except AssertionError : #NEWLINE# #INDENT# trace = traceback . format_exc ( ) #NEWLINE# msg = ( '%s\npid=%s, method=%r, ret_1=%r, ret_2=%r' % ( trace , p . pid , name , ret , nt ) ) #NEWLINE# failures . append ( msg ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if failures : #NEWLINE# #INDENT# self . fail ( '\n\n' . join ( failures ) )