def test_multiple_files(self): """Can multiple files be assigned?""" self._empty_notebook('source/ps1/foo.ipynb') self._empty_notebook('source/ps1/bar.ipynb') run_command("nbgrader assign ps1 --create") assert os.path.isfile("release/ps1/foo.ipynb") assert os.path.isfile("release/ps1/bar.ipynb")
def test_install_user(self, temp_dir): nbextension_dir = os.path.join(temp_dir, "nbextensions") run_command(["nbgrader", "extension", "install", "--nbextensions", nbextension_dir]) # check the extension file were copied assert os.path.isfile(os.path.join(nbextension_dir, "nbgrader", "create_assignment.js")) assert os.path.isfile(os.path.join(nbextension_dir, "nbgrader", "nbgrader.css"))
def test_install_user(self, temp_dir): nbextension_dir = os.path.join(temp_dir, "nbextensions") run_command("nbgrader extension install --nbextensions={}".format(nbextension_dir)) # check the extension file were copied assert os.path.isfile(os.path.join(nbextension_dir, "nbgrader", "create_assignment.js")) assert os.path.isfile(os.path.join(nbextension_dir, "nbgrader", "nbgrader.css"))
def _release(self, assignment, exchange): self._copy_file("files/test.ipynb", "release/ps1/p1.ipynb") run_command([ "nbgrader", "release", assignment, "--NbGraderConfig.course_id=abc101", "--TransferApp.exchange_directory={}".format(exchange) ])
def test_missing_assignment(self, gradebook): """Is an error thrown when the assignment is missing?""" self._copy_file("files/submitted-changed.ipynb", "source/ps1/p1.ipynb") run_command(["nbgrader", "assign", "ps1", "--db", gradebook]) self._copy_file("files/submitted-changed.ipynb", "submitted/ps2/foo/p1.ipynb") run_command(["nbgrader", "autograde", "ps2", "--db", gradebook], retcode=1)
def test_force(self, gradebook): """Ensure the force option works properly""" self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb") self._make_file("source/ps1/foo.txt", "foo") self._make_file("source/ps1/data/bar.txt", "bar") run_command('nbgrader assign ps1 --db="{}" '.format(gradebook)) self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1.ipynb") self._make_file("submitted/foo/ps1/foo.txt", "foo") self._make_file("submitted/foo/ps1/data/bar.txt", "bar") self._make_file("submitted/foo/ps1/blah.pyc", "asdf") run_command('nbgrader autograde ps1 --db="{}"'.format(gradebook)) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert os.path.isfile("autograded/foo/ps1/foo.txt") assert os.path.isfile("autograded/foo/ps1/data/bar.txt") assert not os.path.isfile("autograded/foo/ps1/blah.pyc") # check that it skips the existing directory os.remove("autograded/foo/ps1/foo.txt") run_command('nbgrader autograde ps1 --db="{}"'.format(gradebook)) assert not os.path.isfile("autograded/foo/ps1/foo.txt") # force overwrite the supplemental files run_command('nbgrader autograde ps1 --db="{}" --force'.format(gradebook)) assert os.path.isfile("autograded/foo/ps1/foo.txt") # force overwrite os.remove("source/ps1/foo.txt") os.remove("submitted/foo/ps1/foo.txt") run_command('nbgrader autograde ps1 --db="{}" --force'.format(gradebook)) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert not os.path.isfile("autograded/foo/ps1/foo.txt") assert os.path.isfile("autograded/foo/ps1/data/bar.txt") assert not os.path.isfile("autograded/foo/ps1/blah.pyc")
def _release(self, assignment, exchange, flags="", retcode=0): run_command( 'nbgrader release {} ' '--NbGraderConfig.course_id=abc101 ' '--TransferApp.exchange_directory={} ' '{}'.format(assignment, exchange, flags), retcode=retcode)
def test_grade_overwrite_files(self, gradebook): """Are dependent files properly linked and overwritten?""" self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb") self._make_file("source/ps1/data.csv", "some,data\n") run_command(["nbgrader", "assign", "ps1", "--db", gradebook]) self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1.ipynb") self._make_file('submitted/foo/ps1/timestamp.txt', "2015-02-02 15:58:23.948203 PST") self._make_file("submitted/foo/ps1/data.csv", "some,other,data\n") run_command(["nbgrader", "autograde", "ps1", "--db", gradebook]) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert os.path.isfile("autograded/foo/ps1/timestamp.txt") assert os.path.isfile("autograded/foo/ps1/data.csv") with open("autograded/foo/ps1/timestamp.txt", "r") as fh: contents = fh.read() assert contents == "2015-02-02 15:58:23.948203 PST" with open("autograded/foo/ps1/data.csv", "r") as fh: contents = fh.read() assert contents == "some,data\n"
def test_multiple_files(self): """Can multiple files be assigned?""" self._empty_notebook('source/ps1/foo.ipynb') self._empty_notebook('source/ps1/bar.ipynb') run_command(["nbgrader", "assign", "ps1", "--create"]) assert os.path.isfile("release/ps1/foo.ipynb") assert os.path.isfile("release/ps1/bar.ipynb")
def test_no_course_id(self, exchange): """Does releasing without a course id thrown an error?""" cmd = [ "nbgrader", "release", "ps1", "--TransferApp.exchange_directory={}".format(exchange) ] run_command(cmd, retcode=1)
def test_install_system(self, temp_dir): run_command(["nbgrader", "extension", "install", "--prefix", temp_dir]) # check the extension file were copied nbextension_dir = os.path.join(temp_dir, "share", "jupyter", "nbextensions", "nbgrader") assert os.path.isfile(os.path.join(nbextension_dir, "create_assignment.js")) assert os.path.isfile(os.path.join(nbextension_dir, "nbgrader.css"))
def test_grade(self, gradebook): """Can files be graded?""" self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb") run_command('nbgrader assign ps1 --db="{}" '.format(gradebook)) self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1.ipynb") self._copy_file("files/submitted-changed.ipynb", "submitted/bar/ps1/p1.ipynb") run_command('nbgrader autograde ps1 --db="{}"'.format(gradebook)) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert not os.path.isfile("autograded/foo/ps1/timestamp.txt") assert os.path.isfile("autograded/bar/ps1/p1.ipynb") assert not os.path.isfile("autograded/bar/ps1/timestamp.txt") gb = Gradebook(gradebook) notebook = gb.find_submission_notebook("p1", "ps1", "foo") assert notebook.score == 1 assert notebook.max_score == 4 assert notebook.needs_manual_grade == False comment1 = gb.find_comment(0, "p1", "ps1", "foo") comment2 = gb.find_comment(1, "p1", "ps1", "foo") assert comment1.comment == "No response." assert comment2.comment == "No response." notebook = gb.find_submission_notebook("p1", "ps1", "bar") assert notebook.score == 2 assert notebook.max_score == 4 assert notebook.needs_manual_grade == True comment1 = gb.find_comment(0, "p1", "ps1", "bar") comment2 = gb.find_comment(1, "p1", "ps1", "bar") assert comment1.comment == None assert comment2.comment == None
def test_missing_assignment(self, gradebook): """Is an error thrown when the assignment is missing?""" self._copy_file("files/submitted-changed.ipynb", "source/ps1/p1.ipynb") run_command('nbgrader assign ps1 --db="{}" '.format(gradebook)) self._copy_file("files/submitted-changed.ipynb", "submitted/ps2/foo/p1.ipynb") run_command('nbgrader autograde ps2 --db="{}" '.format(gradebook), retcode=1)
def gradebook(request, tempdir): # create a "class files" directory origdir = os.getcwd() os.mkdir("class_files") os.chdir("class_files") # copy files from the user guide source_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "docs", "source", "user_guide", "source") submitted_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "docs", "source", "user_guide", "submitted") shutil.copytree(os.path.join(os.path.dirname(__file__), source_path), "source") shutil.copytree(os.path.join(os.path.dirname(__file__), submitted_path), "submitted") # create the gradebook gb = Gradebook("sqlite:///gradebook.db") gb.add_assignment("Problem Set 1") gb.add_student("Bitdiddle", first_name="Ben", last_name="B") gb.add_student("Hacker", first_name="Alyssa", last_name="H") gb.add_student("Reasoner", first_name="Louis", last_name="R") # run nbgrader assign run_command([ "nbgrader", "assign", "Problem Set 1", "--IncludeHeaderFooter.header=source/header.ipynb" ]) # run the autograder run_command(["nbgrader", "autograde", "Problem Set 1"]) def fin(): os.chdir(origdir) shutil.rmtree("class_files") request.addfinalizer(fin) return gb
def _release_and_fetch(self, assignment, exchange): self._copy_file("files/test.ipynb", "release/ps1/p1.ipynb") run_command( "nbgrader release {} " "--NbGraderConfig.course_id=abc101 " "--TransferApp.exchange_directory={} ".format(assignment, exchange) ) run_command("nbgrader fetch abc101 {} " "--TransferApp.exchange_directory={} ".format(assignment, exchange))
def _collect(self, assignment, exchange, flags="", retcode=0): run_command( "nbgrader collect {} " "--NbGraderConfig.course_id=abc101 " "--TransferApp.exchange_directory={} " "{}".format(assignment, exchange, flags), retcode=retcode, )
def _collect(self, assignment, exchange, flags="", retcode=0): print("Calling collect with assignment: " + assignment) run_command( 'nbgrader collect {} ' '--NbGraderConfig.course_id=abc101 ' '--TransferApp.exchange_directory={} ' '{}'.format(assignment, exchange, flags), retcode=retcode)
def test_side_effects(self, gradebook): self._copy_file("files/side-effects.ipynb", "source/ps1/p1.ipynb") run_command('nbgrader assign ps1 --db="{}" '.format(gradebook)) self._copy_file("files/side-effects.ipynb", "submitted/foo/ps1/p1.ipynb") run_command('nbgrader autograde ps1 --db="{}"'.format(gradebook)) assert os.path.isfile("autograded/foo/ps1/side-effect.txt") assert not os.path.isfile("submitted/foo/ps1/side-effect.txt")
def test_side_effects(self, gradebook): self._copy_file("files/side-effects.ipynb", "source/ps1/p1.ipynb") run_command(["nbgrader", "assign", "ps1", "--db", gradebook]) self._copy_file("files/side-effects.ipynb", "submitted/foo/ps1/p1.ipynb") run_command(["nbgrader", "autograde", "ps1", "--db", gradebook]) assert os.path.isfile("autograded/foo/ps1/side-effect.txt") assert not os.path.isfile("submitted/foo/ps1/side-effect.txt")
def test_no_course_id(self, exchange, cache): """Does releasing without a course id thrown an error?""" self._release_and_fetch("ps1", exchange, cache) cmd = [ "nbgrader", "submit", "ps1", "--TransferApp.cache_directory={}".format(cache), "--TransferApp.exchange_directory={}".format(exchange) ] run_command(cmd, retcode=1)
def test_install_system(self, temp_dir): run_command(["nbgrader", "extension", "install", "--prefix", temp_dir]) # check the extension file were copied nbextension_dir = os.path.join(temp_dir, "share", "jupyter", "nbextensions", "nbgrader") assert os.path.isfile( os.path.join(nbextension_dir, "create_assignment.js")) assert os.path.isfile(os.path.join(nbextension_dir, "nbgrader.css"))
def test_add_missing_student(self, gradebook): """Can a missing student be added?""" self._copy_file("files/submitted-changed.ipynb", "source/ps1/p1.ipynb") run_command('nbgrader assign ps1 --db="{}" '.format(gradebook)) self._copy_file("files/submitted-changed.ipynb", "submitted/baz/ps1/p1.ipynb") run_command('nbgrader autograde ps1 --db="{}" --create'.format(gradebook)) assert os.path.isfile("autograded/baz/ps1/p1.ipynb")
def test_add_missing_student(self, gradebook): """Can a missing student be added?""" self._copy_file("files/submitted-changed.ipynb", "source/ps1/p1.ipynb") run_command(["nbgrader", "assign", "ps1", "--db", gradebook]) self._copy_file("files/submitted-changed.ipynb", "submitted/baz/ps1/p1.ipynb") run_command(["nbgrader", "autograde", "ps1", "--db", gradebook, "--create"]) assert os.path.isfile("autograded/baz/ps1/p1.ipynb")
def test_filter_notebook(self, gradebook): """Does autograding filter by notebook properly?""" self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb") self._make_file("source/ps1/foo.txt", "foo") self._make_file("source/ps1/data/bar.txt", "bar") run_command(["nbgrader", "assign", "ps1", "--db", gradebook]) self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1.ipynb") self._make_file("submitted/foo/ps1/foo.txt", "foo") self._make_file("submitted/foo/ps1/data/bar.txt", "bar") self._make_file("submitted/foo/ps1/blah.pyc", "asdf") run_command([ "nbgrader", "autograde", "ps1", "--db", gradebook, "--notebook", "p1" ]) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert os.path.isfile("autograded/foo/ps1/foo.txt") assert os.path.isfile("autograded/foo/ps1/data/bar.txt") assert not os.path.isfile("autograded/foo/ps1/blah.pyc") # check that removing the notebook still causes the autograder to run os.remove("autograded/foo/ps1/p1.ipynb") os.remove("autograded/foo/ps1/foo.txt") run_command([ "nbgrader", "autograde", "ps1", "--db", gradebook, "--notebook", "p1" ]) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert os.path.isfile("autograded/foo/ps1/foo.txt") assert os.path.isfile("autograded/foo/ps1/data/bar.txt") assert not os.path.isfile("autograded/foo/ps1/blah.pyc") # check that running it again doesn't do anything os.remove("autograded/foo/ps1/foo.txt") run_command([ "nbgrader", "autograde", "ps1", "--db", gradebook, "--notebook", "p1" ]) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert not os.path.isfile("autograded/foo/ps1/foo.txt") assert os.path.isfile("autograded/foo/ps1/data/bar.txt") assert not os.path.isfile("autograded/foo/ps1/blah.pyc") # check that removing the notebook doesn't caus the autograder to run os.remove("autograded/foo/ps1/p1.ipynb") run_command(["nbgrader", "autograde", "ps1", "--db", gradebook]) assert not os.path.isfile("autograded/foo/ps1/p1.ipynb") assert not os.path.isfile("autograded/foo/ps1/foo.txt") assert os.path.isfile("autograded/foo/ps1/data/bar.txt") assert not os.path.isfile("autograded/foo/ps1/blah.pyc")
def test_skip_extra_notebooks(self, gradebook): self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb") run_command(["nbgrader", "assign", "ps1", "--db", gradebook]) self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1 copy.ipynb") self._copy_file("files/submitted-changed.ipynb", "submitted/foo/ps1/p1.ipynb") run_command(["nbgrader", "autograde", "ps1", "--db", gradebook]) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert not os.path.isfile("autograded/foo/ps1/p1 copy.ipynb")
def _fetch(self, assignment, exchange, flags=None, retcode=0): cmd = [ "nbgrader", "fetch", assignment, "--course", "abc101", "--TransferApp.exchange_directory={}".format(exchange) ] if flags is not None: cmd.extend(flags) run_command(cmd, retcode=retcode)
def test_skip_extra_notebooks(self, gradebook): self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb") run_command('nbgrader assign ps1 --db="{}" '.format(gradebook)) self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1 copy.ipynb") self._copy_file("files/submitted-changed.ipynb", "submitted/foo/ps1/p1.ipynb") run_command('nbgrader autograde ps1 --db="{}"'.format(gradebook)) assert os.path.isfile("autograded/foo/ps1/p1.ipynb") assert not os.path.isfile("autograded/foo/ps1/p1 copy.ipynb")
def test_permissions(self): """Are permissions properly set?""" self._empty_notebook('source/ps1/foo.ipynb') self._make_file("source/ps1/foo.txt", "foo") run_command(["nbgrader", "assign", "ps1", "--create"]) assert os.path.isfile("release/ps1/foo.ipynb") assert os.path.isfile("release/ps1/foo.txt") assert self._get_permissions("release/ps1/foo.ipynb") == "644" assert self._get_permissions("release/ps1/foo.txt") == "644"
def test_handle_failure(self): self._empty_notebook("source/ps1/p1.ipynb") self._empty_notebook("source/ps1/p2.ipynb") run_command(["nbgrader", "assign", "ps1", "--create"]) self._empty_notebook("submitted/foo/ps1/p1.ipynb") self._copy_file("files/test.ipynb", "submitted/foo/ps1/p2.ipynb") run_command(["nbgrader", "autograde", "ps1", "--create"], retcode=1) assert not os.path.exists("autograded/foo/ps1")
def test_custom_permissions(self): """Are custom permissions properly set?""" self._empty_notebook('source/ps1/foo.ipynb') self._make_file("source/ps1/foo.txt", "foo") run_command("nbgrader assign ps1 --create --AssignApp.permissions=666") assert os.path.isfile("release/ps1/foo.ipynb") assert os.path.isfile("release/ps1/foo.txt") assert self._get_permissions("release/ps1/foo.ipynb") == "666" assert self._get_permissions("release/ps1/foo.txt") == "666"
def _collect(self, assignment, exchange, flags=None, retcode=0): cmd = [ 'nbgrader', 'collect', assignment, '--course', 'abc101', '--TransferApp.exchange_directory={}'.format(exchange) ] if flags is not None: cmd.extend(flags) run_command(cmd, retcode=retcode)
def _release_and_fetch(self, assignment, exchange): self._copy_file("files/test.ipynb", "release/ps1/p1.ipynb") run_command([ 'nbgrader', 'release', assignment, '--NbGraderConfig.course_id=abc101', '--TransferApp.exchange_directory={}'.format(exchange) ]) run_command([ 'nbgrader', 'fetch', assignment, '--course', 'abc101', '--TransferApp.exchange_directory={}'.format(exchange) ])
def _collect(self, assignment, exchange, flags=None, retcode=0): cmd = [ 'nbgrader', 'collect', assignment, '--NbGraderConfig.course_id=abc101', '--TransferApp.exchange_directory={}'.format(exchange) ] if flags is not None: cmd.extend(flags) run_command(cmd, retcode=retcode)
def _release(self, assignment, exchange, flags=None, retcode=0): cmd = [ "nbgrader", "release", assignment, "--course", "abc101", "--TransferApp.exchange_directory={}".format(exchange) ] if flags is not None: cmd.extend(flags) run_command(cmd, retcode=retcode)
def test_activate(self, jupyter_data_dir, jupyter_config_dir, env): nbextension_dir = os.path.join(jupyter_data_dir, "nbextensions") run_command(["nbgrader", "extension", "install", "--nbextensions", nbextension_dir], env=env) run_command(["nbgrader", "extension", "activate"], env=env) # check the extension file were copied self._assert_is_installed(nbextension_dir) # check that it is activated self._assert_is_activated(os.path.join(jupyter_config_dir, 'nbconfig', 'notebook.json'), key='create_assignment/main') self._assert_is_activated(os.path.join(jupyter_config_dir, 'nbconfig', 'tree.json'), key='assignment_list/main')
def test_add_missing_student(self, gradebook): """Can a missing student be added?""" self._copy_file("files/submitted-changed.ipynb", "source/ps1/p1.ipynb") run_command(["nbgrader", "assign", "ps1", "--db", gradebook]) self._copy_file("files/submitted-changed.ipynb", "submitted/baz/ps1/p1.ipynb") run_command( ["nbgrader", "autograde", "ps1", "--db", gradebook, "--create"]) assert os.path.isfile("autograded/baz/ps1/p1.ipynb")
def test_save_cells(self, db): """Ensure cells are saved into the database""" self._copy_file("files/test.ipynb", "source/ps1/test.ipynb") gb = Gradebook(db) gb.add_assignment("ps1") run_command(["nbgrader", "assign", "ps1", "--db", db]) notebook = gb.find_notebook("test", "ps1") assert len(notebook.grade_cells) == 6
def test_save_cells(self, db): """Ensure cells are saved into the database""" self._copy_file("files/test.ipynb", "source/ps1/test.ipynb") gb = Gradebook(db) gb.add_assignment("ps1") run_command('nbgrader assign ps1 --db="{}"'.format(db)) notebook = gb.find_notebook("test", "ps1") assert len(notebook.grade_cells) == 8
def _release(self, assignment, exchange, flags=None, retcode=0): cmd = [ "nbgrader", "release", assignment, "--NbGraderConfig.course_id=abc101", "--TransferApp.exchange_directory={}".format(exchange) ] if flags is not None: cmd.extend(flags) run_command(cmd, retcode=retcode)
def _submit(self, assignment, exchange, cache, course="abc101"): run_command( [ "nbgrader", "submit", assignment, "--course", course, "--TransferApp.cache_directory={}".format(cache), "--TransferApp.exchange_directory={}".format(exchange), ] )
def test_install_user(self, temp_dir): nbextension_dir = os.path.join(temp_dir, "nbextensions") run_command([ "nbgrader", "extension", "install", "--nbextensions", nbextension_dir ]) # check the extension file were copied assert os.path.isfile( os.path.join(nbextension_dir, "nbgrader", "create_assignment.js")) assert os.path.isfile( os.path.join(nbextension_dir, "nbgrader", "nbgrader.css"))
def test_force(self): """Ensure the force option works properly""" self._copy_file("files/test.ipynb", "source/ps1/test.ipynb") self._make_file("source/ps1/foo.txt", "foo") self._make_file("source/ps1/data/bar.txt", "bar") self._make_file("source/ps1/blah.pyc", "asdf") run_command(["nbgrader", "assign", "ps1", "--create"]) assert os.path.isfile("release/ps1/test.ipynb") assert os.path.isfile("release/ps1/foo.txt") assert os.path.isfile("release/ps1/data/bar.txt") assert not os.path.isfile("release/ps1/blah.pyc") # check that it skips the existing directory os.remove("release/ps1/foo.txt") run_command(["nbgrader", "assign", "ps1"]) assert not os.path.isfile("release/ps1/foo.txt") # force overwrite the supplemental files run_command(["nbgrader", "assign", "ps1", "--force"]) assert os.path.isfile("release/ps1/foo.txt") # force overwrite os.remove("source/ps1/foo.txt") run_command(["nbgrader", "assign", "ps1", "--force"]) assert os.path.isfile("release/ps1/test.ipynb") assert os.path.isfile("release/ps1/data/bar.txt") assert not os.path.isfile("release/ps1/foo.txt") assert not os.path.isfile("release/ps1/blah.pyc")
def test_invert_validate_changed(self): """Does the inverted validation fail on a changed notebook?""" self._copy_file("files/submitted-changed.ipynb", "submitted-changed.ipynb") output = run_command( ["nbgrader", "validate", "submitted-changed.ipynb", "--invert"]) assert output.split("\n")[0] == "NOTEBOOK PASSED ON 2 CELL(S)!"
def test_validate_changed(self): """Does the validation pass on an changed notebook?""" self._copy_file("files/submitted-changed.ipynb", "submitted-changed.ipynb") output = run_command( ["nbgrader", "validate", "submitted-changed.ipynb"]) assert output == "Success! Your notebook passes all the tests.\n"
def test_custom_permissions(self): """Are custom permissions properly set?""" self._empty_notebook('source/ps1/foo.ipynb') self._make_file("source/ps1/foo.txt", "foo") run_command(["nbgrader", "assign", "ps1", "--create"]) self._empty_notebook('submitted/foo/ps1/foo.ipynb') self._make_file("source/foo/ps1/foo.txt", "foo") run_command([ "nbgrader", "autograde", "ps1", "--create", "--AutogradeApp.permissions=644" ]) assert os.path.isfile("autograded/foo/ps1/foo.ipynb") assert os.path.isfile("autograded/foo/ps1/foo.txt") assert self._get_permissions("autograded/foo/ps1/foo.ipynb") == "644" assert self._get_permissions("autograded/foo/ps1/foo.txt") == "644"
def test_add_extra_notebooks_with_submissions(self, db): """Is an error thrown when new notebooks are added and there are existing submissions?""" gb = Gradebook(db) assignment = gb.add_assignment("ps1") self._copy_file("files/test.ipynb", "source/ps1/test.ipynb") run_command(["nbgrader", "assign", "ps1", "--db", db]) gb.db.refresh(assignment) assert len(assignment.notebooks) == 1 gb.add_student("hacker123") gb.add_submission("ps1", "hacker123") self._copy_file("files/test.ipynb", "source/ps1/test2.ipynb") run_command(["nbgrader", "assign", "ps1", "--db", db, "--force"], retcode=1)
def test_dependent_files(self): """Are dependent files properly linked?""" self._make_file('source/ps1/data/foo.csv', 'foo') self._make_file('source/ps1/data/bar.csv', 'bar') self._empty_notebook('source/ps1/foo.ipynb') self._empty_notebook('source/ps1/bar.ipynb') run_command(["nbgrader", "assign", "ps1", "--create"]) assert os.path.isfile("release/ps1/foo.ipynb") assert os.path.isfile("release/ps1/bar.ipynb") assert os.path.isfile("release/ps1/data/foo.csv") assert os.path.isfile("release/ps1/data/bar.csv") with open('release/ps1/data/foo.csv', 'r') as fh: assert fh.read() == 'foo' with open('release/ps1/data/bar.csv', 'r') as fh: assert fh.read() == 'bar'
def test_validate_unchanged(self): """Does the validation fail on an unchanged notebook?""" self._copy_file("files/submitted-unchanged.ipynb", "submitted-unchanged.ipynb") output = run_command( ["nbgrader", "validate", "submitted-unchanged.ipynb"]) assert output.split( "\n" )[0] == "VALIDATION FAILED ON 3 CELL(S)! If you submit your assignment as it is, you WILL NOT"
def test_invert_grade_cell_changed_ignore_checksums(self): """Does the validate fail if a grade cell has changed with --invert and ignoring checksums?""" self._copy_file("files/submitted-grade-cell-changed.ipynb", "submitted-grade-cell-changed.ipynb") output = run_command([ "nbgrader", "validate", "submitted-grade-cell-changed.ipynb", "--invert", "--DisplayAutoGrades.ignore_checksums=True" ]) assert output.split("\n")[0] == "NOTEBOOK PASSED ON 2 CELL(S)!"
def test_locked_cell_changed(self): """Does the validate fail if a locked cell has changed?""" self._copy_file("files/submitted-locked-cell-changed.ipynb", "submitted-locked-cell-changed.ipynb") output = run_command( ["nbgrader", "validate", "submitted-locked-cell-changed.ipynb"]) assert output.split( "\n" )[0] == "THE CONTENTS OF 2 TEST CELL(S) HAVE CHANGED! This might mean that even though the tests"
def test_activate(self, temp_dir): nbextension_dir = os.path.join(temp_dir, "nbextensions") run_command([ "nbgrader", "extension", "install", "--nbextensions", nbextension_dir ]) run_command( ["nbgrader", "extension", "activate", "--ipython-dir", temp_dir]) # check the extension file were copied assert os.path.isfile( os.path.join(nbextension_dir, "nbgrader", "create_assignment.js")) assert os.path.isfile( os.path.join(nbextension_dir, "nbgrader", "nbgrader.css")) # check that it is activated config_file = os.path.join(temp_dir, 'profile_default', 'nbconfig', 'notebook.json') self._assert_is_activated(config_file)
def test_grade_cell_changed_ignore_checksums(self): """Does the validate pass if a grade cell has changed but we're ignoring checksums?""" self._copy_file("files/submitted-grade-cell-changed.ipynb", "submitted-grade-cell-changed.ipynb") output = run_command([ "nbgrader", "validate", "submitted-grade-cell-changed.ipynb", "--DisplayAutoGrades.ignore_checksums=True" ]) assert output.split( "\n")[0] == "Success! Your notebook passes all the tests."
def test_locked_cell_changed_ignore_checksums(self): """Does the validate pass if a locked cell has changed but we're ignoring checksums?""" self._copy_file("files/submitted-locked-cell-changed.ipynb", "submitted-locked-cell-changed.ipynb") output = run_command([ "nbgrader", "validate", "submitted-locked-cell-changed.ipynb", "--DisplayAutoGrades.ignore_checksums=True" ]) assert output.split( "\n" )[0] == "VALIDATION FAILED ON 1 CELL(S)! If you submit your assignment as it is, you WILL NOT"
def test_validate_unchanged_ignore_checksums(self): """Does the validation fail on an unchanged notebook with ignoring checksums?""" self._copy_file("files/submitted-unchanged.ipynb", "submitted-unchanged.ipynb") output = run_command([ "nbgrader", "validate", "submitted-unchanged.ipynb", "--DisplayAutoGrades.ignore_checksums=True" ]) assert output.split( "\n" )[0] == "VALIDATION FAILED ON 1 CELL(S)! If you submit your assignment as it is, you WILL NOT"
def test_invert_grade_cell_changed(self): """Does the validate fail if a grade cell has changed, even with --invert?""" self._copy_file("files/submitted-grade-cell-changed.ipynb", "submitted-grade-cell-changed.ipynb") output = run_command([ "nbgrader", "validate", "submitted-grade-cell-changed.ipynb", "--invert" ]) assert output.split( "\n" )[0] == "THE CONTENTS OF 1 TEST CELL(S) HAVE CHANGED! This might mean that even though the tests"