generate.py (2866B)
1 #!/usr/bin/env python3 2 import os 3 import string 4 5 from typing import List, Tuple 6 7 test_template = """<h3>{number}: {title}</h3> 8 <div class="test"> 9 {html} 10 </div>""" 11 12 13 def generate_test_list() -> List[Tuple[str, str]]: 14 test_list = []; 15 outers = [ 16 ["inline-block", '<div class="inline-block">', '</div><span class="next">ZZ</span>'], 17 ["float", '<div class="float">', '</div><span class="next">ZZ</span>'], 18 ["table-cell", '<table><tr><td>', '</td><td class="next">ZZ</td></tr></table>']]; 19 middles = [ 20 None, 21 ["inline-block", '<div class="inline-block">', '</div>']]; 22 targets = [ 23 ["block", '<div class="target">HH</div>'], 24 ["inline", '<span class="target">HH</span>'], 25 ["block with borders", '<div class="target border">HHH</div>'], 26 ["inline with borders", '<span class="target border">HHH</span>']]; 27 for outer in outers: 28 for middle in middles: 29 for target in targets: 30 title = target[0]; 31 html = target[1]; 32 if middle is not None: 33 title += " in " + middle[0]; 34 html = middle[1] + html + middle[2]; 35 title = "Shrink-to-fit " + outer[0] + " with a child of orthogonal " + title; 36 html = outer[1] + html + outer[2]; 37 test_list.append((title, html)); 38 return test_list 39 40 41 def read_template() -> str: 42 with open("template.html") as f: 43 return f.read() 44 45 46 def main(): 47 template = read_template() 48 test_list = generate_test_list() 49 50 dest_dir = os.path.abspath( 51 os.path.join(os.path.dirname(os.path.abspath(__file__)), 52 os.path.pardir, 53 os.path.pardir)) 54 55 for index in range(-1, len(test_list)): 56 if index == -1: 57 offset = 0 58 suffix = "" 59 tests = test_list 60 title = "Shrink-to-fit with orthogonal children" 61 flags = " combo" 62 else: 63 offset = index 64 suffix = string.ascii_letters[index] 65 tests = [test_list[index]] 66 title = tests[0][0] 67 flags = "" 68 69 filename = f"orthogonal-parent-shrink-to-fit-001{suffix}.html" 70 71 tests_data = [] 72 for idx, (test_title, html) in enumerate(tests): 73 number = offset + idx + 1 74 tests_data.append(test_template.format(number=number, 75 title=test_title, 76 html=html)) 77 78 output = template.replace("{{title}}", title) 79 output = output.replace("{{flags}}", flags) 80 output = output.replace("{{tests}}", "\n".join(tests_data)) 81 with open(os.path.join(dest_dir, filename), "w") as f: 82 f.write(output) 83 84 85 if __name__ == "__main__": 86 main()