sagemath/sage

sage.doctest: Make imports more specific; make global environment for tests customizable

Closed this issue · 25 comments

We prepare the Sage doctesting module for running in environments where sage.all is not available (#29705).

  1. An explicit import in sage.doctest.parsing:
# We need to import from sage.all to avoid circular imports.
from sage.all import RealIntervalField
RIFtol = RealIntervalField(1044)
  1. We make the global environment for tests customizable in sage.doctest.forker: in init_sage:
    import sage.repl.ipython_kernel.all_jupyter

and again in DocTestTask._run:

            # Import Jupyter globals to doctest the Jupyter
            # implementation of widgets and interacts
            import sage.repl.ipython_kernel.all_jupyter as sage_all

... which is

"""
All imports for Jupyter
"""

from sage.all_cmdline import *

from .widgets_sagenb import (input_box, text_control, slider,
        range_slider, checkbox, selector, input_grid, color_selector)
from .interact import interact

This is exposed by the new sage-runtest option --environment.

For example, #29865 defines modules such as sage.all__sage_objects. We would invoke sage -t --environment=sage.all__sage_objects to test against this global environment.

  1. We ignore errors importing sage.interfaces.

Depends on #29940

CC: @tscrim @fchapoton @orlitzky @kliem @kiwifb

Component: refactoring

Author: Matthias Koeppe

Branch/Commit: 2a602df

Reviewer: Jonathan Kliem

Issue created by migration from https://trac.sagemath.org/ticket/29922

Description changed:

--- 
+++ 
@@ -1 +1,8 @@
+In `sage.doctest.parsing`:
 
+```
+# We need to import from sage.all to avoid circular imports.
+from sage.all import RealIntervalField
+RIFtol = RealIntervalField(1044)
+```
+

Description changed:

--- 
+++ 
@@ -1,4 +1,6 @@
-In `sage.doctest.parsing`:
+We prepare the Sage doctesting module for running in environments where `sage.all` is not available (#29705).
+
+1. A rather disturbing, graphic import in `sage.doctest.parsing`:
 
 ```
 # We need to import from sage.all to avoid circular imports.
@@ -6,3 +8,26 @@
 RIFtol = RealIntervalField(1044)
 ```
 
+
+2. We need to make the global environment for tests customizable in `sage.doctest.forker`:
+
+```
+            # Import Jupyter globals to doctest the Jupyter
+            # implementation of widgets and interacts
+            import sage.repl.ipython_kernel.all_jupyter as sage_all
+```
+... which is
+
+```
+"""
+All imports for Jupyter
+"""
+
+from sage.all_cmdline import *
+
+from .widgets_sagenb import (input_box, text_control, slider,
+        range_slider, checkbox, selector, input_grid, color_selector)
+from .interact import interact
+```
+
+

Description changed:

--- 
+++ 
@@ -9,7 +9,12 @@
 ```
 
 
-2. We need to make the global environment for tests customizable in `sage.doctest.forker`:
+2. We need to make the global environment for tests customizable in `sage.doctest.forker`: in `init_sage`:
+
+```
+    import sage.repl.ipython_kernel.all_jupyter
+```
+   and again in `DocTestTask._run`:
 
 ```
             # Import Jupyter globals to doctest the Jupyter

Description changed:

--- 
+++ 
@@ -35,4 +35,7 @@
 from .interact import interact
 ```
 
+For example, #29865 defines modules such as `sage.all__sage_objects`. We would invoke `sage -t --environment=sage.all__sage_objects` to test against this global environment.
 
+
+
comment:6

Probably we will need to disable the real tolerance feature when we want to test the lowest layers such as sage-objects to avoid having to pull in the whole numeric tower.

Branch pushed to git repo; I updated commit sha1. New commits:

7d86833sage.doctest.forker: Do not fail if sage.interfaces.quit cannot be imported
comment:10

Cc'ing you because this ticket is touching the same files that will need to be modified if you want to implement the option for #29935

Branch pushed to git repo; I updated commit sha1. New commits:

b3ab1c1src/bin/sage-runtests: Add --environment option

Changed commit from 7d86833 to b3ab1c1

Changed commit from b3ab1c1 to 66572cd

Branch pushed to git repo; I updated commit sha1. New commits:

9757019sage.doctest.forker.DocTestTask._run: Remove special support for sagenb
66572cdWIP

Dependencies: #29940

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

6bec225sage.doctest.forker.DocTestTask._run: Remove special support for sagenb
ad00b40sage.doctest, src/bin/sage-runtests: Remove handling of sagenb
faef943Merge branch 't/29940/sage_doctest__remove_handling_of_sagenb' into t/29922/sage_doctest__make_imports_more_specific__make_global_environment_for_tests_customizable
67db00fsrc/bin/sage-runtests, sage.doctest: Handle option --environment

Changed commit from 66572cd to 67db00f

Author: Matthias Koeppe

Description changed:

--- 
+++ 
@@ -1,6 +1,6 @@
 We prepare the Sage doctesting module for running in environments where `sage.all` is not available (#29705).
 
-1. A rather disturbing, graphic import in `sage.doctest.parsing`:
+1. An explicit import in `sage.doctest.parsing`:
 
 ```
 # We need to import from sage.all to avoid circular imports.
@@ -9,7 +9,7 @@
 ```
 
 
-2. We need to make the global environment for tests customizable in `sage.doctest.forker`: in `init_sage`:
+2. We make the global environment for tests customizable in `sage.doctest.forker`: in `init_sage`:
 
 ```
     import sage.repl.ipython_kernel.all_jupyter
@@ -35,7 +35,11 @@
 from .interact import interact
 ```
 
-For example, #29865 defines modules such as `sage.all__sage_objects`. We would invoke `sage -t --environment=sage.all__sage_objects` to test against this global environment.
+   This is exposed by the new `sage-runtest` option `--environment`.
+
+   For example, #29865 defines modules such as `sage.all__sage_objects`. We would invoke `sage -t --environment=sage.all__sage_objects` to test against this global environment.
 
 
+3. We ignore errors importing `sage.interfaces`.
 
+

Changed commit from 67db00f to 2a602df

Branch pushed to git repo; I updated commit sha1. New commits:

9bf6f88sage.doctest.control: Remove unused import
89988cfsage.doctest.forker.init_sage: Actually handle the optional arg
2664865sage.misc.package: Do not fail if SAGE_PKGS, SAGE_SPKG_INST do not exist
2a602dfsage.repl.display.fancy_repr: Do not fail if sage.matrix.matrix1 canno be imported
comment:19

Ready for review

kliem commented

Reviewer: Jonathan Kliem

kliem commented
comment:21

This looks reasonable, it does not break the doctesting framework and the added doctests pass.

comment:22

Thank you.