本文整理汇总了Python中rtv.content.SubredditContent.get方法的典型用法代码示例。如果您正苦于以下问题:Python SubredditContent.get方法的具体用法?Python SubredditContent.get怎么用?Python SubredditContent.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rtv.content.SubredditContent
的用法示例。
在下文中一共展示了SubredditContent.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_content_subreddit
# 需要导入模块: from rtv.content import SubredditContent [as 别名]
# 或者: from rtv.content.SubredditContent import get [as 别名]
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)
示例2: test_content_subreddit_load_more
# 需要导入模块: from rtv.content import SubredditContent [as 别名]
# 或者: from rtv.content.SubredditContent import get [as 别名]
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)
示例3: test_content_subreddit_load_more
# 需要导入模块: from rtv.content import SubredditContent [as 别名]
# 或者: from rtv.content.SubredditContent import get [as 别名]
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))