Some helpers to help writing correction bots, use by hackinscience.org.
Project description
Correction Helper
Project
This is just a set of tools to help writing correction bots in Python for Python.
It is used for hackinscience, but could be used elsewhere.
Security considerations
Running student code is probably really unsafe, unless you trust your students not to drop you a backdoor.
This projet does not help with security in any ways, maybe take a
look at firejail if you have
trust issues (Yes you can use correction-helper
inside firejail
).
Usage
To install it, run: pip install correction-helper
.
In your checking code, you can use it like this:
The student_code
decorator
This decorator is aimed to catch most problems that could happen in student code, use it simply as:
with student_code():
their_function()
Find a more complete example in the examples/
directory.
Allowed parameters for student_code
, and their default values
exception_prefix="Got an exception:"
Printed right before the exception, if any.
friendly=False
To use, or not friendly-traceback instead of bare Python exceptions.
print_allowed=False
To allow the use to print to stdout / stderr, you can read what they printed using the value of the context manager:
with student_code(print_allowed=True) as run:
their_function()
assert run.stderr == ""
assert run.stdout == "42"
print_allowed
can be set to None
meaning "neither allowed nor
really denied": the student output will be printed along with the
print_prefix
, but it's not considered a failure.
print_prefix="Your code printed something (it should **not**):"
Message to display when they printed and print_allowed
was False
.
Good practices
Try first if the student code works, if it works, it works. Only if the code does not work, try to understand why.
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 correction-helper-2021.11.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ac675452dbede64be237aa509e8e5446f08854a6c37b0ab14dd82274cee4864 |
|
MD5 | f319182087fa46b86d9919ab8568cf84 |
|
BLAKE2b-256 | 7ce3b41a6b23d5ae2c83d23857f434d1cc11f4c2f7cc397fcead176679638fed |
Hashes for correction_helper-2021.11.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bdceef6c91c63a67b6c487f4da7e0b20f2836a9a09f0a93c6c38858a841870e |
|
MD5 | 80e03c87c1b8c37078283cd8d60d6905 |
|
BLAKE2b-256 | 41342685f835f41570029a04079eaaa6c44aa16ef577dd1ce3bb5f49dd3d9093 |