Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feedback tests #307

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions abcclassroom/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def copy_feedback_files(assignment_name, push_to_github=False, scrub=False):
course_dir = cf.get_config_option(config, "course_directory", True)
clone_dir = cf.get_config_option(config, "clone_dir", True)
materials_dir = cf.get_config_option(config, "course_materials", True)

try:
feedback_dir = Path(course_dir, materials_dir, "feedback")
with open(roster_filename, newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
feedback_dir = Path(course_dir, materials_dir, "feedback")
student_repos = []
with open(roster_filename, newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
try:
student = row["github_username"]
feedback_path = Path(feedback_dir, student, assignment_name)
source_files = list(feedback_path.glob("*.html"))
Expand All @@ -66,6 +66,7 @@ def copy_feedback_files(assignment_name, push_to_github=False, scrub=False):
"student".format(destination_dir)
)
continue
student_repos.append(destination_dir)
# TODO: Turn this into a helper function lines 46 - 64 here
# Don't copy any system related files -- not this is exactly
# the same code used in the template.py copy files function.
Expand Down Expand Up @@ -104,9 +105,21 @@ def copy_feedback_files(assignment_name, push_to_github=False, scrub=False):
if push_to_github:
github.push_to_github(destination_dir)

except FileNotFoundError as err:
print("Missing file or directory:")
print(" ", err)
except FileNotFoundError as err:
print("Missing file or directory:")
print(" ", err)

# if we didn't find any repos, there is probably something wrong
if len(student_repos) == 0:
print(
"""No repositories found in {} for assignment {};
exiting""".format(
clone_dir, assignment
)
)
sys.exit(1)

return student_repos


def copy_feedback(args):
Expand Down
96 changes: 64 additions & 32 deletions abcclassroom/tests/test_feedback.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
# from pathlib import Path
# Tests for feedback script

import pytest
from pathlib import Path

import abcclassroom.feedback as abcfeedback
import abcclassroom.github as github

test_data = {
"assignment": "assignment1",
"students": ["bert", "ernie"],
"files": ["feedback.html", "anotherfile.txt"],
}


@pytest.fixture
def create_directories(default_config, tmp_path):
"""
Creates the directories containing feedback reports and cloned student
repos. Creates two feedback and one non-feedback files.
"""
default_config["course_directory"] = tmp_path
print(default_config)
materials_dir = default_config["course_materials"]
clone_dir = default_config["clone_dir"]
assignment = test_data["assignment"]
students = test_data["students"]
files = test_data["files"]
# create the feedback directory course_dir/materials_dir/feedback
feedback_path = Path(tmp_path, materials_dir, "feedback").mkdir(
parents=True
)
for f in files:
Path(feedback_path, f).touch()

# create the cloned student repos
for s in students:
repo_name = "{}-{}".format(assignment, s)
repo_path = Path(tmp_path, clone_dir, repo_name)
repo_path.mkdir(parents=True)
github.init_and_commit(repo_path)


@pytest.fixture
def create_roster_file(default_config, tmp_path):
"""Create a student roster with the single github_username column"""
default_config["roster"] = "roster.csv"
with open("roster.csv") as rosterfile:
rosterfile.write("github_username\n")
for s in default_config["students"]:
rosterfile.write("{}\n".format(s))


def test_copy_feedback_files(default_config, tmp_path, create_directories):
"Tests that copying the feedback files copies both files"
default_config["course_directory"] = tmp_path
abcfeedback.copy_feedback_files(default_config)


#
# import abcclassroom.feedback as abcfeedback
#
# # import abcclassroom.config as cf
#
#
# def test_html_copies(default_config, tmp_path):
# """Test that an html feedback report added to a repo copies over. """
#
# assignment = "assignment1"
# default_config["course_directory"] = tmp_path
#
# # Setup student cloned directory with a single notebook
# # (this could be a fixture?)
# clone_path = Path(
# tmp_path, "cloned_repos", assignment, "assignment1-test-student"
# )
# clone_path.mkdir(parents=True)
# clone_path.joinpath("assignment1-test-student.ipynb").touch()
#
# # Setup feedback directory
# feedback_path = Path(
# tmp_path, "nbgrader", "feedback", "test-student", assignment
# )
# feedback_path.mkdir(parents=True)
# feedback_path.joinpath("assignment1-test-student.html").touch()
#
# # Return feedback -- this requires a config file
# abcfeedback.copy_feedback_files(assignment, github=None)
#
# # Add html file to one student's directory
#
# # Run abc-feedback
# def test_git_commit(default_config, tmp_path):
# "Tests that changes get commited ok"
# do_github_push = False
# need to create student repos list
# abcfeedback.git_commit_push(student_repos, do_github_push)