Test Backend¶
This backend is only for doctesting purposes.
EXAMPLES:
We switch to the test backend for the remainder of this file:
sage: from sage.repl.rich_output import get_display_manager
sage: dm = get_display_manager()
sage: from sage.repl.rich_output.test_backend import BackendTest, TestObject
sage: doctest_backend = dm.switch_backend(BackendTest())
sage: dm
The Sage display manager using the test backend
sage: dm._output_promotions
{<class 'sage.repl.rich_output.output_basic.OutputPlainText'>:
 <class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>}
sage: dm.displayhook(1/2)
1/2 [TestOutputPlainText]
TestOutputPlainText container
sage: test = TestObject()
sage: test
called the _repr_ method
sage: dm.displayhook(test)
called the _rich_repr_ method [TestOutputPlainText]
TestOutputPlainText container
>>> from sage.all import *
>>> from sage.repl.rich_output import get_display_manager
>>> dm = get_display_manager()
>>> from sage.repl.rich_output.test_backend import BackendTest, TestObject
>>> doctest_backend = dm.switch_backend(BackendTest())
>>> dm
The Sage display manager using the test backend
>>> dm._output_promotions
{<class 'sage.repl.rich_output.output_basic.OutputPlainText'>:
 <class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>}
>>> dm.displayhook(Integer(1)/Integer(2))
1/2 [TestOutputPlainText]
TestOutputPlainText container
>>> test = TestObject()
>>> test
called the _repr_ method
>>> dm.displayhook(test)
called the _rich_repr_ method [TestOutputPlainText]
TestOutputPlainText container
- class sage.repl.rich_output.test_backend.BackendTest[source]¶
- Bases: - BackendBase- display_immediately(plain_text, rich_output)[source]¶
- Show output without going back to the command line prompt. - INPUT: - Same as - displayhook().- OUTPUT: - This method returns the rich output for doctesting convenience. The actual display framework ignores the return value. - EXAMPLES: - sage: from sage.repl.rich_output.output_basic import OutputPlainText sage: plain_text = OutputPlainText.example() sage: from sage.repl.rich_output.test_backend import BackendTest sage: backend = BackendTest() sage: backend.display_immediately(plain_text, plain_text) Example plain text output OutputPlainText container - >>> from sage.all import * >>> from sage.repl.rich_output.output_basic import OutputPlainText >>> plain_text = OutputPlainText.example() >>> from sage.repl.rich_output.test_backend import BackendTest >>> backend = BackendTest() >>> backend.display_immediately(plain_text, plain_text) Example plain text output OutputPlainText container 
 - supported_output()[source]¶
- Return the outputs that are supported by the backend. - OUTPUT: - Iterable of output container classes. Only the - TestOutputPlainTextoutput container is supported by the test backend.- EXAMPLES: - sage: display_manager = sage.repl.rich_output.get_display_manager() sage: backend = display_manager._backend sage: list(backend.supported_output()) [<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>] - >>> from sage.all import * >>> display_manager = sage.repl.rich_output.get_display_manager() >>> backend = display_manager._backend >>> list(backend.supported_output()) [<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>] - The output of this method is used by the display manager to set up the actual supported outputs. Compare: - sage: list(display_manager.supported_output()) [<class 'sage.repl.rich_output.output_basic.OutputPlainText'>] - >>> from sage.all import * >>> list(display_manager.supported_output()) [<class 'sage.repl.rich_output.output_basic.OutputPlainText'>] 
 
- class sage.repl.rich_output.test_backend.TestObject[source]¶
- Bases: - SageObject- Test object with both - _repr_()and- _rich_repr_()
- class sage.repl.rich_output.test_backend.TestOutputPlainText(*args, **kwds)[source]¶
- Bases: - OutputPlainText- Backend-specific subclass of the plain text output container. - Backends must not influence how the display system constructs output containers, they can only control how the output container is displayed. In particular, we cannot override the constructor (only the - OutputPlainTextconstructor is used).- EXAMPLES: - sage: from sage.repl.rich_output.test_backend import TestOutputPlainText sage: TestOutputPlainText() Traceback (most recent call last): ... AssertionError: cannot override constructor - >>> from sage.all import * >>> from sage.repl.rich_output.test_backend import TestOutputPlainText >>> TestOutputPlainText() Traceback (most recent call last): ... AssertionError: cannot override constructor - print_to_stdout()[source]¶
- Write the data to stdout. - This is just a convenience method to help with debugging. - EXAMPLES: - sage: from sage.repl.rich_output import get_display_manager sage: dm = get_display_manager() sage: test_output = dm.displayhook(123) 123 [TestOutputPlainText] sage: type(test_output) <class 'sage.repl.rich_output.test_backend.TestOutputPlainText'> sage: test_output.print_to_stdout() 123 [TestOutputPlainText] - >>> from sage.all import * >>> from sage.repl.rich_output import get_display_manager >>> dm = get_display_manager() >>> test_output = dm.displayhook(Integer(123)) 123 [TestOutputPlainText] >>> type(test_output) <class 'sage.repl.rich_output.test_backend.TestOutputPlainText'> >>> test_output.print_to_stdout() 123 [TestOutputPlainText]