<commit_before>from .base import BaseTest, expect, str_test
from datetime import datetime
from github3.git import Commit
from github3.pulls import (PullRequest, PullDestination, ReviewComment,
        PullFile)
from github3.users import User


class TestPullRequest(BaseTest):
    def __init__(self, methodName='runTest'):
        super(TestPullRequest, self).__init__(methodName)
        repo = self.g.repository(self.kr, 'requests')
        self.pr = repo.pull_request(833)
        self.body = [
        ('Use dicts and lists where necessary but accept both dicts and lists'
            ' of'), '2-tuples everywhere.'
        ]
        self.body_html = [
        ('<p>'
         'Use dicts and lists where necessary but accept both dicts and lists'
         ' of'
         '<br>'),
         '2-tuples everywhere.</p>'
        ]
        self.url = 'https://github.com/{0}/requests/pull/833'.format(self.kr)

    def test_pull_request(self):
        expect(self.pr).isinstance(PullRequest)
        expect(repr(self.pr)) != ''

    def test_base(self):
        expect(self.pr.base).is_not_None()
        expect(self.pr.base).isinstance(PullDestination)
        expect(self.pr.base.label) == 'kennethreitz:develop'

    def test_body(self):
        expect(self.pr.body).isinstance(str_test)
        body = '\n'.join(self.body)
        expect(self.pr.body) == body

    def test_body_html(self):
        expect(self.pr.body_html).isinstance(str_test)
        body = '\n'.join(self.body_html)
        expect(self.pr.body_html) == body

    def test_body_text(self):
        expect(self.pr.body_text).isinstance(str_test)
        body = '\n'.join(self.body)
        expect(self.pr.body_text) == body

    def test_closed_at(self):
        expect(self.pr.closed_at).isinstance(datetime)

    def test_created_at(self):
        expect(self.pr.created_at).isinstance(datetime)

    def test_diff_url(self):
        url = self.pr.diff_url
        expect(url).isinstance(str_test)
        expect(url) == self.url + '.diff'

    def test_head(self):
        head = self.pr.head
        label = head.label
        expect(head).isinstance(PullDestination)
        expect(label) == 'sigmavirus24:fix_key_val_args'

    def test_html_url(self):
        url = self.pr.html_url
        expect(url).isinstance(str_test)
        expect(url) == self.url

    def test_id(self):
        expect(self.pr.id) == 2228458

    def test_is_mergeable(self):
        expect(self.pr.is_mergeable()).is_False()

    def test_is_merged(self):
        expect(self.pr.is_merged()).is_True()

    def test_issue_url(self):
        expect(self.pr.issue_url).isinstance(str_test)
        expect(self.pr.issue_url) == self.url.replace('pull', 'issues')

    def test_links(self):
        expect(self.pr.links).isinstance(dict)
        links = ['comments', 'html', 'issue', 'review_comments', 'self']
        expect(sorted(list(self.pr.links.keys()))) == links

    def test_list_comments(self):
        comments = self.pr.list_comments()
        self.expect_list_of_class(comments, ReviewComment)

    def test_list_commits(self):
        commits = self.pr.list_commits()
        self.expect_list_of_class(commits, Commit)

    def test_list_files(self):
        files = self.pr.list_files()
        self.expect_list_of_class(files, PullFile)

    def test_merged_at(self):
        expect(self.pr.merged_at).isinstance(datetime)

    def test_merged_by(self):
        u = self.pr.merged_by
        expect(u).isinstance(User)
        expect(u.login) == self.kr

    def test_number(self):
        expect(self.pr.number) == 833

    def test_patch_url(self):
        expect(self.pr.patch_url).isinstance(str_test)
        expect(self.pr.patch_url) == self.url + '.patch'

    def test_requires_auth(self):
        self.raisesGHE(self.pr.merge, 'foo bar')
        self.raisesGHE(self.pr.update, 'New title')

    def test_state(self):
        expect(self.pr.state) == 'closed'

    def test_title(self):
        expect(self.pr.title) == 'Fixes #817.'

    def test_user(self):
        expect(self.pr.user).isinstance(User)
        expect(self.pr.user.login) == self.sigm

    def test_with_auth(self):
        if not self.auth:
            return
        r = self._g.repository(self.gh3py, self.test_repo)
        pr = r.pull_request(2)
        title, body, state = pr.title, pr.body, pr.state
        expect(pr.update('Test editing', 'New body')).is_True()
        expect(pr.update(title, body, state)).is_True()
        expect(pr.update()).is_False()


class TestReviewComment(BaseTest):
    def __init__(self, methodName='runTest'):
        super(TestReviewComment, self).__init__(methodName)
        repo = self.g.repository(self.kr, 'requests')
        self.comment = repo.pull_request(819).list_comments()[0]

    def test_review_comment(self):
        expect(self.comment).isinstance(ReviewComment)
        expect(repr(self.comment)) != ''

    def test_body(self):
        expect(self.comment.body).isinstance(str_test)

    def test_body_html(self):
        html = self.comment.body_html
        if html:
            expect(html).isinstance(str_test)

    def test_body_text(self):
        text = self.comment.body_text<commit_msg>Let's see if this fixes the Problems with JSON<commit_after>from .base import BaseTest, expect, str_test
from datetime import datetime
from github3.git import Commit
from github3.pulls import (PullRequest, PullDestination, ReviewComment,
        PullFile)
from github3.users import User


class TestPullRequest(BaseTest):
    def __init__(self, methodName='runTest'):
        super(TestPullRequest, self).__init__(methodName)
        repo = self.g.repository(self.kr, 'requests')
        self.pr = repo.pull_request(833)
        self.body = [
        ('Use dicts and lists where necessary but accept both dicts and lists'
            ' of'), '2-tuples everywhere.'
        ]
        self.body_html = [
        ('<p>'
         'Use dicts and lists where necessary but accept both dicts and lists'
         ' of'
         '<br>'),
         '2-tuples everywhere.</p>'
        ]
        self.url = 'https://github.com/{0}/requests/pull/833'.format(self.kr)

    def test_pull_request(self):
        expect(self.pr).isinstance(PullRequest)
        expect(repr(self.pr)) != ''

    def test_base(self):
        expect(self.pr.base).is_not_None()
        expect(self.pr.base).isinstance(PullDestination)
        expect(self.pr.base.label) == 'kennethreitz:develop'

    def test_body(self):
        expect(self.pr.body).isinstance(str_test)
        body = '\n'.join(self.body)
        expect(self.pr.body) == body

    def test_body_html(self):
        expect(self.pr.body_html).isinstance(str_test)
        body = '\n'.join(self.body_html)
        expect(self.pr.body_html) == body

    def test_body_text(self):
        expect(self.pr.body_text).isinstance(str_test)
        body = '\n'.join(self.body)
        expect(self.pr.body_text) == body

    def test_closed_at(self):
        expect(self.pr.closed_at).isinstance(datetime)

    def test_created_at(self):
        expect(self.pr.created_at).isinstance(datetime)

    def test_diff_url(self):
        url = self.pr.diff_url
        expect(url).isinstance(str_test)
        expect(url) == self.url + '.diff'

    def test_head(self):
        head = self.pr.head
        label = head.label
        expect(head).isinstance(PullDestination)
        expect(label) == 'sigmavirus24:fix_key_val_args'

    def test_html_url(self):
        url = self.pr.html_url
        expect(url).isinstance(str_test)
        expect(url) == self.url

    def test_id(self):
        expect(self.pr.id) == 2228458

    def test_is_mergeable(self):
        expect(self.pr.is_mergeable()).is_False()

    def test_is_merged(self):
        expect(self.pr.is_merged()).is_True()

    def test_issue_url(self):
        expect(self.pr.issue_url).isinstance(str_test)
        expect(self.pr.issue_url) == self.url.replace('pull', 'issues')

    def test_links(self):
        expect(self.pr.links).isinstance(dict)
        links = ['comments', 'html', 'issue', 'review_comments', 'self']
        expect(sorted(list(self.pr.links.keys()))) == links

    def test_list_comments(self):
        comments = self.pr.list_comments()
        self.expect_list_of_class(comments, ReviewComment)

    def test_list_commits(self):
        commits = self.pr.list_commits()
        self.expect_list_of_class(commits, Commit)

    def test_list_files(self):
        files = self.pr.list_files()
        self.expect_list_of_class(files, PullFile)

    def test_merged_at(self):
        expect(self.pr.merged_at).isinstance(datetime)

    def test_merged_by(self):
        u = self.pr.merged_by
        expect(u).isinstance(User)
        expect(u.login) == self.kr

    def test_number(self):
        expect(self.pr.number) == 833

    def test_patch_url(self):
        expect(self.pr.patch_url).isinstance(str_test)
        expect(self.pr.patch_url) == self.url + '.patch'

    def test_requires_auth(self):
        self.raisesGHE(self.pr.merge, 'foo bar')
        self.raisesGHE(self.pr.update, 'New title')

    def test_state(self):
        expect(self.pr.state) == 'closed'

    def test_title(self):
        expect(self.pr.title) == 'Fixes #817.'

    def test_user(self):
        expect(self.pr.user).isinstance(User)
        expect(self.pr.user.login) == self.sigm

    def test_with_auth(self):
        if not self.auth:
            return
        r = self._g.repository(self.gh3py, self.test_repo)
        pr = r.pull_request(2)
        title, body, state = pr.title, pr.body, pr.state
        expect(pr.update('Test editing', 'New body', 'open')).is_True()
        expect(pr.update(title, body, state)).is_True()
        expect(pr.update()).is_False()


class TestReviewComment(BaseTest):
    def __init__(self, methodName='runTest'):
        super(TestReviewComment, self).__init__(methodName)
        repo = self.g.repository(self.kr, 'requests')
        self.comment = repo.pull_request(819).list_comments()[0]

    def test_review_comment(self):
        expect(self.comment).isinstance(ReviewComment)
        expect(repr(self.comment)) != ''

    def test_body(self):
        expect(self.comment.body).isinstance(str_test)

    def test_body_html(self):
        html = self.comment.body_html
        if html:
            expect(html).isinstance(str_test)

    def test_body_text(self):
        text = self.comment.body_text
{'fraction_non_alphanumeric': 0.13162180285467956, 'fraction_numerical': 0.006322444678609062, 'mean_word_length': 2.7526959022286124, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2599598', 'n_tokens_mistral': 3483, 'n_tokens_neox': 3358, 'n_words': 560}