Skip to content

Commit 834c6a2

Browse files
authored
Fix syntax and logic issues in tests_to_html.py (#2974)
This PR addresses bugs in `tests_to_html.py` that affect the generation of HTML test reports: 1. **Robust Suffix Stripping**: Replaces hardcoded string slicing lengths (`[0:-8]`) with Python's built-in `removesuffix()` method. This correctly handles variable-length language suffixes (e.g., `_glsl.png` which is 9 characters vs `_osl.png` which is 8 characters), preventing filename truncation bugs. 2. **CSS Syntax Error**: Adds a trailing newline (`\n`) to the `@media print` block to prevent it from concatenating directly with the following `td` rule, which produces invalid CSS. 3. **Three-way Comparison Bug**: Fixes a copy-paste error where `path3` was joined with `args.inputdir2` instead of `args.inputdir3`.
1 parent 244b694 commit 834c6a2

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

python/MaterialXTest/tests_to_html.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def main(args=None):
8787
fh.write("<style>\n")
8888
# Preserve inline background-color when printing to PDF, so transparent renders
8989
# don't vanish into the white page.
90-
fh.write("@media print { * { print-color-adjust: exact; -webkit-print-color-adjust: exact; } }")
90+
fh.write("@media print { * { print-color-adjust: exact; -webkit-print-color-adjust: exact; } }\n")
9191
fh.write("td {")
9292
fh.write(" padding: " + str(args.cellpadding) + ";")
9393
fh.write(" border: " + str(args.tableborder) + "px solid black;")
@@ -158,13 +158,13 @@ def main(args=None):
158158
langFiles3 = []
159159
langPaths3 = []
160160
preFixLen: int = len(args.inputdir1) + 1 # including the path separator
161-
postFix: str = args.lang1 + ".png"
161+
postFix: str = f"_{args.lang1}.png"
162162
for file1, path1 in zip(langFiles1, langPaths1):
163163
# Allow for just one language to be shown if source and dest are the same.
164164
# Otherwise add in equivalent name with dest language replacement if
165165
# pointing to the same directory
166166
if args.inputdir1 != args.inputdir2 or args.lang1 != args.lang2:
167-
file2 = file1[:-len(postFix)] + args.lang2 + ".png"
167+
file2 = f"{file1.removesuffix(postFix)}_{args.lang2}.png"
168168
path2 = os.path.join(args.inputdir2, path1[len(args.inputdir1)+1:])
169169
else:
170170
file2 = ""
@@ -173,8 +173,8 @@ def main(args=None):
173173
langPaths2.append(path2)
174174

175175
if useThirdLang:
176-
file3 = file1[:-len(postFix)] + args.lang3 + ".png"
177-
path3 = os.path.join(args.inputdir2, path1[len(args.inputdir1)+1:])
176+
file3 = f"{file1.removesuffix(postFix)}_{args.lang3}.png"
177+
path3 = os.path.join(args.inputdir3, path1[len(args.inputdir1)+1:])
178178
else:
179179
file3 = ""
180180
path3 = None
@@ -192,13 +192,15 @@ def main(args=None):
192192
diffRms1 = diffRms2 = diffRms3 = None
193193

194194
if file1 and file2 and DIFF_ENABLED and args.CREATE_DIFF:
195-
diffPath1 = fullPath1[0:-8] + "_" + args.lang1 + "-1_vs_" + args.lang2 + "-2_diff.png"
195+
basePath = fullPath1.removesuffix(postFix)
196+
diffPath1 = f"{basePath}_{args.lang1}-1_vs_{args.lang2}-2_diff.png"
196197
diffRms1 = computeDiff(fullPath1, fullPath2, diffPath1)
197198

198199
if useThirdLang and file1 and file3 and DIFF_ENABLED and args.CREATE_DIFF:
199-
diffPath2 = fullPath1[0:-8] + "_" + args.lang1 + "-1_vs_" + args.lang3 + "-3_diff.png"
200+
basePath = fullPath1.removesuffix(postFix)
201+
diffPath2 = f"{basePath}_{args.lang1}-1_vs_{args.lang3}-3_diff.png"
200202
diffRms2 = computeDiff(fullPath1, fullPath3, diffPath2)
201-
diffPath3 = fullPath1[0:-8] + "_" + args.lang2 + "-2_vs_" + args.lang3 + "-3_diff.png"
203+
diffPath3 = f"{basePath}_{args.lang2}-2_vs_{args.lang3}-3_diff.png"
202204
diffRms3 = computeDiff(fullPath2, fullPath3, diffPath3)
203205

204206
if args.error >= 0:

0 commit comments

Comments
 (0)