Skip to content

Commit 58d305c

Browse files
gh-136438: Make sure test_generated_cases pass with all optimization levels (#136594)
Fix the `test_generated_cases` to work with `-O` or `-OO` flags. Previously, `test_generated_cases` was catching an `AssertionError` while `Tools/cases_generator/optimizer_generator.py` used an `assert` statement. This approach semantically incorrect, no one should trying to catch an `AssertionError`! Now the `assert` statement has been replaced with an explicit `raise ValueError(...)` and the corresponding `self.assertRaisesRegex(AssertionError, ...)` has been updated to catch a `ValueError` instead.
1 parent 658599c commit 58d305c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Lib/test/test_generated_cases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,7 @@ def test_missing_override_failure(self):
20372037
"""
20382038
output = """
20392039
"""
2040-
with self.assertRaisesRegex(AssertionError, "All abstract uops"):
2040+
with self.assertRaisesRegex(ValueError, "All abstract uops"):
20412041
self.run_cases_test(input, input2, output)
20422042

20432043
def test_validate_uop_input_length_mismatch(self):

Tools/cases_generator/optimizer_generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ def generate_abstract_interpreter(
398398
out.emit("\n")
399399
base_uop_names = set([uop.name for uop in base.uops.values()])
400400
for abstract_uop_name in abstract.uops:
401-
assert (
402-
abstract_uop_name in base_uop_names
403-
), f"All abstract uops should override base uops, but {abstract_uop_name} is not."
401+
if abstract_uop_name not in base_uop_names:
402+
raise ValueError(f"All abstract uops should override base uops, "
403+
"but {abstract_uop_name} is not.")
404404

405405
for uop in base.uops.values():
406406
override: Uop | None = None

0 commit comments

Comments
 (0)