Feedback Writers

Implements the feedback writers providing the output to the user.

class Writer

Base writer interface.

Handles the opening and closing of resouces (files, file descriptors, streams, and so on).

Also defines how the output is provided to the user. Current implementations are:

Parameters:

is_atv2True if the run environment is AutoTest V2.

Methods

finalize

Cleans up the resources used by the writer.

write

Defines how the feedback is provided to the user.

abstract finalize()

Cleans up the resources used by the writer.

Asserter calls this method when exiting to make sure no open handles are left.

Return type:

None

abstract write(cond, maker, positive_feedback, negative_feedback)

Defines how the feedback is provided to the user.

Parameters:
  • cond (bool) – The condition that must be satisfied for the assertion to pass. If resolved to True, the positive feedback (or its default) is output, otherwise the negative feedback (or its default) is output.

  • maker (Callable[[Union[str, NoFeedback, None], FeedbackType], Union[str, NoFeedback]]) – The feedback maker function.

  • positive_feedback (Union[str, NoFeedback, None]) – The positive feedback override.

  • negative_feedback (Union[str, NoFeedback, None]) – The negative feedback override.

Return type:

None

class StructuredOutputWriter

Writer that uses structured output to report feedback.

It also rises a FeedbackAssertionError without message in case of failures.

If the code is running on ATv2, or the environment variable CG_FEEDBACK_HELPERS_TRUNCATE is set, it uses the cg truncate command under the hood.

class ExceptionsWriter

Writer that uses exceptions to report negative feedback.

Positive feedback is printed to standard output.

This can also be used as a debug writer as the text is clearly written in the output, instead of formatted for structured output feedback message format.

class FeedbackAssertionError

Exception raised when an assertion fails.

Inherits from SystemExit to make the execution exit gracefully.

NO_FEEDBACK passes 1 to the constructor of SystemExit.

Parameters:

feedback (Union[str, NoFeedback]) – The feedback message to display the user.