Build a website for visual comparison
(show_browser=True)
| 56 | |
| 57 | |
| 58 | def run(show_browser=True): |
| 59 | """ |
| 60 | Build a website for visual comparison |
| 61 | """ |
| 62 | image_dir = "result_images" |
| 63 | _subdirs = (name |
| 64 | for name in os.listdir(image_dir) |
| 65 | if os.path.isdir(os.path.join(image_dir, name))) |
| 66 | |
| 67 | failed_rows = [] |
| 68 | body_sections = [] |
| 69 | for subdir in sorted(_subdirs): |
| 70 | if subdir == "test_compare_images": |
| 71 | # These are the images which test the image comparison functions. |
| 72 | continue |
| 73 | |
| 74 | pictures = defaultdict(dict) |
| 75 | for file in os.listdir(os.path.join(image_dir, subdir)): |
| 76 | if os.path.isdir(os.path.join(image_dir, subdir, file)): |
| 77 | continue |
| 78 | fn, fext = os.path.splitext(file) |
| 79 | if fext != ".png": |
| 80 | continue |
| 81 | if "-failed-diff" in fn: |
| 82 | file_type = 'diff' |
| 83 | test_name = fn[:-len('-failed-diff')] |
| 84 | elif "-expected" in fn: |
| 85 | for ext in NON_PNG_EXTENSIONS: |
| 86 | if fn.endswith(f'_{ext}'): |
| 87 | display_extension = f'_{ext}' |
| 88 | extension = ext |
| 89 | fn = fn[:-len(display_extension)] |
| 90 | break |
| 91 | else: |
| 92 | display_extension = '' |
| 93 | extension = 'png' |
| 94 | file_type = 'expected' |
| 95 | test_name = fn[:-len('-expected')] + display_extension |
| 96 | else: |
| 97 | file_type = 'actual' |
| 98 | test_name = fn |
| 99 | # Always use / for URLs. |
| 100 | pictures[test_name][file_type] = '/'.join((subdir, file)) |
| 101 | |
| 102 | subdir_rows = [] |
| 103 | for name, test in sorted(pictures.items()): |
| 104 | expected_image = test.get('expected', '') |
| 105 | actual_image = test.get('actual', '') |
| 106 | |
| 107 | if 'diff' in test: |
| 108 | # A real failure in the image generation, resulting in |
| 109 | # different images. |
| 110 | status = " (failed)" |
| 111 | failed = f'<a href="{test["diff"]}">diff</a>' |
| 112 | current = linked_image_template.format(actual_image) |
| 113 | failed_rows.append(row_template.format(name, "", current, |
| 114 | expected_image, failed)) |
| 115 | elif 'actual' not in test: |
no test coverage detected