# Path: tabun_api/compat.py
# PY2 = sys.version_info.major == 2


import time
import json
import pytest
import tabun_api as api
from io import BytesIO
from tabun_api.compat import text, binary
from testutil import UserTest, load_file, form_intercept, set_mock, user, assert_data
    ('/blog/132085.html', '132085_comments.json', False),
    (None, 'comments.json', True)
])
def test_get_comments(user, url, data_file, rev):
    comments_data = json.loads(load_file(data_file, template=False).decode('utf-8'))
    if url:
        comments = user.get_comments(url)
    else:
        comments = user.get_comments()

    assert list(sorted(comments.keys(), reverse=rev)) == [x['comment_id'] for x in comments_data]

    for data in comments_data:
        comment = comments[data['comment_id']]
        assert data['comment_id'] == comment.comment_id
        assert_data(comment, data)


def test_get_comments_types_ok(user):
    comments = user.get_comments()
    comments.update(user.get_comments('/blog/132085.html'))
    for comment_id, comment in comments.items():
        assert isinstance(comment_id, int)
        assert comment.blog is None or isinstance(comment.blog, text)
        if comment.deleted:
            assert comment.author is None
            assert comment.raw_body is None
            assert comment.vote_total is None
        else:
            assert isinstance(comment.author, text)

# Path: tabun_api/compat.py
# PY2 = sys.version_info.major == 2


# Path: test/test_comments.py
import time
import json
import pytest
import tabun_api as api
from io import BytesIO
from tabun_api.compat import text, binary
from testutil import UserTest, load_file, form_intercept, set_mock, user, assert_data

    ('/blog/132085.html', '132085_comments.json', False),
    (None, 'comments.json', True)
])
def test_get_comments(user, url, data_file, rev):
    comments_data = json.loads(load_file(data_file, template=False).decode('utf-8'))
    if url:
        comments = user.get_comments(url)
    else:
        comments = user.get_comments()

    assert list(sorted(comments.keys(), reverse=rev)) == [x['comment_id'] for x in comments_data]

    for data in comments_data:
        comment = comments[data['comment_id']]
        assert data['comment_id'] == comment.comment_id
        assert_data(comment, data)


def test_get_comments_types_ok(user):
    comments = user.get_comments()
    comments.update(user.get_comments('/blog/132085.html'))
    for comment_id, comment in comments.items():
        assert isinstance(comment_id, int)
        assert comment.blog is None or isinstance(comment.blog, text)
        if comment.deleted:
            assert comment.author is None
            assert comment.raw_body is None
            assert comment.vote_total is None
        else:
            assert isinstance(comment.author, text)

            assert isinstance(comment.raw_body, text)