No project description provided
Project description
cg_feedback_helpers
This package provides functionality to provide feedback messages. It
mainly provides the class Asserter
. The Asserter
has a number of
methods that are documented on the official
docs, which allow
to run assertions. Each assertion can provide either positive or negative
feedback. A few helpers are also provided to aid with input and output
coupled when running assertions. At the end of a run, call
Asserter::emit_success
to guarantee the user receives some feedback
if everything was correct.
The package outputs feedback in the following format:
{
"tag": "feedback",
"contents": [
{
"value": <your feedback message>,
"sentiment": <"positive" | "negative">
},
]
}
Usage:
The following example shows how the asserter can be used to check that
the function greet_user
responds with the correct output to a user
input.
from cg_feedback_helpers import asserter, helpers
def greet_user():
name = input()
print(f"Hi {name}")
with helpers.capture_output() as buffer, helpers.as_stdin("John"):
greet_user()
output = helpers.get_lines_from_buffer(buffer)
asserter.has_length(output, 1)
asserter.equals(output[0], "John")
asserter.emit_success()
The output of which will be:
{"tag":"feedback","contents":[{"value":"Got expected length 1","sentiment":"positive"}]}
{"tag":"feedback","contents":[{"value":"Got expected value Hi John","sentiment":"positive"}]}
{"tag":"feedback","contents":[{"value":"Everything was correct! Good job!","sentiment":"positive"}]}
Module contains:
Asserter
class, of which the default messages produced can be configured, as well as its failure behavior (either using exceptions orsys.exit
);helpers
to make it easier to work with input/output tests.
Limitation:
The module currently does not support markdown feedback, nor the
neutral
sentiment.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cg_feedback_helpers-2024.1.16.1247.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbaaf32b7ddb78b2df340bd242c28af0e6a88f2c35bcd40998362c1d9a74949e |
|
MD5 | 26c87ebf5d3afb03be69ce8ee0f7fbef |
|
BLAKE2b-256 | 2dc10a9925ff8c50fd65522f7a06ceb882bfd441d8569c4b69f8acb015fa4181 |
Hashes for cg_feedback_helpers-2024.1.16.1247-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3600888ffc8339d9156b8714ae1a293a311083f83b34942e2ba44f5c70046626 |
|
MD5 | 1d1f27af355cda27ead8654f310e7e8e |
|
BLAKE2b-256 | f4bcc9b7c82f75e292e9082ea20f04a0a87f4e5c6de8252deaeb2eac444b2669 |