當前位置: 首頁>>代碼示例>>Python>>正文


Python content.SubredditContent類代碼示例

本文整理匯總了Python中rtv.content.SubredditContent的典型用法代碼示例。如果您正苦於以下問題:Python SubredditContent類的具體用法?Python SubredditContent怎麽用?Python SubredditContent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SubredditContent類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_content_subreddit_from_name

def test_content_subreddit_from_name(reddit, terminal):

    name = '/r/python'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python'
    assert content.order is None

    # Can submit without the /r/ and with the order in the name
    name = 'python/top/'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python'
    assert content.order == 'top'

    # Explicit order trumps implicit
    name = '/r/python/top'
    content = SubredditContent.from_name(
        reddit, name, terminal.loader, order='new')
    assert content.name == '/r/python'
    assert content.order == 'new'

    # Invalid order raises an exception
    name = '/r/python/fake'
    with terminal.loader():
        SubredditContent.from_name(reddit, name, terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.SubredditError)

    # Front page alias
    name = '/r/front/rising'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/front'
    assert content.order == 'rising'

    # Queries
    SubredditContent.from_name(reddit, 'front', terminal.loader, query='pea')
    SubredditContent.from_name(reddit, 'python', terminal.loader, query='pea')
開發者ID:rpesche,項目名稱:rtv,代碼行數:35,代碼來源:test_content.py

示例2: test_content_subreddit_from_name_invalid

def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):

    with terminal.loader():
        SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
    # Must always have an argument because it gets displayed
    assert terminal.loader.exception.args[0]
開發者ID:mardiqwop,項目名稱:rtv,代碼行數:7,代碼來源:test_content.py

示例3: test_content_subreddit_multireddit

def test_content_subreddit_multireddit(reddit, terminal):

    name = '/r/python+linux'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name == '/r/python+linux'

    # Invalid multireddit
    name = '/r/a+b'
    with terminal.loader():
        SubredditContent.from_name(reddit, name, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.NotFound)
開發者ID:prabhath6,項目名稱:rtv,代碼行數:11,代碼來源:test_content.py

示例4: test_content_subreddit_saved

def test_content_subreddit_saved(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/saved', terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.AccountError)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/saved', terminal.loader)
開發者ID:prabhath6,項目名稱:rtv,代碼行數:12,代碼來源:test_content.py

示例5: test_content_subreddit_from_name_authenticated

def test_content_subreddit_from_name_authenticated(
        prompt, name, order, reddit, terminal, oauth, refresh_token):

    with pytest.raises(exceptions.AccountError):
        SubredditContent.from_name(reddit, prompt, terminal.loader)

    # Login and try again
    oauth.config.refresh_token = refresh_token
    oauth.authorize()

    content = SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert content.name == name
    assert content.order == order
開發者ID:prabhath6,項目名稱:rtv,代碼行數:13,代碼來源:test_content.py

示例6: test_content_subreddit_load_more

def test_content_subreddit_load_more(reddit, terminal):

    submissions = reddit.get_front_page(limit=None)
    content = SubredditContent('front', submissions, terminal.loader)

    assert content.get(50)['type'] == 'Submission'
    assert len(content._submission_data) == 51

    for data in islice(content.iterate(0, 1), 0, 50):
        assert all(k in data for k in ('object', 'n_rows', 'offset', 'type',
                                       'index', 'title', 'split_title'))
        # All text should be converted to unicode by this point
        for val in data.values():
            assert not isinstance(val, six.binary_type)
開發者ID:rpesche,項目名稱:rtv,代碼行數:14,代碼來源:test_content.py

示例7: test_content_subreddit_me

def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):

    # Not logged in
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/me', terminal.loader)
    assert isinstance(terminal.loader.exception, exceptions.AccountError)

    # Logged in
    oauth.config.refresh_token = refresh_token
    oauth.authorize()
    with terminal.loader():
        SubredditContent.from_name(reddit, '/u/me', terminal.loader)

    # If there is no submitted content, an error should be raised
    if terminal.loader.exception:
        assert isinstance(terminal.loader.exception, exceptions.SubredditError)
開發者ID:prabhath6,項目名稱:rtv,代碼行數:16,代碼來源:test_content.py

示例8: test_content_subreddit_from_name_order

def test_content_subreddit_from_name_order(reddit, terminal):

    # Explicit order trumps implicit
    name = '/r/python/top'
    content = SubredditContent.from_name(
        reddit, name, terminal.loader, order='new')
    assert content.name == '/r/python'
    assert content.order == 'new'
開發者ID:prabhath6,項目名稱:rtv,代碼行數:8,代碼來源:test_content.py

示例9: test_content_subreddit_load_more

def test_content_subreddit_load_more(reddit, terminal):

    submissions = reddit.get_front_page(limit=None)
    content = SubredditContent('front', submissions, terminal.loader)

    assert content.get(50)['type'] == 'Submission'
    assert content.range == (0, 50)

    for i, data in enumerate(islice(content.iterate(0, 1), 0, 50)):
        assert all(k in data for k in ('object', 'n_rows', 'offset', 'type',
                                       'index', 'title', 'split_title'))
        # All text should be converted to unicode by this point
        for val in data.values():
            assert not isinstance(val, six.binary_type)

        # Index be appended to each title, starting at "1." and incrementing
        assert data['index'] == i + 1
        assert data['title'].startswith(six.text_type(i + 1))
開發者ID:prabhath6,項目名稱:rtv,代碼行數:18,代碼來源:test_content.py

示例10: test_content_subreddit

def test_content_subreddit(reddit, terminal):

    submissions = reddit.get_front_page(limit=5)
    content = SubredditContent('front', submissions, terminal.loader)

    # Submissions are loaded on demand, excluding for the first one
    assert len(content._submission_data) == 1
    assert content.get(0)['type'] == 'Submission'

    for data in content.iterate(0, 1):
        assert all(k in data for k in ('object', 'n_rows', 'offset', 'type',
                                       'index', 'title', 'split_title'))
        # All text should be converted to unicode by this point
        for val in data.values():
            assert not isinstance(val, six.binary_type)

    # Out of bounds
    with pytest.raises(IndexError):
        content.get(-1)
    with pytest.raises(IndexError):
        content.get(5)
開發者ID:rpesche,項目名稱:rtv,代碼行數:21,代碼來源:test_content.py

示例11: test_content_subreddit_random

def test_content_subreddit_random(reddit, terminal):

    name = '/r/random'
    content = SubredditContent.from_name(reddit, name, terminal.loader)
    assert content.name.startswith('/r/')
    assert content.name != name
開發者ID:prabhath6,項目名稱:rtv,代碼行數:6,代碼來源:test_content.py

示例12: test_content_subreddit_from_name_query

def test_content_subreddit_from_name_query(prompt, query, reddit, terminal):

    SubredditContent.from_name(reddit, prompt, terminal.loader, query=query)
開發者ID:prabhath6,項目名稱:rtv,代碼行數:3,代碼來源:test_content.py

示例13: test_content_subreddit_from_name_invalid

def test_content_subreddit_from_name_invalid(prompt, reddit, terminal):

    with terminal.loader():
        SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert isinstance(terminal.loader.exception, praw.errors.InvalidSubreddit)
開發者ID:prabhath6,項目名稱:rtv,代碼行數:5,代碼來源:test_content.py

示例14: test_content_subreddit_from_name

def test_content_subreddit_from_name(prompt, name, order, reddit, terminal):

    content = SubredditContent.from_name(reddit, prompt, terminal.loader)
    assert content.name == name
    assert content.order == order
開發者ID:prabhath6,項目名稱:rtv,代碼行數:5,代碼來源:test_content.py


注:本文中的rtv.content.SubredditContent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。