Drop-in replacement for the unittest module to use them in tests for nbgrader assignments.
Project description
nbgrader_unittest
Drop-in replacement for the unittest module to use them in tests for nbgrader assignments.
You can use this module just like the unittest module. Just don't
call the main function to run the tests. Use the run_nbgrader_test
function instead.
If your tests all pass, no output will be generated and nbgrader will assign
full marks to this cell. If one of your tests fail, the usual unittest output
will be created and printed to sys.stderr and no marks will be assigned to
this cell in nbgrader.
Example
You prepare a new jupyter notebook assignment with parts, that should be autograded with nbgrader.Your assignment could be something like this:
Write a function that returns a list of numbers, such that $x_i=i^2$, for $1 \leq i \leq n$. Make sure it handles the case where $n<1$ by raising a
ValueError.
Your code cell with the "Autograded answer" will look like this:
def squares(n):
"""Compute the squares of numbers from 1 to n, such that the
ith element of the returned list equals i^2.
"""
### BEGIN SOLUTION
if n < 1:
raise ValueError("n must be greater than or equal to 1")
return [x**2 for x in range(1, n + 1)]
### END SOLUTION
In a new code cell you put your "Autograder test":
import nbgrader_unittest
class SquaresTests(nbgrader_unittest.TestCase):
def test_square_of_one(self):
self.assertEqual(squares(1), [1])
def test_squares_up_to_ten(self):
self.assertEqual(
squares(10),
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
)
def test_negative_argument(self):
with self.assertRaises(ValueError):
squares(-4)
nbgrader_unittest.run_nbgrader_test(SquaresTests)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbgrader_unittest_sebastian_stigler-0.0.3.tar.gz.
File metadata
- Download URL: nbgrader_unittest_sebastian_stigler-0.0.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9c22d72c27389fd2181b068cf2ae7bbb995ab6151998fc369d3a6dd9bf1e228
|
|
| MD5 |
7506530050a37b9278c5016b64b74232
|
|
| BLAKE2b-256 |
038430c16dde15bc3e55ddf28a24bfa4caf2c9b249d958c77585a6aa474a2fb4
|
File details
Details for the file nbgrader_unittest_sebastian_stigler-0.0.3-py3-none-any.whl.
File metadata
- Download URL: nbgrader_unittest_sebastian_stigler-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
527daf3fc962d3ecdd8506e100e201127ebcd5cf06874164a5086b4bd60c87a2
|
|
| MD5 |
673d64a0e9ceed19d7499af0c1e5b062
|
|
| BLAKE2b-256 |
5251ddc1f3dca62ba9a9105b0454c026dae0421cfcfe939b780ae29460c9eac4
|