ok-client icon indicating copy to clipboard operation
ok-client copied to clipboard

Easier way to write notebook tests

Open Sumukh opened this issue 8 years ago • 3 comments

We should come up with a way that makes it easier to write tests for notebooks. A normal python assignment can just use doctests and OK will run those. There's no equivalent for notebooks.

It's hard to expect notebook authors to create a bunch of files to do tests. They should be able to define their tests inline if possible.

Sumukh avatar Mar 04 '17 03:03 Sumukh

Here are some things I thought about. Not huge fans of either - but just wanted to note it here for when we come back to this.

Either:

def test_q9():
   """
   >>> code 
   2 
   ...
   """
ok.grade(test_q9)

I'd much rather do something like

ok.grade("""
>>> code_var 
5 
""")

Sumukh avatar Mar 28 '17 23:03 Sumukh

We can also use textwrap.dedent and strip to normalize indentation and spacing:

ok.grade("""
    >>> code_var
    5
""")

Or, if we want to get fancy, we could implement a mini-compiler:

ok.grade("""

Question 09:
    >>> code_var
    5

Question 10:
    >>> q10_result
    19

""")

To compactly grade multiple questions. I'm taking a compilers course, so maybe I can do this as one of the projects :P

epai avatar Sep 05 '17 04:09 epai

Just FYI: DS100 uses cell tags and a custom python script to take cells that contain assert statements and turn them into ok tests:

screenshot 2017-10-20 11 24 34

Gets turned into q01b.py.

The code is private right now but I can send it over if you'd like.

SamLau95 avatar Oct 20 '17 18:10 SamLau95