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

Commit

Permalink
src/bin/sage-runtests, sage.doctest: Handle option --environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Jun 22, 2020
1 parent faef943 commit 67db00f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bin/sage-runtests
Expand Up @@ -72,7 +72,7 @@ if __name__ == "__main__":
parser.add_option("--randorder", type=int, metavar="SEED", help="randomize order of tests")
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")
parser.add_option("--environment", type=str, default=None, help="name of a module that provides the global environment for tests")
parser.add_option("--environment", type=str, default="sage.repl.ipython_kernel.all_jupyter", help="name of a module that provides the global environment for tests")

parser.add_option("-i", "--initial", action="store_true", default=False, help="only show the first failure in each file")
parser.add_option("--exitfirst", action="store_true", default=False, help="end the test run immediately after the first failure or unexpected exception")
Expand Down
20 changes: 20 additions & 0 deletions src/sage/doctest/control.py
Expand Up @@ -99,6 +99,7 @@ def __init__(self, **kwds):
self.randorder = None
self.global_iterations = 1 # sage-runtests default is 0
self.file_iterations = 1 # sage-runtests default is 0
self.environment = "sage.repl.ipython_kernel.all_jupyter"
self.initial = False
self.exitfirst = False
self.force_lib = False
Expand Down Expand Up @@ -497,6 +498,25 @@ def _repr_(self):
"""
return "DocTest Controller"

def load_environment(self):
"""
Return the module that provides the global environment.
EXAMPLES::
sage: from sage.doctest.control import DocTestDefaults, DocTestController
sage: DC = DocTestController(DocTestDefaults(), [])
sage: 'BipartiteGraph' in DC.load_environment().__dict__
True
sage: DC = DocTestController(DocTestDefaults(environment='sage.doctest.all'), [])
sage: 'BipartiteGraph' in DC.load_environment().__dict__
False
sage: 'run_doctests' in DC.load_environment().__dict__
True
"""
from importlib import import_module
return import_module(self.options.environment)

def load_stats(self, filename):
"""
Load stats from the most recent run(s).
Expand Down
7 changes: 4 additions & 3 deletions src/sage/doctest/forker.py
Expand Up @@ -88,7 +88,7 @@



def init_sage():
def init_sage(environment=None):
"""
Import the Sage library.
Expand Down Expand Up @@ -1630,7 +1630,7 @@ def __init__(self, controller):
<sage.doctest.forker.DocTestDispatcher object at ...>
"""
self.controller = controller
init_sage()
init_sage(controller.options.environment)

def serial_dispatch(self):
"""
Expand Down Expand Up @@ -2510,7 +2510,8 @@ def _run(self, runner, options, results):
"""
# Import Jupyter globals to doctest the Jupyter
# implementation of widgets and interacts
import sage.repl.ipython_kernel.all_jupyter as sage_all
from importlib import import_module
sage_all = import_module(options.environment)
dict_all = sage_all.__dict__
# Remove '__package__' item from the globals since it is not
# always in the globals in an actual Sage session.
Expand Down

0 comments on commit 67db00f

Please sign in to comment.