Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'public/29962-reb2' of git://trac.sagemath.org/sage into…
Browse files Browse the repository at this point in the history
… public/29936-reb
  • Loading branch information
Jonathan Kliem committed Jul 12, 2020
2 parents 5e913d7 + 1d99129 commit 8292b04
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ usage_advanced() {
echo " labeled \"# optional\" or labeled"
echo " \"# optional tag\" for any of the tags given."
echo " --randorder[=seed] -- randomize order of tests"
echo " --random-seed[=seed] -- random seed for fuzzing doctests"
echo " --new -- only test files modified since last commit"
echo " --initial -- only show the first failure per block"
echo " --debug -- drop into PDB after an unexpected error"
Expand Down
1 change: 1 addition & 0 deletions src/bin/sage-runtests
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ if __name__ == "__main__":
'if "build" is listed, will also run tests specific to Sage\'s build/packaging system; '
'if set to "all", then all tests will be run')
parser.add_option("--randorder", type=int, metavar="SEED", help="randomize order of tests")
parser.add_option("--random-seed", dest="random_seed", type=int, metavar="SEED", help="random seed for fuzzing doctests")
parser.add_option("--global-iterations", "--global_iterations", type=int, default=0, help="repeat the whole testing process this many times")
parser.add_option("--file-iterations", "--file_iterations", type=int, default=0, help="repeat each file this many times, stopping on the first failure")

Expand Down
27 changes: 26 additions & 1 deletion src/doc/en/developer/doctesting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,31 @@ You can also pass in an explicit amount of time::
Finally, you can disable any warnings about long tests with
``--warn-long 0``.

Doctests may start from a random seed::

[kliem@sage sage-9.2]$ sage -t --warn-long 89.5 --random-seed=112986622569797306072457879734474628454 src/sage/doctest/tests/random_seed.rst
Running doctests with ID 2020-06-23-23-24-28-14a52269.
...
Doctesting 1 file.
sage -t --warn-long 89.5 --random-seed=112986622569797306072457879734474628454 src/sage/doctest/tests/random_seed.rst
**********************************************************************
File "src/sage/doctest/tests/random_seed.rst", line 3, in sage.doctest.tests.random_seed
Failed example:
randint(5, 10)
Expected:
9
Got:
8
**********************************************************************
1 item had failures:
1 of 2 in sage.doctest.tests.random_seed
[1 test, 1 failure, 0.00 s]
----------------------------------------------------------------------
sage -t --warn-long 89.5 --random-seed=112986622569797306072457879734474628454 src/sage/doctest/tests/random_seed.rst # 1 doctest failed
----------------------------------------------------------------------
Total time for all tests: 0.0 seconds
cpu time: 0.0 seconds
cumulative wall time: 0.0 seconds

.. _section-optional-doctest-flag:

Expand Down Expand Up @@ -861,7 +886,7 @@ If you want Sage to detect external software or other capabilities
(such as magma, latex, internet) automatically and run all of the
relevant tests, then add ``external``::

$ sage -t --optional=external src/sage/rings/real_mpfr.pyx
$ sage -t --optional=external src/sage/rings/real_mpfr.pyx
Running doctests with ID 2016-03-16-14-10-21-af2ebb67.
Using --optional=external
External software to be detected: cplex,gurobi,internet,latex,macaulay2,magma,maple,mathematica,matlab,octave,scilab
Expand Down
4 changes: 4 additions & 0 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, **kwds):
self.long = False
self.warn_long = None
self.randorder = None
self.random_seed = 0
self.global_iterations = 1 # sage-runtests default is 0
self.file_iterations = 1 # sage-runtests default is 0
self.initial = False
Expand Down Expand Up @@ -411,6 +412,9 @@ def __init__(self, options, args):
self.load_stats(options.stats_path)
self._init_warn_long()

if self.options.random_seed is None:
self.options.random_seed = 0

def __del__(self):
if getattr(self, 'logfile', None) is not None:
self.logfile.close()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def run(self, test, compileflags=None, out=None, clear_globs=True):
TestResults(failed=0, attempted=4)
"""
self.setters = {}
randstate.set_random_seed(0)
randstate.set_random_seed(self.options.random_seed)
warnings.showwarning = showwarning_with_traceback
self.running_doctest_digest = hashlib.md5()
self.test = test
Expand Down
2 changes: 2 additions & 0 deletions src/sage/doctest/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def report_head(self, source):
cmd += " --warn-long"
if warnlong != 1.0:
cmd += " %.1f"%(warnlong)
seed = self.controller.options.random_seed
cmd += " --random-seed={}".format(seed)
cmd += " " + source.printpath
return cmd

Expand Down
Loading

0 comments on commit 8292b04

Please sign in to comment.