Helpers¶
Helpers functions that implement boiler plate code used together with
Asserter. It provides support for
easier Input/Output tests.
- class capture_output¶
This context manager allows you to capture the output printed to
stdoutin aio.StringIObuffer.>>> from cg_feedback_helpers import helpers >>> with helpers.capture_output() as buffer: ... print("Hi") >>> print(f"Output was: {buffer.getvalue()}") Output was: Hi
- class as_stdin¶
This context manager allows you to provide input to a program by passing in the input lines. It temporarily replaces the standard
stdinbuffer with one containing the specified input lines.>>> from cg_feedback_helpers import helpers >>> with helpers.as_stdin("Hi"): ... print(input()) Hi
- get_lines_from_buffer(buffer, *, extra_splits=None)¶
Boiler plate to make the use of
capture_outputeasier. By providing the buffer fromcapture_outputyou will get the output lines, split on the new line, and all lines with just white spaces filtered out.- Parameters:
- Returns:
A list containing the output lines, with the empty lines filtered out.
- Return type:
>>> from cg_feedback_helpers import helpers >>> with helpers.capture_output() as buffer: ... print("something.goes\nout") >>> print(helpers.get_lines_from_buffer(buffer, extra_splits=[r"\."])) ['something', 'goes', 'out']