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>
This commit is contained in:
Alessandro Gatti
2026-01-15 20:33:58 +01:00
parent e66a1a3f4a
commit eae83df201
2 changed files with 6 additions and 0 deletions

View File

@@ -43,6 +43,9 @@ for function_name, function, test_vals in functions:
ans = "{:.5g}".format(function(value))
except ValueError as e:
ans = str(e)
if ans.startswith("expected a "):
# CPython 3.14 changed messages to be more detailed; convert them back to simple ones
ans = "math domain error"
print("{}({:.5g}) = {}".format(function_name, value, ans))
tuple_functions = [

View File

@@ -51,6 +51,9 @@ for function_name, function, test_vals in functions:
ans = "{:.4g}".format(function(value))
except ValueError as e:
ans = str(e)
if ans.startswith("expected a "):
# CPython 3.14 changed messages to be more detailed; convert them back to simple ones
ans = "math domain error"
# a tiny error in REPR_C value for 1.5204998778 causes a wrong rounded value
if is_REPR_C and function_name == "erfc" and ans == "1.521":
ans = "1.52"