IPython custom cell magic to test code snippets typed into notebook cells.
Reason this release was yanked:
obsolete
Project description
README
IPython custom cell magic to test code snippets typed into notebook cells.
Installation
This package depends on IPython, you may need to install it first.
Install from PyPI
As of 2022-07-01, tmagic is available at https://pypi.org/project/tmagic/.
Install it as usual: pip3 install tmagic.
Install from BitBucket
To install the package for yourself as user:
pip install git+ssh://git@bitbucket.org/interquadrat/testmagic.git
You will need to have the appropriate credentials to get this working.
Install from a local repository
To get around BitBucket authentication issues, the trick is to install from the local Git repository.
Assuming that this local repo belongs to the user "teacher" that also has sudo rights,
then install the package for all users like this:
sudo -H pip3 install git+file:///home/teacher/PROJECTS/training/testmagic
where you may need to modify the path to the local repo.
How to use
See also the example IPython notebook file example.ipynb.
The description below explains usage in a bit more detail.
Preparation
Import the TestMagic class and create an instance of it that is connected to the harness.
from tmagic import TestMagic
magic = TestMagic()
magic.register_test("answer", 42)
Usage examples
Start a cell with %%testexpr <testname> where <testname> is the name of the test
that you registered with the Harness object ("answer" in the above example).
Then add one or more Python statements to the cell.
The last statement must evaluate to the "good value" (42) defined in the register_test
method invocation.
The following test will fail:
%%testexpr answer
a = 6
b = 8
a*b
When executing this cell, the output will be:
Test failed :-(
48
This, however, will succeed:
%%testexpr answer
a = 6
b = 7
a*b
producing the output:
Test passed :-)
42
Register several tests at once
The register_tests() convenience method lets you register several test name - expected value pairs.
tests = { "square":4, "cube":8 }
magic.register_tests(tests)
Run the tests (both will succeed of course):
%%testexpr square
2*2
%%testexpr cube
pow(2,3)
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 tmagic-0.0.6.tar.gz.
File metadata
- Download URL: tmagic-0.0.6.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cb9ee842410dbadbe8074e733dd880f9f1a9cfa4c36c62fb98ccc33a5f6b12e
|
|
| MD5 |
0baebeaf49cdc99c4ed679d470c59165
|
|
| BLAKE2b-256 |
a82d262d26400b54331f14610a6794970327bd778f0f6d9ace3a2050b1b27cf4
|
File details
Details for the file tmagic-0.0.6-py3-none-any.whl.
File metadata
- Download URL: tmagic-0.0.6-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee776fd9b17385f54d79e040d1d8b2c0814c1a3b165d42f73ab9c2c408df5c25
|
|
| MD5 |
c8501bd813f61cc2602e8391f65d3d63
|
|
| BLAKE2b-256 |
5894d8cd5371f7d8ea223ec42ac36df63b8292e88a58b32380855583fb9d597a
|