Ejemplo n.º 1
0
def check_points(rmd_fname, tests_path=None):
    if tests_path is None:
        tests_path = op.join(op.dirname(rmd_fname), 'tests')
    # Find chunks
    nb = loads(read_utf8(rmd_fname))
    chunks = nb.chunks
    # Identify questions
    questions = question_chunks(nb)
    # Detect mismatch
    mismatch = {}
    missing = []
    total = 0
    for question in questions:
        # Get marks allocated
        marks, out_of, r_total = [float(v) for v in get_marks(question.code)]
        total += marks
        assert total == r_total
        # Find following ok.grade chunk, if present.
        q_i = chunks.index(question)
        assert q_i >= 0
        test_name = ok_test_name(chunks[q_i + 1].code)
        if test_name is None:
            missing.append(chunks[q_i].code)
            continue
        # Load corresponding test
        test = load_test(op.join(tests_path, test_name + '.py'))
        # Check points same as marks allocated
        if test['points'] != marks:
            mismatch[test_name] = (test['points'], marks)
    return total, missing, mismatch
Ejemplo n.º 2
0
def process_dir(path, site_dict=None):
    site_dict = {} if site_dict is None else site_dict
    fnames = get_exercise_fnames(path)
    template = read_utf8(fnames['template'])
    if site_dict:
        template = Template(template).render(site=site_dict)
    write_utf8(fnames['exercise'], make_exercise(template))
    write_utf8(fnames['solution'], make_solution(template))
    clear_directory_for(fnames['exercise'])
Ejemplo n.º 3
0
def process_dir(path, out_path, grade=False, site_config=None):
    templates = [fn for fn in os.listdir(path) if TEMPLATE_RE.search(fn)]
    if len(templates) == 0:
        raise RuntimeError('No _template.Rmd in directory')
    if len(templates) > 1:
        raise RuntimeError('More than one _template.Rmd in directory')
    template_fname = op.join(path, templates[0])
    template = read_utf8(template_fname)
    if site_config:
        template = render_template(template, site_config)
    exercise_fname = TEMPLATE_RE.sub('.Rmd', template_fname)
    write_utf8(exercise_fname, make_exercise(template))
    solution_fname = TEMPLATE_RE.sub('_solution.Rmd', template_fname)
    write_utf8(solution_fname, make_solution(template))
    b_e.process_nb(exercise_fname, execute=False, out_path=out_path)
    if grade:
        gok.show_grade(solution_fname, op.join(path, 'tests'))
Ejemplo n.º 4
0
def check_points(rmd_fname, tests_path=None):
    if tests_path is None:
        tests_path = op.join(op.dirname(rmd_fname), 'tests')
    # Find chunks
    nb = loads(read_utf8(rmd_fname))
    chunks = nb.chunks
    # Identify questions
    questions = question_chunks(nb)
    for question in questions[:-1]:
        # Find following ok.grade chunk, if present.
        q_i = chunks.index(question)
        assert q_i >= 0
        test_name = ok_test_name(chunks[q_i + 1].code)
        if test_name is None:
            continue
        # Get marks allocated
        marks, out_of, running_total = get_marks(question.code)
        # Load corresponding test
        test = load_test(op.join(tests_path, test_name + '.py'))
        # Check points same as marks allocated
        assert test['points'] == float(marks)
Ejemplo n.º 5
0
def process_dir(path, grade=False, site_dict=None):
    site_dict = {} if site_dict is None else site_dict
    templates = [fn for fn in os.listdir(path) if TEMPLATE_RE.search(fn)]
    if len(templates) == 0:
        raise RuntimeError('No _template.Rmd in directory')
    if len(templates) > 1:
        raise RuntimeError('More than one _template.Rmd in directory')
    template_fname = op.join(path, templates[0])
    template = read_utf8(template_fname)
    if site_dict:
        template = Template(template).render(site=site_dict)
    exercise_fname = TEMPLATE_RE.sub('.Rmd', template_fname)
    write_utf8(exercise_fname, make_exercise(template))
    solution_fname = TEMPLATE_RE.sub('_solution.Rmd', template_fname)
    write_utf8(solution_fname, make_solution(template))
    process_write_nb(exercise_fname, execute=False)
    if grade:
        grades, messages = gok.grade_nb_fname(solution_fname, path)
        gok.print_grades(grades)
        gok.print_messages(messages)
        if not all(grades.values()):
            raise RuntimeError('One or more grades 0')