Metadata-Version: 2.1
Name: jupyter-autograde
Version: 0.2.13
Summary: Unittesting & Grading of Jupyter Notebooks
Home-page: https://github.com/cssh-rwth/autograde
License: MIT
Keywords: jupyter,notebook,testing,grading
Author: Lukas Ochse
Maintainer: Chair for Computational Social Sciences and Humanities at RWTH Aachen University
Requires-Python: >=3.8,<3.10
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: Flask (>=1.1,<1.2)
Requires-Dist: Jinja2 (>=2.11,<2.12)
Requires-Dist: dataclasses-json (>=0.5,<0.6)
Requires-Dist: django-htmlmin-ajax (>=0.11,<0.12)
Requires-Dist: ipykernel (>=5.5,<5.6)
Requires-Dist: jupyter (>=1.0,<1.1)
Requires-Dist: matplotlib (>=3.4,<3.5)
Requires-Dist: numpy (>=1.21,<1.22)
Requires-Dist: pandas (>=1.2,<1.3)
Requires-Dist: scipy (>=1.7,<1.8)
Requires-Dist: seaborn (>=0.11,<0.12)
Project-URL: Repository, https://github.com/cssh-rwth/autograde
Description-Content-Type: text/x-rst

.. _auto-grade:

=========
autograde
=========

.. image:: https://github.com/cssh-rwth/autograde/workflows/test%20autograde/badge.svg
   :alt: autograde test
   :target: https://github.com/cssh-rwth/autograde/actions

.. image:: https://img.shields.io/pypi/v/jupyter-autograde?color=blue&label=jupyter-autograde
   :alt: autograde on PyPI
   :target: https://pypi.org/project/jupyter-autograde

*autograde* is a tool for testing *Jupyter* notebooks. Its features include execution of notebooks (optionally isolated via docker/podman) with consecutive unit testing of the final notebook state. On top of that, an audit mode allows for refining results (e.g. grading plots by hand). Eventually, *autograde* can summarize these results in human and machine readable formats.

setup
-----

Before installing *autograde* and in case you want to use it with a container backend, ensure `docker <https://www.docker.com/>`_ **or** `podman <https://podman.io/>`_ is available on your system.
We recommend podman as it runs rootless.

Now, in order to install *autograde*, run :code:`pip install jupyter-autograde`.
Alternatively, you can install *autograde* from source by cloning this repository and runing :code:`poetry install` within it.
This requires `poetry <https://python-poetry.org/docs/>`_ to be installed on your system!

Eventually, build the respective container image: :code:`python -m autograde build`.
**Note:** in order to build a container image, *autograde* must not be installed via *PyPI* but from source code!

usage
-----

Once installed, *autograde* can be invoked via the `autograde` command.
If you are using a virtual environment (which poetry does implicitly) you may have to activate it first.
Alternative methods:

- **`path/to/python -m autograde`** runs *autograde* with a specific python binary, e.g. the one of your virtual environment.
- **`poetry run autograde`** if you've installed *autograde* from source, you

testing
```````

*autograde* comes with some example files located in the :code:`demo/` subdirectory that we will use for now to illustrate the workflow. Run:

::

    python -m autograde test demo/test.py demo/notebook.ipynb --target /tmp --context demo/context

What happened? Let's first have a look at the arguments of *autograde*:

* :code:`demo/test.py` a script with test cases we want apply
* :code:`demo/notebook.ipynb` is the a notebook to be tested (here you may also specify a directory to be recursively searched for notebooks)
* The optional flag :code:`--target` tells *autograde* where to store results, :code:`/tmp` in our case, and the current working directory by default.
* The optional flag :code:`--context` specifies a directory that is mounted into the sandbox and may contain arbitrary files or subdirectories.
  This is useful when the notebook expects some external files to be present such as data sets.

The output is a compressed archive that is named something like :code:`results_[Lastname1,Lastname2,...]_XXXXXXXX.zip` and which has the following contents:

* :code:`artifacts/`: directory with all files that where created or modified by the tested notebook as well as rendered matplotlib plots.
* :code:`code.py`: code extracted from the notebook including :code:`stdout`/:code:`stderr` as comments
* :code:`notebook.ipynb`: an identical copy of the tested notebook
* :code:`test_restults.json`: test results


reports
```````

The :code:`report` sub command creates human readable HTML reports from test results:

::

    python -m autograde report path/to/result(s)

The respective report is added to the results archive inplace.


patching
````````

Results from multiple test runs can be merged via the :code:`patch` sub command:

::

    python -m autograde patch path/to/result(s) /path/to/patch/result(s)


summarize results
`````````````````

In a typical scenario, test cases are not just applied to one notebook but many at a time.
Therefore, *autograde* comes with a summary feature, that aggregates results, shows you a score distribution and has some very basic fraud detection.
To create a summary, simply run:

::

    python -m autograde summary path/to/results

Two new files will appear in the result directory:

* :code:`summary.csv`: aggregated results
* :code:`summary.html`: human readable summary report


help
````

To get an overview of all available commands and their usage, run

::

    python -m autograde [sub command] --help


