def test_grade_notebook(): """ Test notebooks that grade at various percentages """ test_paths = os.path.join(here, 'notebooks/grading/tests/q*.py') full_grade_notebook = os.path.join(here, 'notebooks/grading/full-grade.ipynb') assert grade_notebook(full_grade_notebook, glob(test_paths)) == 1 half_grade_notebook = os.path.join(here, 'notebooks/grading/half-grade.ipynb') assert grade_notebook(half_grade_notebook, glob(test_paths)) == 0.5 zero_grade_notebook = os.path.join(here, 'notebooks/grading/zero-grade.ipynb') assert grade_notebook(zero_grade_notebook, glob(test_paths)) == 0
def main(): argparser = argparse.ArgumentParser() argparser.add_argument('ipynb_path', help='Path to python file to grade') args = argparser.parse_args() ipynb_path = os.path.abspath(args.ipynb_path) os.chdir(os.path.dirname(ipynb_path)) base_path = os.path.dirname(ipynb_path) test_files = glob(os.path.join(base_path, 'tests/q*.py')) result = grade_notebook(ipynb_path, test_files) print(result)
def gradeNotebook(nb_path): tests = glob(op.join(op.dirname(nb_path), 'tests', 'q*.py')) r, s = gofer_wrangle(grade_notebook(nb_path, tests)) return r, s
Table().with_column("Age estimate", bootstrap_ages * 1e-9).hist(bins=np.arange(12, 16, .1), unit="billion years") print( "95% confidence interval for the age of the universe: [{:g}, {:g}] billion years" .format(lower_end * 1e-9, upper_end * 1e-9)) # In[18]: check('tests/q1_7.py') # Nice work, data astronomer! You can compare your result to the [Planck project 2015 results](https://arxiv.org/pdf/1502.01589.pdf), which estimated the age of the universe to be 13.799±0.021 billion years. # ## Submission # You're finished with lab 3! In order to successfully submit your assignment, follow these steps... # - **IMPORTANT** Before you do anything, **Save and Checkpoint** from the `File` menu. Please do this first before running the cell below, # - **run all the tests and verify that they all pass** (the next cell has a shortcut for that), # - **Review the notebook one last time** If you make any changes, please **Save and Checkpoint** again. # - **Hit the Submit button** Your submission will be saved and grade will be posted when it's finished running. # In[19]: # For your convenience, you can run this cell to run all the tests at once! import glob from gofer.ok import grade_notebook if not globals().get('__GOFER_GRADER__', False): display(grade_notebook('lab03.ipynb', sorted(glob.glob('tests/q*.py')))) # In[ ]:
import sys import os.path as op from glob import glob from gofer.ok import grade_notebook nb_fname = sys.argv[1] tests = glob(op.join(op.dirname(nb_fname), 'tests', 'q*.py')) print(grade_notebook(nb_fname, tests))