#NEWLINE# def report_diff_values( fileobj , a , b , ind = 0 ) : #NEWLINE# #INDENT# 'Write a diff between two values to the specified file-like object.' #NEWLINE# typea = type ( a ) #NEWLINE# typeb = type ( b ) #NEWLINE# if ( isinstance ( a , string_types ) and ( not isinstance ( b , string_types ) ) ) : #NEWLINE# #INDENT# a = repr ( a ) . lstrip ( 'u' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( b , string_types ) and ( not isinstance ( a , string_types ) ) ) : #NEWLINE# #INDENT# b = repr ( b ) . lstrip ( 'u' ) #NEWLINE# #UNINDENT# #UNINDENT# if isinstance ( a , ( int , float , complex , np . number ) ) : #NEWLINE# #INDENT# a = repr ( a ) #NEWLINE# #UNINDENT# if isinstance ( b , ( int , float , complex , np . number ) ) : #NEWLINE# #INDENT# b = repr ( b ) #NEWLINE# #UNINDENT# if ( isinstance ( a , np . ndarray ) and isinstance ( b , np . ndarray ) ) : #NEWLINE# #INDENT# diff_indices = np . where ( ( a != b ) ) #NEWLINE# num_diffs = reduce ( ( lambda x , y : ( x * y ) ) , ( len ( d ) for d in diff_indices ) , 1 ) #NEWLINE# for idx in islice ( zip ( * diff_indices ) , 3 ) : #NEWLINE# #INDENT# fileobj . write ( indent ( ( u ( '  at %r:\n' ) % list ( idx ) ) , ind ) ) #NEWLINE# report_diff_values ( fileobj , a [ idx ] , b [ idx ] , ind = ( ind + 1 ) ) #NEWLINE# #UNINDENT# if num_diffs : #NEWLINE# #INDENT# fileobj . write ( indent ( ( '  ...and at %d more indices.\n' % ( num_diffs - 3 ) ) , ind ) ) #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# padding = ( max ( len ( typea . __name__ ) , len ( typeb . __name__ ) ) + 3 ) #NEWLINE# for line in difflib . ndiff ( str ( a ) . splitlines ( ) , str ( b ) . splitlines ( ) ) : #NEWLINE# #INDENT# if ( line [ 0 ] == '-' ) : #NEWLINE# #INDENT# line = ( 'a>' + line [ 1 : ] ) #NEWLINE# if ( typea != typeb ) : #NEWLINE# #INDENT# typename = ( ( '(' + typea . __name__ ) + ') ' ) #NEWLINE# line = ( typename . rjust ( padding ) + line ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ 0 ] == '+' ) : #NEWLINE# #INDENT# line = ( 'b>' + line [ 1 : ] ) #NEWLINE# if ( typea != typeb ) : #NEWLINE# #INDENT# typename = ( ( '(' + typeb . __name__ ) + ') ' ) #NEWLINE# line = ( typename . rjust ( padding ) + line ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# line = ( ' ' + line ) #NEWLINE# if ( typea != typeb ) : #NEWLINE# #INDENT# line = ( ( ' ' * padding ) + line ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# fileobj . write ( indent ( ( '  %s\n' % line . rstrip ( '\n' ) ) , ind ) )