Esempio n. 1
0
def test_create_template_dir_merge_when_exists(default_config, tmp_path):
    """
    Tests that create_template_dir with mode "merge" does not fail when
    directory already exists.
    """
    default_config["course_directory"] = tmp_path
    abctemplate.create_template_dir(default_config, "test_assignment")
    # run it again! merge!
    abctemplate.create_template_dir(default_config, "test_assignment", "merge")
Esempio n. 2
0
def test_create_template_dir_fail_when_exists(default_config, tmp_path):
    """
    Tests that create_template_dir with default mode "fail" does indeed
    fail with sys.exit when the directory already exists.
    """
    default_config["course_directory"] = tmp_path
    abctemplate.create_template_dir(default_config, "test_assignment")
    # run it again! fail!
    with pytest.raises(SystemExit):
        abctemplate.create_template_dir(default_config, "test_assignment")
Esempio n. 3
0
def test_move_git_dir(default_config, tmp_path):
    """
    Tests that we correctly move (and moce back) a .git directory in the template repo when running in delete mode.
    """
    default_config["course_directory"] = tmp_path
    template_path = abctemplate.create_template_dir(default_config,
                                                    "test_assignment")
    github.init_and_commit(template_path, False)
    assert Path(template_path, ".git").exists()
    template_path = abctemplate.create_template_dir(default_config,
                                                    "test_assignment",
                                                    "delete")
    assert Path(template_path, ".git").exists()
Esempio n. 4
0
def test_create_template_dir_delete_when_exists(default_config, tmp_path):
    """
    Tests that create_template_dir with mode "delete" re-creates the directory with the same contents.
    """
    default_config["course_directory"] = tmp_path
    template_path = abctemplate.create_template_dir(default_config,
                                                    "test_assignment")
    # run it again! delete!
    contents_before = list(Path(template_path).glob("*"))
    template_path = abctemplate.create_template_dir(default_config,
                                                    "test_assignment",
                                                    "delete")
    contents_after = list(Path(template_path).glob("*"))
    assert contents_before == contents_after
Esempio n. 5
0
def test_copy_assignment_files(default_config, tmp_path):
    """Test that files are moved to the template repo directory and that
    ignored files are NOT moved.
    """
    default_config["course_directory"] = tmp_path
    assignment = "assignment1"
    files_to_ignore = default_config["files_to_ignore"]
    # first, set up the test course materials directory
    # and create some temporary files
    cmpath = Path(
        tmp_path, default_config["course_materials"], "release", assignment
    )
    cmpath.mkdir(parents=True)
    cmpath.joinpath("file1.txt").touch()
    cmpath.joinpath("file2.txt").touch()
    cmpath.joinpath(".DS_Store").touch()

    template_repo = abctemplate.create_template_dir(default_config, assignment)
    abctemplate.copy_assignment_files(
        default_config, template_repo, assignment
    )
    # Test that both text files have been moved to the template dir but that
    # the system .DS_Store is not there
    for afile in os.listdir(cmpath):
        if afile not in files_to_ignore:
            assert afile in os.listdir(template_repo)
        else:
            print(afile)
            assert afile not in os.listdir(template_repo)
Esempio n. 6
0
def test_create_extra_files(default_config, tmp_path):
    default_config["course_directory"] = tmp_path
    assignment = "assignment1"
    template_repo = abctemplate.create_template_dir(default_config, assignment)
    abctemplate.create_extra_files(default_config, template_repo, assignment)
    assert Path(template_repo, "testfile.txt").exists()
    f = open(Path(template_repo, "testfile.txt"))
    assert f.readline() == "line1\n"
Esempio n. 7
0
def test_copy_assignment_files_fails_nodir(default_config, tmp_path):
    # test that fails if nbgrader dir does not exist
    default_config["course_directory"] = tmp_path
    assignment = "assignment1"
    template_repo = abctemplate.create_template_dir(default_config, assignment)
    with pytest.raises(SystemExit):
        abctemplate.copy_assignment_files(default_config, template_repo,
                                          assignment)
Esempio n. 8
0
def test_coursename_config_options(tmp_path):
    # test that it fails if neither short_coursename or course_name is set
    localconfig = {
        "template_dir": "test_template",
        "course_directory": tmp_path,
    }
    with pytest.raises(SystemExit):
        template_path = abctemplate.create_template_dir(
            localconfig, "test_assignment")
Esempio n. 9
0
def test_create_template_dir(default_config, tmp_path):
    """
    Tests that create_template_dir with default mode "fail" creates a directory with the expected name.
    """
    default_config["course_directory"] = tmp_path
    shortname = default_config["short_coursename"]
    templates_dir = default_config["template_dir"]
    assignment = "test_assignment"
    template_path = abctemplate.create_template_dir(default_config, assignment)
    assert os.path.isdir(template_path)

    assert template_path == Path(
        tmp_path, templates_dir,
        "{}-{}-template".format(shortname, assignment))
Esempio n. 10
0
def test_copy_assignment_files(default_config, tmp_path):
    # test that contents are the same for target and source directory
    default_config["course_directory"] = tmp_path
    assignment = "assignment1"
    # first, set up the test nbgrader directory
    nbpath = Path(tmp_path, default_config["nbgrader_dir"], "release",
                  assignment)
    nbpath.mkdir(parents=True)
    # create some temporary files
    nbpath.joinpath("file1.txt").touch()
    nbpath.joinpath("file2.txt").touch()
    template_repo = abctemplate.create_template_dir(default_config, assignment)
    abctemplate.copy_assignment_files(default_config, template_repo,
                                      assignment)
    assert os.listdir(nbpath) == os.listdir(template_repo)
Esempio n. 11
0
def test_create_extra_files(default_config, tmp_path):
    default_config["course_directory"] = tmp_path
    assignment = "assignment1"

    # create the extra_files dir and some extra files
    readme_contents = ["# readme\n", "\n", "another line\n"]
    Path(tmp_path, "extra_files").mkdir()
    Path(tmp_path, "extra_files", ".gitignore").touch()
    with open(Path(tmp_path, "extra_files", "readme.md"), "w") as f:
        f.writelines(readme_contents)

    template_repo = abctemplate.create_template_dir(default_config, assignment)
    abctemplate.create_extra_files(default_config, template_repo, assignment)
    assert Path(template_repo, "readme.md").exists()
    assert Path(template_repo, ".gitignore").exists()
Esempio n. 12
0
def test_create_extra_files_readme(default_config, tmp_path):
    # tests for the special README.md case
    default_config["course_directory"] = tmp_path
    course_name = default_config["course_name"]
    assignment = "assignment1"
    template_repo = abctemplate.create_template_dir(default_config, assignment)
    abctemplate.create_extra_files(default_config, template_repo, assignment)
    assert Path(template_repo, "README.md").exists()
    f = open(Path(template_repo, "README.md"))
    assert f.readline() == "# {}: {}\n".format(course_name, assignment)

    # test when course_name not set
    del default_config["course_name"]
    abctemplate.create_extra_files(default_config, template_repo, assignment)
    assert Path(template_repo, "README.md").exists()

    f = open(Path(template_repo, "README.md"))
    assert f.readline() == "# README\n"