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.backend_test 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.backend_test.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
class sage.repl.rich_output.backend_test.BackendTest

Bases: sage.repl.rich_output.backend_base.BackendBase

display_immediately(plain_text, rich_output)

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.backend_test import BackendTest
sage: backend = BackendTest()
sage: backend.display_immediately(plain_text, plain_text)
Example plain text output
OutputPlainText container
supported_output()

Return the outputs that are supported by the backend.

OUTPUT:

Iterable of output container classes. Only the TestOutputPlainText output 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.backend_test.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'>]
class sage.repl.rich_output.backend_test.TestObject

Bases: sage.structure.sage_object.SageObject

Test object with both _repr_() and _rich_repr_()

class sage.repl.rich_output.backend_test.TestOutputPlainText(*args, **kwds)

Bases: sage.repl.rich_output.output_basic.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 OutputPlainText constructor is used).

EXAMPLES:

sage: from sage.repl.rich_output.backend_test import TestOutputPlainText
sage: TestOutputPlainText()
Traceback (most recent call last):
AssertionError: cannot override constructor
print_to_stdout()

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.backend_test.TestOutputPlainText'>
sage: test_output.print_to_stdout()
123 [TestOutputPlainText]