Exemplo n.º 1
0
    def test_raises_if_state_is_not_all(self, tmp_grades_file,
                                        mocked_hook_results):
        """Test that a warning is issued if the plugin is run on list-issues
        results where the state is not ``all`` (i.e. ``repobee list-issues``
        was not run with the ``--all`` flag). This is important as closed
        issues should still be taken into account.
        """
        args = argparse.Namespace(
            students=list(TEAMS),
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names="week-1 week-2 week-4 week-6".split(),
            edit_msg_file=str(tmp_grades_file.parent / "editmsg.txt"),
            teachers=list(TEACHERS),
            grade_specs=[PASS_GRADESPEC_FORMAT],
            allow_other_states=False,
        )
        mocked_hook_results["list-issues"] = [
            plug.HookResult(
                hook="list-issues",
                status=plug.Status.SUCCESS,
                msg=None,
                # change the state to OPEN, which will cause any closed
                # grading issues to be missed
                data={"state": plug.IssueState.OPEN.value},
            )
        ]

        with pytest.raises(_exception.FileError) as exc_info:
            csvgrades.callback(args=args, api=None)

        assert "repobee list-issues was not run with the --all flag" in str(
            exc_info.value)
Exemplo n.º 2
0
    def test_correctly_marks_passes(self, tmp_grades_file,
                                    mocked_hook_results):
        args = argparse.Namespace(
            students=list(TEAMS),
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names="week-1 week-2 week-4 week-6".split(),
            edit_msg_file=str(tmp_grades_file.parent / "editmsg.txt"),
            teachers=list(TEACHERS),
            grade_specs=[PASS_GRADESPEC_FORMAT],
            allow_other_states=False,
        )

        csvgrades.callback(args=args, api=None)

        assert _file.read_grades_file(
            tmp_grades_file) == _file.read_grades_file(EXPECTED_GRADES_FILE)
Exemplo n.º 3
0
    def test_repos_without_hook_results_are_skipped(self, tmp_grades_file,
                                                    mocked_hook_results):
        """Run with extra repos that have no hook results (week-3)"""
        args = argparse.Namespace(
            students=list(TEAMS),
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names="week-1 week-2 week-3 week-4 week-6".split(),
            edit_msg_file=str(tmp_grades_file.parent / "editmsg.txt"),
            teachers=list(TEACHERS),
            grade_specs=[PASS_GRADESPEC_FORMAT],
            allow_other_states=False,
        )

        csvgrades.callback(args=args, api=None)

        assert _file.read_grades_file(
            tmp_grades_file) == _file.read_grades_file(EXPECTED_GRADES_FILE)
Exemplo n.º 4
0
    def test_writes_edit_msg(self, tmp_grades_file, mocked_hook_results,
                             mocker):
        edit_msg_file = tmp_grades_file.parent / "editmsg.txt"
        args = argparse.Namespace(
            students=list(TEAMS),
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names="week-1 week-2 week-4 week-6".split(),
            edit_msg_file=str(edit_msg_file),
            teachers=list(TEACHERS),
            grade_specs=[PASS_GRADESPEC_FORMAT],
            allow_other_states=False,
        )

        csvgrades.callback(args=args, api=None)

        assert (edit_msg_file.read_text("utf8").strip() ==
                EXPECTED_EDIT_MSG_FILE.read_text("utf8").strip())
Exemplo n.º 5
0
    def test_writes_nothing_if_graders_are_not_teachers(
            self, tmp_grades_file, mocked_hook_results):
        edit_msg_file = tmp_grades_file.parent / "editmsg.txt"
        grades_file_contents = tmp_grades_file.read_text(encoding="utf8")
        args = argparse.Namespace(
            students=list(TEAMS),
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names="week-1 week-2 week-4 week-6".split(),
            edit_msg_file=str(edit_msg_file),
            teachers=["glassey", "slarse"],  # wrong teachers!
            grade_specs=[PASS_GRADESPEC_FORMAT],
            allow_other_states=False,
        )

        csvgrades.callback(args=args, api=None)

        assert tmp_grades_file.read_text("utf8") == grades_file_contents
        assert not edit_msg_file.exists()
Exemplo n.º 6
0
    def test_does_not_overwrite_lower_priority_grades(self, tmp_grades_file):
        """Test that e.g. a grade with priority 3 does not overwrite a grade
        with priority 1 that is already in the grades file.
        """
        shutil.copy(str(EXPECTED_GRADES_MULTI_SPEC_FILE), str(tmp_grades_file))
        slarse, *_ = TEAMS
        hook_result_mapping = {
            _marker.generate_repo_name(str(slarse), "week-4"):
            [create_komp_hookresult(SLARSE_TA)],
            "list-issues": [
                plug.HookResult(
                    hook="list-issues",
                    status=plug.Status.SUCCESS,
                    msg=None,
                    data={"state": plug.IssueState.ALL.value},
                )
            ],
        }
        grades_file_contents = tmp_grades_file.read_text("utf8")
        edit_msg_file = tmp_grades_file.parent / "editmsg.txt"
        args = argparse.Namespace(
            students=[slarse],
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names=["week-4"],
            edit_msg_file=str(edit_msg_file),
            teachers=list(TEACHERS),
            grade_specs=[PASS_GRADESPEC_FORMAT, KOMP_GRADESPEC_FORMAT],
            allow_other_states=False,
        )

        with mock.patch(
                "repobee_csvgrades._file.read_results_file",
                autospec=True,
                return_value=hook_result_mapping,
        ):
            csvgrades.callback(args=args, api=None)

        assert tmp_grades_file.read_text("utf8") == grades_file_contents
        assert not edit_msg_file.exists()
Exemplo n.º 7
0
    def test_students_missing_from_grades_file_causes_crash(
            self, tmp_grades_file, mocked_hook_results):
        """Test that if a specified student is missing from the grades
        file, there is a crash.
        """
        missing_team = plug.Team(members=["randomdude"])
        args = argparse.Namespace(
            students=list(TEAMS) + [missing_team],
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names="week-1 week-2 week-4 week-6".split(),
            edit_msg_file=str(tmp_grades_file.parent / "editmsg.txt"),
            teachers=list(TEACHERS),
            grade_specs=[PASS_GRADESPEC_FORMAT],
            allow_other_states=False,
        )

        with pytest.raises(_exception.FileError) as exc_info:
            csvgrades.callback(args=args, api=None)

        assert "student(s) {} missing from the grades file".format(
            missing_team.members[0]) in str(exc_info.value)
Exemplo n.º 8
0
    def test_multiple_specs(self, tmp_grades_file, mocked_hook_results):
        """Test that multiple specs works correctly, in the sense that they are
        all registered, but where there are multiple matching issues per repo,
        the grade spec with the lowest priority wins out.
        """
        edit_msg_file = tmp_grades_file.parent / "editmsg.txt"
        args = argparse.Namespace(
            students=list(TEAMS),
            hook_results_file="",  # don't care, read_results_file is mocked
            grades_file=str(tmp_grades_file),
            master_repo_names="week-1 week-2 week-4 week-6".split(),
            edit_msg_file=str(edit_msg_file),
            teachers=TEACHERS,
            grade_specs=[PASS_GRADESPEC_FORMAT, KOMP_GRADESPEC_FORMAT],
            allow_other_states=False,
        )

        csvgrades.callback(args=args, api=None)

        assert _file.read_grades_file(
            tmp_grades_file) == _file.read_grades_file(
                EXPECTED_GRADES_MULTI_SPEC_FILE)
        assert (edit_msg_file.read_text("utf8").strip() ==
                EXPECTED_EDIT_MSG_MULTI_SPEC_FILE.read_text("utf8").strip())