class Course (object):
- def __init__(self, assignments=None, people=None, grades=None):
+ def __init__(self, name=None, assignments=None, people=None, grades=None):
+ self.name = name
if assignments is None:
assignments = []
self.assignments = sorted(assignments)
def load_course(basedir):
+ """Load a course directory.
+
+ >>> from pygrader.test.course import StubCourse
+ >>> stub_course = StubCourse(load=False)
+ >>> course = load_course(basedir=stub_course.basedir)
+ >>> course.name
+ 'phys101'
+ >>> course.assignments # doctest: +ELLIPSIS
+ [<pygrader.model.assignment.Assignment object at 0x...>, ...]
+ >>> course.people # doctest: +ELLIPSIS
+ [<pygrader.model.person.Person object at 0x...>, ...]
+ >>> course.grades
+ []
+ """
_LOG.debug('loading course from {}'.format(basedir))
config = _configparser.ConfigParser()
config.read([_os_path.join(basedir, 'course.conf')])
+ name = config.get('course', 'name')
names = {}
for option in ['assignments', 'professors', 'assistants', 'students']:
names[option] = [
people[person].groups = [group]
people = people.values()
grades = list(load_grades(basedir, assignments, people))
- return _Course(assignments=assignments, people=people, grades=grades)
+ return _Course(
+ name=name, assignments=assignments, people=people, grades=grades)
def parse_date(string):
"""Parse dates given using the W3C DTF profile of ISO 8601.
COURSE_CONF = """
[course]
+name: phys101
assignments: Attendance 1, Attendance 2, Attendance 3, Attendance 4,
Attendance 5, Attendance 6, Attendance 7, Attendance 8, Attendance 9,
Assignment 1, Assignment 2, Exam 1, Exam 2
course.conf
>>> course.cleanup()
"""
- def __init__(self):
+ def __init__(self, load=True):
self.basedir = _tempfile.mkdtemp(prefix='pygrader-tmp-')
try:
self.mailbox = _os_path.join(self.basedir, 'mail')
course_conf = _os_path.join(self.basedir, 'course.conf')
with open(course_conf, 'w') as f:
f.write(COURSE_CONF)
- self.course = _load_course(basedir=self.basedir)
+ if load:
+ self.course = _load_course(basedir=self.basedir)
except Exception:
self.cleanup()
[course]
+name: phys101
assignments: Attendance 1, Attendance 2, Attendance 3, Attendance 4,
Attendance 5, Attendance 6, Attendance 7, Attendance 8, Attendance 9,
Assignment 1, Assignment 2, Exam 1, Exam 2