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_prefix="Your code printed something (it should **not**):"
Message to display when they printed and print_allowed
was False
.
print_expect=None
String that you bet they'll print instead of return.
print_expect_message
Default value:
Your code printed what I expected it to return so maybe just replace your
return
statement.
This is the message displayed when you won you bet with
print_expect
, they printed instead of returning.
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.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce032821ee2643ff3218e3cb77c53076ecd9f1d7a25d505ffc493598779e3646 |
|
MD5 | fa353f3ddcddfc596188321fd977f728 |
|
BLAKE2b-256 | 2e4ec9505df37e3dab3ba89a746993c2bfacc19b506d01c0e88bb4bb9ea2dc44 |
Hashes for correction_helper-2021.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4facc0b057a835963680f74a2cc497349d362288c06080472721ba9e844f1e92 |
|
MD5 | 9bb6161702074df2d2d34ea85e78bb3a |
|
BLAKE2b-256 | b2d448ea35f61f0e6d0a365b816cf53484669adbf799942f333f37b174138fc5 |