Skip to main content

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()

Here is a more complete example:

from correction_helper import fail, student_code

with student_code():
    # Here, if the import fail, if the student prints, or try to exit,
    # it will be reported with a nice message in Markdown, and your process
    # will exit with code 1.
    from solution import missing_card


def check_deck(deck, expected):
    with student_code(print_expect=expected):
        # Here, if the function raises, if the student prints, or try to exit,
        # it will be reported too, and exit with code 1 too.
        # If the student prints what is expected to be returned
        # (the `print_expect` parameter), we told that, too.
        missing = missing_card(deck)
    if missing != expected:
        fail(f"""With the following deck (missing card is `{expected}`):

{code(deck, "text")}

You're returning:

{code(missing, "text")}
""")

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 print call by a 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

correction-helper-2021.4.4.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

correction_helper-2021.4.4-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file correction-helper-2021.4.4.tar.gz.

File metadata

  • Download URL: correction-helper-2021.4.4.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.3

File hashes

Hashes for correction-helper-2021.4.4.tar.gz
Algorithm Hash digest
SHA256 a173b13868e407766a254e3b8a5f988b323efb996bef30bc73e8b0fd68bad6c3
MD5 47062463af31daac4d3a55f3525758a1
BLAKE2b-256 f259a80028e2ae8311b9254074f8fdf6011f98bb945b1b2824cc5e23ce28bbff

See more details on using hashes here.

File details

Details for the file correction_helper-2021.4.4-py3-none-any.whl.

File metadata

  • Download URL: correction_helper-2021.4.4-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.3

File hashes

Hashes for correction_helper-2021.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7100420fdb4d7c5a3dd1837ef131789595085e1eaec4e6f2acd42dabf045272e
MD5 c02ca3d3934a527da3a069f022a72ea9
BLAKE2b-256 2c1f8791c9dab66c04f7b7ac43fa5ea731108328156f7531a9df18a99deac92f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page