Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to test a notebook with jupytext --check #286

Closed
mwouts opened this issue Jul 11, 2019 · 5 comments · Fixed by #371
Closed

Document how to test a notebook with jupytext --check #286

mwouts opened this issue Jul 11, 2019 · 5 comments · Fixed by #371
Milestone

Comments

@mwouts
Copy link
Owner

mwouts commented Jul 11, 2019

We should provide a sample notebook with

  • a function
  • doctests
  • and explicit unit tests

and document how to test it with jupytext --check [pytest].

How does that compare to

@mwouts mwouts modified the milestone: 1.2.2 Aug 30, 2019
@mwouts mwouts added this to the 1.3.0 milestone Sep 7, 2019
@mwouts
Copy link
Owner Author

mwouts commented Sep 29, 2019

Apparently doctest, unittest and pytest can only run on real .py files, not on stdin. So if we want to test notebooks using jupytext --check, we'd have to write the python form to a temporary .py script, and test that one using the given command. Maybe jupytext --check could create the temp file when {} is found in the command to be executed, just like find -exec does?

@mwouts
Copy link
Owner Author

mwouts commented Sep 29, 2019

@mattharrison, you mentioned at #220 that you would like to run doctest on (Markdown) notebooks.

May I ask if I understand correctly that you plan to use doctest to make sure that the outputs don't change (like nbval does)? Or are you just looking for a way to make sure that the doctests inside the notebook are correct, like executing import doctest; doctest.testmod() in the notebook, but maybe outside of the notebook, like here:

jupytext --to py notebook.md # (or notebook.ipynb)
python -m doctest notebook.py

@mattharrison
Copy link

I have authored multiple books using rst. I enter my Python code as if it were typed at the terminal and then I can run doctest to ensure that my book "runs".

I'd like to be able to do similar with Jupytext, ie write a book, but using Markdown (because I want to go back and forth from Jupyter to try things out). When writing about machine learning/data analysis, having the output is critical for readers.

Here's an example from rst:

How to do it…
~~~~~~~~~~~~~


.. code:: pycon

   >>> pd.set_option('max_columns', 4, 'max_rows', 10)

.. code:: pycon

    >>> movies = pd.read_csv('data/movie.csv')
    >>> movies.head()
       color      director_name  ...  aspect_ratio  movie_facebook_likes
    0  Color      James Cameron  ...          1.78                 33000
    1  Color     Gore Verbinski  ...          2.35                     0
    2  Color         Sam Mendes  ...          2.35                 85000
    3  Color  Christopher Nolan  ...          2.35                164000
    4    NaN        Doug Walker  ...           NaN                     0
    <BLANKLINE>
    [5 rows x 28 columns]

Realize this might be "out of scope" for jupytext, but would love to be able to get the output in markdown. :)

@mwouts
Copy link
Owner Author

mwouts commented Oct 1, 2019

I see! Thanks for the clarification, this is an interesting use case. Since Jupytext Markdown is a format for Jupyter notebooks, maybe we'll be able to do that using notebook tools rather than doctest, but the idea is exactly the same.

Precisely, I expect that, when outputs become available in Markdown, you will be able to either

  1. re-run the notebook (jupytext --execute book.md) and check e.g. with git diff if any output has changed, or
  2. test the notebook with nbval (works similarly, but does not requires git, and allows to test only certain cells)

@mwouts
Copy link
Owner Author

mwouts commented Oct 13, 2019

Just a quick note for myself - some of the programs above do not accept files on stdin. So maybe we could implement a temp file facility in Jupytext, and allow one to call pytest like:

jupytext notebook.ipynb --check 'python -m pytest {}'

mwouts added a commit that referenced this issue Oct 30, 2019
mwouts added a commit that referenced this issue Nov 2, 2019
mwouts added a commit that referenced this issue Nov 2, 2019
@mwouts mwouts closed this as completed in b19e4d6 Nov 2, 2019
@mwouts mwouts mentioned this issue Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants