The backend used for doctests¶
This backend is active during doctests. It should mimic the behavior of the IPython command line as close as possible. Without actually launching image viewers, of course.
EXAMPLES:
sage: from sage.repl.rich_output import get_display_manager
sage: get_display_manager()
The Sage display manager using the doctest backend
>>> from sage.all import *
>>> from sage.repl.rich_output import get_display_manager
>>> get_display_manager()
The Sage display manager using the doctest backend
- class sage.repl.rich_output.backend_doctest.BackendDoctest[source]¶
Bases:
BackendBase
- default_preferences()[source]¶
Return the backend’s display preferences.
Matches the IPython command line display preferences to keep the differences between that and the doctests to a minimum.
OUTPUT:
Instance of
DisplayPreferences
.EXAMPLES:
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline sage: backend = BackendIPythonCommandline() sage: backend.default_preferences() Display preferences: * align_latex is not specified * graphics is not specified * supplemental_plot = never * text is not specified
>>> from sage.all import * >>> from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline >>> backend = BackendIPythonCommandline() >>> backend.default_preferences() Display preferences: * align_latex is not specified * graphics is not specified * supplemental_plot = never * text is not specified
- display_immediately(plain_text, rich_output)[source]¶
Display object immediately.
INPUT:
Same as
displayhook()
.EXAMPLES:
The following example does not call the displayhook. More precisely, the
show()
method returnsNone
which is ignored by the displayhook. When running the example on a Sage display backend capable of displaying graphics outside of the displayhook, the plot is still shown. Nothing is shown during doctests:sage: plt = plot(sin) # needs sage.plot sage.symbolic sage: plt # needs sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive sage: plt.show() # needs sage.plot sage.symbolic sage: from sage.repl.rich_output import get_display_manager sage: dm = get_display_manager() sage: dm.display_immediately(plt) # indirect doctest # needs sage.plot sage.symbolic
>>> from sage.all import * >>> plt = plot(sin) # needs sage.plot sage.symbolic >>> plt # needs sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive >>> plt.show() # needs sage.plot sage.symbolic >>> from sage.repl.rich_output import get_display_manager >>> dm = get_display_manager() >>> dm.display_immediately(plt) # indirect doctest # needs sage.plot sage.symbolic
- displayhook(plain_text, rich_output)[source]¶
Display object from displayhook.
INPUT:
plain_text
– instance ofOutputPlainText
. The plain text version of the output.rich_output
– instance of an output container class (subclass ofOutputBase
). Guaranteed to be one of the output containers returned fromsupported_output()
, possibly the same asplain_text
.
EXAMPLES:
This ends up calling the displayhook:
sage: plt = plot(sin) # needs sage.plot sage.symbolic sage: plt # needs sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive sage: plt.show() # needs sage.plot sage.symbolic sage: from sage.repl.rich_output import get_display_manager sage: dm = get_display_manager() sage: dm.displayhook(plt) # indirect doctest # needs sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive
>>> from sage.all import * >>> plt = plot(sin) # needs sage.plot sage.symbolic >>> plt # needs sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive >>> plt.show() # needs sage.plot sage.symbolic >>> from sage.repl.rich_output import get_display_manager >>> dm = get_display_manager() >>> dm.displayhook(plt) # indirect doctest # needs sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive
- install(**kwds)[source]¶
Switch to the doctest backend.
This method is being called from within
switch_backend()
. You should never call it by hand.INPUT:
**kwds
– none of the optional keyword arguments are used in the doctest backend
EXAMPLES:
sage: from sage.repl.rich_output.backend_doctest import BackendDoctest sage: backend = BackendDoctest() sage: backend.install() sage: backend.uninstall()
>>> from sage.all import * >>> from sage.repl.rich_output.backend_doctest import BackendDoctest >>> backend = BackendDoctest() >>> backend.install() >>> backend.uninstall()
- supported_output()[source]¶
Return the supported output types.
OUTPUT:
Set of subclasses of
OutputBase
, the supported output container types.EXAMPLES:
sage: from sage.repl.rich_output.backend_doctest import BackendDoctest sage: from sage.repl.rich_output.output_catalog import * sage: backend = BackendDoctest() sage: OutputPlainText in backend.supported_output() True sage: OutputSceneJmol in backend.supported_output() True
>>> from sage.all import * >>> from sage.repl.rich_output.backend_doctest import BackendDoctest >>> from sage.repl.rich_output.output_catalog import * >>> backend = BackendDoctest() >>> OutputPlainText in backend.supported_output() True >>> OutputSceneJmol in backend.supported_output() True
- uninstall()[source]¶
Switch away from the doctest backend.
This method is being called from within
switch_backend()
. You should never call it by hand.EXAMPLES:
sage: from sage.repl.rich_output.backend_doctest import BackendDoctest sage: backend = BackendDoctest() sage: backend.install() sage: backend.uninstall()
>>> from sage.all import * >>> from sage.repl.rich_output.backend_doctest import BackendDoctest >>> backend = BackendDoctest() >>> backend.install() >>> backend.uninstall()
- validate(rich_output)[source]¶
Perform checks on
rich_output
.INPUT:
rich_output
– instance of a subclass ofOutputBase
OUTPUT: an assertion is triggered if
rich_output
is invalidEXAMPLES:
sage: from sage.repl.rich_output import get_display_manager sage: dm = get_display_manager() sage: invalid = dm.types.OutputImagePng('invalid') sage: backend = dm._backend; backend doctest sage: backend.validate(invalid) Traceback (most recent call last): ... AssertionError sage: backend.validate(dm.types.OutputPlainText.example()) sage: backend.validate(dm.types.OutputAsciiArt.example()) sage: backend.validate(dm.types.OutputLatex.example()) sage: backend.validate(dm.types.OutputImagePng.example()) sage: backend.validate(dm.types.OutputImageGif.example()) sage: backend.validate(dm.types.OutputImageJpg.example()) sage: backend.validate(dm.types.OutputImageSvg.example()) sage: backend.validate(dm.types.OutputImagePdf.example()) sage: backend.validate(dm.types.OutputImageDvi.example()) sage: backend.validate(dm.types.OutputSceneJmol.example()) sage: backend.validate(dm.types.OutputSceneWavefront.example()) sage: backend.validate(dm.types.OutputSceneCanvas3d.example()) sage: backend.validate(dm.types.OutputVideoOgg.example()) sage: backend.validate(dm.types.OutputVideoWebM.example()) sage: backend.validate(dm.types.OutputVideoMp4.example()) sage: backend.validate(dm.types.OutputVideoFlash.example()) sage: backend.validate(dm.types.OutputVideoMatroska.example()) sage: backend.validate(dm.types.OutputVideoAvi.example()) sage: backend.validate(dm.types.OutputVideoWmv.example()) sage: backend.validate(dm.types.OutputVideoQuicktime.example())
>>> from sage.all import * >>> from sage.repl.rich_output import get_display_manager >>> dm = get_display_manager() >>> invalid = dm.types.OutputImagePng('invalid') >>> backend = dm._backend; backend doctest >>> backend.validate(invalid) Traceback (most recent call last): ... AssertionError >>> backend.validate(dm.types.OutputPlainText.example()) >>> backend.validate(dm.types.OutputAsciiArt.example()) >>> backend.validate(dm.types.OutputLatex.example()) >>> backend.validate(dm.types.OutputImagePng.example()) >>> backend.validate(dm.types.OutputImageGif.example()) >>> backend.validate(dm.types.OutputImageJpg.example()) >>> backend.validate(dm.types.OutputImageSvg.example()) >>> backend.validate(dm.types.OutputImagePdf.example()) >>> backend.validate(dm.types.OutputImageDvi.example()) >>> backend.validate(dm.types.OutputSceneJmol.example()) >>> backend.validate(dm.types.OutputSceneWavefront.example()) >>> backend.validate(dm.types.OutputSceneCanvas3d.example()) >>> backend.validate(dm.types.OutputVideoOgg.example()) >>> backend.validate(dm.types.OutputVideoWebM.example()) >>> backend.validate(dm.types.OutputVideoMp4.example()) >>> backend.validate(dm.types.OutputVideoFlash.example()) >>> backend.validate(dm.types.OutputVideoMatroska.example()) >>> backend.validate(dm.types.OutputVideoAvi.example()) >>> backend.validate(dm.types.OutputVideoWmv.example()) >>> backend.validate(dm.types.OutputVideoQuicktime.example())