Skip to content

Commit eae83df

Browse files
committed
tests/float/math_fun: Fix domain error tests with CPython 3.14.
This commit makes tests exercising certain math functions' limit work when using CPython 3.14 to validate the tests' output. CPython 3.14 introduced more descriptive messages when math domain error conditions are encountered rather than a single generic message. This breaks the tests in question as MicroPython uses a single error message when reporting these conditions (both to closely follow CPython and to save firmware space). The math domain tests now look for an error pattern that is compatible with both CPython 3.14 and previous versions, converting messages in the newer format into the previous one. This makes the tests' behaviour under MicroPython comparable with CPython for the foreseeable future. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent e66a1a3 commit eae83df

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

tests/float/math_fun.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
ans = "{:.5g}".format(function(value))
4444
except ValueError as e:
4545
ans = str(e)
46+
if ans.startswith("expected a "):
47+
# CPython 3.14 changed messages to be more detailed; convert them back to simple ones
48+
ans = "math domain error"
4649
print("{}({:.5g}) = {}".format(function_name, value, ans))
4750

4851
tuple_functions = [

tests/float/math_fun_special.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
ans = "{:.4g}".format(function(value))
5252
except ValueError as e:
5353
ans = str(e)
54+
if ans.startswith("expected a "):
55+
# CPython 3.14 changed messages to be more detailed; convert them back to simple ones
56+
ans = "math domain error"
5457
# a tiny error in REPR_C value for 1.5204998778 causes a wrong rounded value
5558
if is_REPR_C and function_name == "erfc" and ans == "1.521":
5659
ans = "1.52"

0 commit comments

Comments
 (0)