コード例 #1
0
    def test_strip_flag(self, fake_repo):
        """Tests that stripping a file works properly"""
        file_name = "valid-shred-marker.in"
        file_src_path = fake_repo.path / file_name
        shutil.copy(testhelpers.get_resource(file_name), file_src_path)

        run_repobee(
            f"sanitize file {file_src_path} {file_src_path} --strip".split())

        assert file_src_path.is_file()
コード例 #2
0
    def test_does_not_creat_file_with_shred_marker(self, sanitizer_config,
                                                   fake_repo):
        """Test that sanitize-file removes a file containing a shred marker."""
        file_name = "valid-shred-marker.in"
        file_src_path = fake_repo.path / file_name
        file_dst_path = fake_repo.path / "inverse.out"
        shutil.copy(testhelpers.get_resource(file_name), file_src_path)

        run_repobee(f"sanitize file {file_src_path} {file_dst_path}".split())

        assert not file_dst_path.is_file()
コード例 #3
0
    def test_no_commit_invalid_file_return_error_status(self, fake_repo):
        file_name = "missing-end-marker.in"
        file_src_path = fake_repo.path / file_name
        shutil.copy(testhelpers.get_resource(file_name), file_src_path)
        fake_repo.repo.git.add(file_src_path)
        fake_repo.repo.git.commit("-m", "'Initial commit'")

        result = run_repobee(
            f"sanitize repo --no-commit --repo-root {fake_repo.path}".split())

        assert (result.status == plug.Status.ERROR
                and "START block must begin file or follow an END block"
                in result.msg)
コード例 #4
0
    def test_target_branch_with_iso8859_file(self, fake_repo):
        """Test sanitize-repo when there are ISO8859 files in the repo. This is to
        ensure that we can sanitize using ISO8859 without errors.
        """
        in_src_path = testhelpers.get_resource("iso8859.txt")
        in_dst_path = fake_repo.path / in_src_path.name
        shutil.copy(in_src_path, in_dst_path)

        sanitized_src_path = testhelpers.get_resource("sanitized-iso8859.txt")
        sanitized_dst_path = fake_repo.path / sanitized_src_path.name
        shutil.copy(sanitized_src_path, sanitized_dst_path)

        fake_repo.repo.git.add(sanitized_dst_path)
        fake_repo.repo.git.add(in_dst_path)
        fake_repo.repo.git.commit("-m", "Add ISO8859 files")

        in_rel = _fileutils.create_relpath(in_dst_path, fake_repo.path)
        sanitzed_rel = _fileutils.create_relpath(sanitized_dst_path,
                                                 fake_repo.path)

        fake_repo.file_infos.append(
            _FileInfo(
                original_text=in_rel.read_text_relative_to(fake_repo.path),
                expected_text=sanitzed_rel.read_text_relative_to(
                    fake_repo.path),
                abspath=in_dst_path,
                relpath=in_rel.__str__(),
                encoding=in_rel.encoding,
            ))

        target_branch = "student-version"
        run_repobee(f"sanitize repo --target-branch {target_branch} "
                    f"--repo-root {fake_repo.path}".split())

        fake_repo.repo.git.checkout(target_branch)
        fake_repo.repo.git.reset("--hard")
        assert_expected_text_in_files(fake_repo.file_infos)
コード例 #5
0
    def test_invalid_file_return_error_status(self, fake_repo):
        """Test that sanitize-file returns a PlugResult with status ERROR when
        file has invalid syntax
        """
        file_name = "missing-end-marker.in"
        file_src_path = fake_repo.path / file_name
        shutil.copy(testhelpers.get_resource(file_name), file_src_path)

        fake_repo.repo.git.add(file_src_path)
        fake_repo.repo.git.commit("-m", "'Initial commit'")

        result = run_repobee(
            f"sanitize file {file_src_path} {file_src_path}".split())

        assert (result.status == plug.Status.ERROR
                and "START block must begin file or follow an END block"
                in result.msg)
コード例 #6
0
    def test_removes_file_with_shred_marker(self, sanitizer_config, fake_repo):
        """Test that sanitize-repo does not send any files that contain a shred
        marker to target-branch
        """
        file_name = "valid-shred-marker.in"
        file_src_path = testhelpers.get_resource(file_name)
        file_dst_path = fake_repo.path / file_name
        shutil.copy(file_src_path, file_dst_path)

        fake_repo.repo.git.add(file_dst_path)
        fake_repo.repo.git.commit("-m", "Add shred file")

        target_branch = "student-version"
        run_repobee(f"sanitize repo --target-branch {target_branch} "
                    f"--repo-root {fake_repo.path}".split())

        fake_repo.repo.git.checkout(target_branch)
        fake_repo.repo.git.reset("--hard")
        assert not file_dst_path.is_file()