Beispiel #1
0
    def test_mandatory_property(self, mock):
        mock.side_effect = self.save_grade

        enter_quiet_mode()

        record_result(True, '', '', '')
        grade()

        self.assertEqual(self.grade, 2,
                         'if all tests are passed, the grade should be 2')

        record_result(False, '', '', '', should_succeed=False)
        grade()

        self.assertEqual(
            self.grade, 5,
            'no positive grade without passing one positive test')

        record_result(False, '', '', '', should_succeed=False)
        record_result(True, '', '', '', should_succeed=True)
        grade()

        self.assertEqual(self.grade, 2,
                         'postive grade with at least one positive test')

        record_result(True, '', '', '', should_succeed=True)
        record_result(True, '', '', '', should_succeed=True)
        record_result(True, '', '', '', should_succeed=True)
        record_result(True, '', '', '', should_succeed=True)
        record_result(False, '', '', '', should_succeed=True, mandatory=True)
        grade()

        self.assertEqual(self.grade, 5,
                         'can not pass when failing a mandatory test')
def process_arguments(argv: List[str], assignments: List[Assignment], baseline: List[Assignment]):
    all_assignments = baseline + assignments

    def curried_parse_assignment(assignment: str) -> Optional[Assignment]:
        return parse_assignment(assignment, all_assignments)

    parser = ArgumentParser(argv[0], formatter_class=RawDescriptionHelpFormatter,
            description=GRADER_SYNOPSIS, epilog=list_assignments_str(all_assignments))

    parser.add_argument('-q', action='store_true', default=False,
            help='print grade only', dest='quiet')
    parser.add_argument('-b', default=None, metavar="<file>",
            help='bulk grade assignments given as github commit links in file',
            dest='bulk_file')
    parser.add_argument('-d', default=None, metavar="<directory>",
            help='directory where all bulk-graded repositories are stored',
            dest='bulk_directory')
    parser.add_argument('--truncate', metavar=('trailing', 'leading'), nargs=2,
            type=parse_truncate_range,
            help='truncates the amount of leading and trailing lines',
            dest='truncate')
    parser.add_argument('assignment', metavar='assignment', nargs='?',
            type=curried_parse_assignment, help='grade this assignment')

    try:
        if len(argv) <= 1:
            parser.print_help()
            exit()

        set_home_path(Path(os.path.abspath(os.path.dirname(argv[0]))))

        args = parser.parse_args(argv[1:])

        if args.quiet:
            enter_quiet_mode()

        if args.truncate:
            set_truncate(*args.truncate)

        if args.bulk_file:
            enable_bulk_grader(args.bulk_file)

        if args.bulk_directory:
            set_bulk_grade_directory(args.bulk_directory)

        validate_options_for(args.assignment)

        if bulk_grade_mode:
            do_bulk_grading(args.assignment, baseline)
        else:
            check_assignment(args.assignment, baseline)

    finally:
        reset_state()
Beispiel #3
0
def do_bulk_grading(assignment, base_test):
    enter_quiet_mode()

    if not os.path.exists(bulk_grade_directory):
        os.mkdir(bulk_grade_directory)

    working_directory = os.getcwd()

    os.chdir(bulk_grade_directory)

    with open(file_with_commit_links, 'rt') as file:
        for line in file.readlines():
            matcher = re.match(
                '^https://github.com/([^/]+)/([^/]+)/commit/([0-9a-f]+)$',
                line)

            if matcher is None:
                print('the link "' + line +
                      '" is not a valid github commit link')
                exit(1)

            user = matcher.group(1)
            repo = matcher.group(2)
            commit = matcher.group(3)

            clone_dir = os.path.join(bulk_grade_directory,
                                     '{}/{}'.format(user, repo))

            if not os.path.exists(clone_dir):
                os.system('git clone -q https://github.com/{}/{} {}/{}'.format(
                    user, repo, user, repo))

            os.chdir(clone_dir)

            # remove all changes in local repository
            os.system('git reset --hard -q')

            # fetch updates from github repository
            os.system('git fetch -q')

            # change the local repository state using the commit ID
            os.system('git checkout -q {}'.format(commit))

            print_loud('{}/{}: '.format(user, repo), end='')
            check_assignment(assignment, base_test)
            print_loud('')

            os.chdir(bulk_grade_directory)

    os.chdir(working_directory)

    if bulk_grade_directory is DEFAULT_BULK_GRADE_DIRECTORY:
        os.system('rm -rf {}'.format(bulk_grade_directory))
Beispiel #4
0
def process_arguments(argv: List[str], assignments: Set[Assignment],
                      baseline: Assignment):
    def curried_parse_assignment(assignment: str) -> Optional[Assignment]:
        return parse_assignment(assignment, assignments)

    parser = ArgumentParser(argv[0],
                            formatter_class=RawDescriptionHelpFormatter,
                            description=GRADER_SYNOPSIS,
                            epilog=list_assignments_str(assignments))

    parser.add_argument('-q',
                        action='store_true',
                        default=False,
                        help='only the grade is printed',
                        dest='quiet')
    parser.add_argument(
        '-b',
        default=None,
        metavar="<file>",
        help=
        'bulk grade assignments defined by a file with github commit links',
        dest='bulk_file')
    parser.add_argument(
        '-d',
        default=None,
        metavar="<directory>",
        help='path where all bulk graded repositories should be saved',
        dest='bulk_directory')
    parser.add_argument('assignment',
                        metavar='assignment',
                        nargs='?',
                        type=curried_parse_assignment,
                        help='The assignment to test')

    try:
        if len(argv) <= 1:
            parser.print_help()
            exit()

        set_home_path(Path(os.path.abspath(os.path.dirname(argv[0]))))

        args = parser.parse_args(argv[1:])

        if args.quiet:
            enter_quiet_mode()

        if args.bulk_file:
            enable_bulk_grader(args.bulk_file)

        if args.bulk_directory:
            set_bulk_grade_directory(args.bulk_directory)

        validate_options_for(args.assignment)

        if bulk_grade_mode:
            do_bulk_grading(args.assignment, baseline)
        else:
            check_assignment(args.assignment, baseline)

    finally:
        reset_state()