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).
- 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)
- We make the global environment for tests customizable in
sage.doctest.forker: ininit_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.
- 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 JupyterDescription 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.
+
+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:
7d86833 | sage.doctest.forker: Do not fail if sage.interfaces.quit cannot be imported |
Commit: 7d86833
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:
b3ab1c1 | src/bin/sage-runtests: Add --environment option |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
6bec225 | sage.doctest.forker.DocTestTask._run: Remove special support for sagenb |
ad00b40 | sage.doctest, src/bin/sage-runtests: Remove handling of sagenb |
faef943 | Merge branch 't/29940/sage_doctest__remove_handling_of_sagenb' into t/29922/sage_doctest__make_imports_more_specific__make_global_environment_for_tests_customizable |
67db00f | src/bin/sage-runtests, sage.doctest: Handle option --environment |
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`.
+Branch pushed to git repo; I updated commit sha1. New commits:
9bf6f88 | sage.doctest.control: Remove unused import |
89988cf | sage.doctest.forker.init_sage: Actually handle the optional arg |
2664865 | sage.misc.package: Do not fail if SAGE_PKGS, SAGE_SPKG_INST do not exist |
2a602df | sage.repl.display.fancy_repr: Do not fail if sage.matrix.matrix1 canno be imported |
Ready for review
Reviewer: Jonathan Kliem
This looks reasonable, it does not break the doctesting framework and the added doctests pass.
Thank you.