#NEWLINE# def run( ) : #NEWLINE# #INDENT# image_dir = 'result_images' #NEWLINE# _html = '' #NEWLINE# _html += '<html><head><style media="screen" type="text/css">\n    img{\n        width:100%;\n        max-width:800px;\n    }\n    </style>\n    </head><body>\n' #NEWLINE# _subdirs = [ name for name in os . listdir ( image_dir ) if os . path . isdir ( os . path . join ( image_dir , name ) ) ] #NEWLINE# _row = '<tr><td>{0} {1}</td><td>{2}</td><td><a href="{3}"><img src="{3}"></a></td><td>{4}</td>\n' #NEWLINE# _failed = '' #NEWLINE# _failed += '<h2>Only Failed</h2>' #NEWLINE# _failed += '<table>\n<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>\n' #NEWLINE# _has_failure = False #NEWLINE# _body = '' #NEWLINE# for subdir in _subdirs : #NEWLINE# #INDENT# pictures = defaultdict ( dict ) #NEWLINE# for file in os . listdir ( os . path . join ( image_dir , subdir ) ) : #NEWLINE# #INDENT# if os . path . isdir ( os . path . join ( image_dir , subdir , file ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ( fn , fext ) = os . path . splitext ( file ) #NEWLINE# if ( fext != '.png' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( '-failed-diff' in fn ) : #NEWLINE# #INDENT# pictures [ fn [ : ( - 12 ) ] ] [ 'f' ] = os . path . join ( subdir , file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( '-expected' in fn ) : #NEWLINE# #INDENT# pictures [ fn [ : ( - 9 ) ] ] [ 'e' ] = os . path . join ( subdir , file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pictures [ fn ] [ 'c' ] = os . path . join ( subdir , file ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# _body += '<h2>{0}</h2>' . format ( subdir ) #NEWLINE# _body += '<table>\n<thead><td>name</td><td>actual</td><td>expected</td><td>diff</td></thead>\n' #NEWLINE# for ( name , test ) in six . iteritems ( pictures ) : #NEWLINE# #INDENT# if test . get ( 'f' , None ) : #NEWLINE# #INDENT# _has_failure = True #NEWLINE# s = '(failed)' #NEWLINE# failed = '<a href="{0}">diff</a>' . format ( test . get ( 'f' , '' ) ) #NEWLINE# current = '<a href="{0}"><img src="{0}"></a>' . format ( test . get ( 'c' , '' ) ) #NEWLINE# _failed += _row . format ( name , '' , current , test . get ( 'e' , '' ) , failed ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( test . get ( 'c' , None ) is None ) : #NEWLINE# #INDENT# _has_failure = True #NEWLINE# s = '(failed)' #NEWLINE# failed = '--' #NEWLINE# current = '(Failure in test, no image produced)' #NEWLINE# _failed += _row . format ( name , '' , current , test . get ( 'e' , '' ) , failed ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s = '(passed)' #NEWLINE# failed = '--' #NEWLINE# current = '<a href="{0}"><img src="{0}"></a>' . format ( test . get ( 'c' , '' ) ) #NEWLINE# #UNINDENT# #UNINDENT# _body += _row . format ( name , '' , current , test . get ( 'e' , '' ) , failed ) #NEWLINE# #UNINDENT# _body += '</table>\n' #NEWLINE# #UNINDENT# _failed += '</table>\n' #NEWLINE# if _has_failure : #NEWLINE# #INDENT# _html += _failed #NEWLINE# #UNINDENT# _html += _body #NEWLINE# _html += '\n</body></html>' #NEWLINE# index = os . path . join ( image_dir , 'index.html' ) #NEWLINE# with open ( index , 'w' ) as f : #NEWLINE# #INDENT# f . write ( _html ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# import webbrowser #NEWLINE# webbrowser . open ( index ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# print ( 'Open {0} in a browser for a visual comparisson.' . format ( str ( index ) ) )