<commit_before>"""Unit tests for the github3.pulls module."""
import json
import os

from .helper import UnitHelper, UnitIteratorHelper, create_url_helper

from github3.pulls import PullRequest


def get_pr_example_data():
    """Load the example data for the PullRequest object."""
    directory = os.path.dirname(__file__)
    example = os.path.join(directory, 'pull_request_example')
    with open(example) as fd:
        data = json.load(fd)
    return data


url_for = create_url_helper(
    'https://api.github.com/repos/octocat/Hello-World/pulls/1'
)


class TestPullRequest(UnitHelper):

    """PullRequest unit tests."""

    described_class = PullRequest
    example_data = get_pr_example_data()

    def test_diff(self):
        """Show that a user can request the diff of a Pull Request."""
        self.instance.diff()

        self.session.get.assert_called_once_with(
            url_for(),
            headers={'Accept': 'application/vnd.github.diff'}
        )
<commit_msg>Test that PullRequest#close requires authentication<commit_after>"""Unit tests for the github3.pulls module."""
import json
import os
import pytest

from .helper import UnitHelper, UnitIteratorHelper, create_url_helper

from github3 import GitHubError
from github3.pulls import PullRequest


def get_pr_example_data():
    """Load the example data for the PullRequest object."""
    directory = os.path.dirname(__file__)
    example = os.path.join(directory, 'pull_request_example')
    with open(example) as fd:
        data = json.load(fd)
    return data


url_for = create_url_helper(
    'https://api.github.com/repos/octocat/Hello-World/pulls/1'
)


class TestPullRequest(UnitHelper):

    """PullRequest unit tests."""

    described_class = PullRequest
    example_data = get_pr_example_data()

    def test_diff(self):
        """Show that a user can request the diff of a Pull Request."""
        self.instance.diff()

        self.session.get.assert_called_once_with(
            url_for(),
            headers={'Accept': 'application/vnd.github.diff'}
        )


class TestPullRequestRequiresAuthentication(UnitHelper):

    """PullRequest unit tests that demonstrate which methods require auth."""

    described_class = PullRequest
    example_data = get_pr_example_data()

    def after_setup(self):
        """Make it appear as if the user has not authenticated."""
        self.session.has_auth.return_value = False

    def test_close(self):
        """Show that you must be authenticated to close a Pull Request."""
        with pytest.raises(GitHubError):
            self.instance.close()


{'fraction_non_alphanumeric': 0.101076095311299, 'fraction_numerical': 0.002690238278247502, 'mean_word_length': 3.3747899159663866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6478490', 'n_tokens_mistral': 768, 'n_tokens_neox': 732, 'n_words': 203}