Skip to main content

Convert notebook cells to unittests

Project description

Convert notebook cells to unittests

  • Free software: MIT license

Installation

pip install celltest

You can also install the in-development version with:

pip install https://github.com/NikZak/celltest/archive/master.zip

Usage

From command line

celltest [-h] -f FILES [FILES ...] [-c CALLBACKS [CALLBACKS ...]] [-nio] [-o [OUTPUT]] [-st [STANDARD_TEMPLATE]] [-ct [CUSTOM_TEMPLATE]] [-hf [HEADER]] [-v]

Optional arguments:

-h, --help            show help message and exit

-f FILES [FILES ...], --files FILES [FILES ...]
                      <Required> notebook file(s) to convert

-c CALLBACKS [CALLBACKS ...], --callbacks CALLBACKS [CALLBACKS ...]
                      callbacks to call after the test file creation (e.g. isort, black, yapf)

-nio, --not_insert_outputs
                      do not insert cell ouputs in the test file (then outputs are read from notebook during testing)

-o [OUTPUT], --output [OUTPUT]
                      output file. Defaults to test_[notebook name].py

-st [STANDARD_TEMPLATE], --standard_template [STANDARD_TEMPLATE]
                      standard template file: 1: default template 2: minimalistic template without checking outputs

-ct [CUSTOM_TEMPLATE], --custom_template [CUSTOM_TEMPLATE]
                      custom template file

-hf [HEADER], --header [HEADER]
                      header file. Header to insert in every test file

-v, --verbose         increase output verbosity

From notebook cell

# CT: ignore
# convert current notebook to unittest
from celltest.cells import CellConvert
CellConvert(callbacks=['isort', 'black', 'yapf']).run()

Accepted parameters to control test flow:

'comment', 'setup', 'ignore_outputs', 'ignore_stderr', 'ignore_stdout', 'ignore', 'ignore_display_data', 'run_all_till_now'

Parameters can be either specified in first line (after the % magic) of the notebook cells (e.g.):

# CT: ignore_outputs comment "Test ABC method"

or written in cell metadata:

{ "celltest :
    ["ignore_outputs", "comment", "Test ABC method"]
}

In case of conflicts line parameters are prioritised

Accepted callbacks (if installed) to prettify the .py test file:

isort, black, yapf

Documentation

https://celltest.readthedocs.io/

Development

To run all the tests run:

tox

Note, to combine the coverage data from all the tox environments run:

Windows

set PYTEST_ADDOPTS=--cov-append
tox

Other

PYTEST_ADDOPTS=--cov-append tox

Changelog

0.0.0 (2020-09-09)

  • First release on PyPI.

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

celltest-0.0.2.tar.gz (72.4 kB view details)

Uploaded Source

File details

Details for the file celltest-0.0.2.tar.gz.

File metadata

  • Download URL: celltest-0.0.2.tar.gz
  • Upload date:
  • Size: 72.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for celltest-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3ba7fdae58585d744bd532c534f3b17dda916517de693f39e21193220366c330
MD5 57015a01f8c44dcfbc36b68bd47a2807
BLAKE2b-256 035a957acbb2b85c29b465afae2eb0676b7e91cdd97814a78756b873aa22776c

See more details on using hashes here.

Supported by

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