Skip to content

Commit

Permalink
ignore autotest assignment files; make quickstart rename ps1_autotest…
Browse files Browse the repository at this point in the history
… -> ps1; add quickstart test for autotest
  • Loading branch information
trevorcampbell committed Aug 30, 2023
1 parent 0ca7287 commit cf1d605
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ nbgrader/docs/source/user_guide/release/ps1/problem2.html
nbgrader/docs/source/user_guide/source/header.html
nbgrader/docs/source/user_guide/source/ps1/problem1.html
nbgrader/docs/source/user_guide/source/ps1/problem2.html
nbgrader/docs/source/user_guide/source/ps1_autotest/problem1.html
nbgrader/docs/source/user_guide/source/ps1_autotest/problem2.html
nbgrader/docs/source/user_guide/source/ps2/problem.html

# components stuff
node_modules
Expand Down
6 changes: 4 additions & 2 deletions nbgrader/apps/quickstartapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def start(self):
if not os.path.isdir(course_path):
os.mkdir(course_path)

# populating it with an example
# populate it with an example
self.log.info("Copying example from the user guide...")
example = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', 'docs', 'source', 'user_guide', 'source'))
Expand All @@ -135,9 +135,11 @@ def start(self):
os.path.dirname(__file__), '..', 'docs', 'source', 'user_guide', 'autotests.yml'))
shutil.copyfile(tests_file_path, os.path.join(course_path, 'autotests.yml'))
ignored_files = shutil.ignore_patterns("*.html", "ps2", "ps1")
shutil.copytree(example, os.path.join(course_path, "source"), ignore=ignored_files)
os.rename(os.path.join(course_path, "source", "ps1_autotest"), os.path.join(course_path, "source", "ps1"))
else:
ignored_files = shutil.ignore_patterns("*.html", "ps2", "autotests.yml", "ps1_autotest")
shutil.copytree(example, os.path.join(course_path, "source"), ignore=ignored_files)
shutil.copytree(example, os.path.join(course_path, "source"), ignore=ignored_files)

# create the config file
self.log.info("Generating example config file...")
Expand Down
25 changes: 25 additions & 0 deletions nbgrader/tests/apps/test_nbgrader_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,28 @@ def test_quickstart_f(self):

# nbgrader generate_assignment should work
run_nbgrader(["generate_assignment", "ps1"])

def test_quickstart_autotest(self):
"""Is the quickstart example with autotests properly generated?"""

run_nbgrader(["quickstart", "example", "--autotest"])

# it should fail if it already exists
run_nbgrader(["quickstart", "example", "--autotest"], retcode=1)

# it should succeed if --force is given
os.remove(os.path.join("example", "nbgrader_config.py"))
run_nbgrader(["quickstart", "example", "--force", "--autotest"])
assert os.path.exists(os.path.join("example", "nbgrader_config.py"))
assert os.path.exists(os.path.join("example", "autotests.yml"))

# nbgrader validate should work
os.chdir("example")
for nb in os.listdir(os.path.join("source", "ps1")):
if not nb.endswith(".ipynb"):
continue
output = run_nbgrader(["validate", os.path.join("source", "ps1", nb)], stdout=True)
assert output.strip() == "Success! Your notebook passes all the tests."

# nbgrader generate_assignment should work
run_nbgrader(["generate_assignment", "ps1"])

0 comments on commit cf1d605

Please sign in to comment.