Closed rwst closed 6 years ago
The lazy_import is not even necessary for trigger.
Description changed:
---
+++
@@ -47,4 +47,4 @@
The reason why the doctest fails is that, despite fixing the random seed, the functions and symbols picked by random_expr
are different. This, at some point in the buildup of the expression, leads to the sub-expression kronecker_delta(-0.6165326641917295 + 0.15117833554974136*I, e)
which immediately evaluates to 0
. The 0
progresses eventually into a denominator, causing the error. random_expr
is not written to avoid such errors if they happen, nor does it avoid other exceptions thrown. The author of the doctest apparently just chose a random seed that happens to not throw errors.
-Of course the actual bug is that random_expr
changes behaviour when unrelated code is changed.
+A fix that filters out zero divisions and intended exceptions thrown from code in functions
before returning the expression would be the best solution (but it doesn't handle runtime errors from Pynac).
Description changed:
---
+++
@@ -1,50 +1,18 @@
-Applying the following minimal patch makes a completely unrelated doctest fail:
+The docs for `random_expr` read:
-diff --git a/src/sage/functions/all.py b/src/sage/functions/all.py -index e7f1ea0efa..d26f83f2f9 100644 ---- a/src/sage/functions/all.py -+++ b/src/sage/functions/all.py -@@ -4,7 +4,7 @@ from sage.misc.lazy_import import lazy_import
-+class Function_Fresnel_test1(BuiltinFunction): -+ def init(self): -+ BuiltinFunction.init(self, "fresnel_test1") -+ -+fresnel_test1 = Function_Fresnel_test1() -+ -+class Function_Fresnel_test2(BuiltinFunction): -+ def init(self): -+ BuiltinFunction.init(self, "fresnel_test2") -+ -+fresnel_test2 = Function_Fresnel_test2() -+
an erroneous expression (such as a division by zero).
+It has the following doctest:
-File "src/sage/symbolic/random_tests.py", line 265, in sage.symbolic.random_tests.? -Failed example:
-The reason why the doctest fails is that, despite fixing the random seed, the functions and symbols picked by `random_expr` are different. This, at some point in the buildup of the expression, leads to the sub-expression `kronecker_delta(-0.6165326641917295 + 0.15117833554974136*I, e)` which immediately evaluates to `0`. The `0` progresses eventually into a denominator, causing the error. `random_expr` is not written to avoid such errors if they happen, nor does it avoid other exceptions thrown. The author of the doctest apparently just chose a random seed that happens to not throw errors.
+Despite having a random seed the test run changes with every new builtin function introduced in `sage/functions` because the global function list changes. That's why the test was marked random. The problem however is that the test can even raise an error, as the docs state above. The"`random`" keyword does not catch this, and it would make the test useless anyway.
-A fix that filters out zero divisions and intended exceptions thrown from code in functions
before returning the expression would be the best solution (but it doesn't handle runtime errors from Pynac).
+Tests are meant to test the functionality of the associated code so the test and perhaps random_expr
should be rewritten such that it allows a test that does not change with a changed global function list.
Author: Ralf Stephan
I don't fully understand the context, but the change looks reasonable and really unlikely to break anything—and this ticket has been languishing for months.
Reviewer: Marc Mezzarobba
Changed branch from u/rws/fix_inherently_failing_random_expr_doctest to a17755c
Thanks. Oddly enough, #24212 depends on this.
The docs for
random_expr
read:It has the following doctest:
Despite having a random seed the test run changes with every new builtin function introduced in
sage/functions
because the global function list changes. That's why the test was marked random. The problem however is that the test can even raise an error, as the docs state above. The"random
" keyword does not catch this, and it would make the test useless anyway.Tests are meant to test the functionality of the associated code so the test and perhaps
random_expr
should be rewritten such that it allows a test that does not change with a changed global function list.Component: symbolics
Author: Ralf Stephan
Branch:
a17755c
Reviewer: Marc Mezzarobba
Issue created by migration from https://trac.sagemath.org/ticket/24425