ok-client
ok-client copied to clipboard
Easier way to write notebook tests
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.
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
""")
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
Just FYI: DS100 uses cell tags and a custom python script to take cells that contain assert statements and turn them into ok tests:

Gets turned into q01b.py.
The code is private right now but I can send it over if you'd like.