77#
88
99import os
10- import time
1110import six
1211
1312from collections import defaultdict
4847
4948
5049def run ():
51- # Build a website for visual comparison
50+ """
51+ Build a website for visual comparison
52+ """
5253 image_dir = "result_images"
53- # build the website
54- _subdirs = [ name for name in os .listdir (image_dir ) if os . path . isdir ( os . path . join ( image_dir , name ))]
55- # loop over all pictures
56- _has_failure = False
54+ _subdirs = ( name
55+ for name in os .listdir (image_dir )
56+ if os . path . isdir ( os . path . join ( image_dir , name )))
57+
5758 failed_rows = []
5859 body_sections = []
5960 for subdir in _subdirs :
6061 if subdir == "test_compare_images" :
61- # these are the image which test the image comparison functions.. .
62+ # These are the images which test the image comparison functions.
6263 continue
64+
6365 pictures = defaultdict (dict )
6466 for file in os .listdir (os .path .join (image_dir , subdir )):
6567 if os .path .isdir (os .path .join (image_dir , subdir , file )):
@@ -81,16 +83,15 @@ def run():
8183 actual_image = test .get ('c' , '' )
8284
8385 if 'f' in test :
84- # a real failure in the image generation, resulting in different images
85- _has_failure = True
86+ # A real failure in the image generation, resulting in
87+ # different images.
8688 status = " (failed)"
8789 failed = '<a href="{0}">diff</a>' .format (test ['f' ])
8890 current = linked_image_template .format (actual_image )
8991 failed_rows .append (row_template .format (name , "" , current ,
9092 expected_image , failed ))
9193 elif 'c' not in test :
9294 # A failure in the test, resulting in no current image
93- _has_failure = True
9495 status = " (failed)"
9596 failed = '--'
9697 current = '(Failure in test, no image produced)'
@@ -100,13 +101,14 @@ def run():
100101 status = " (passed)"
101102 failed = '--'
102103 current = linked_image_template .format (actual_image )
104+
103105 subdir_rows .append (row_template .format (name , status , current ,
104106 expected_image , failed ))
105107
106108 body_sections .append (
107109 subdir_template .format (subdir = subdir , rows = '\n ' .join (subdir_rows )))
108110
109- if _has_failure :
111+ if failed_rows :
110112 failed = failed_template .format (rows = '\n ' .join (failed_rows ))
111113 else :
112114 failed = ''
@@ -122,5 +124,6 @@ def run():
122124 except :
123125 print ("Open {} in a browser for a visual comparison." .format (index ))
124126
127+
125128if __name__ == '__main__' :
126129 run ()
0 commit comments