Simplify score and comment count data
This commit changes the functionality of the Content class (and its subclasses) by removing the text from the comments and score fields of Reddit data dictionaries created by Content.strip*. data['comments'] is now an integer, but data['score'] remains a string to preserve using '-' when the score is hidden. It is now the responsibility of wherever this data is used to provide the extra text that these variables used to include, and modifications have been made to the Submission and Subreddit classes to preserve the previous way the data was displayed. Tests modified to expect these changes.
This commit is contained in:
@@ -736,9 +736,9 @@ def test_subreddit_page__create_format(terminal, subreddit_page):
|
|||||||
data = {
|
data = {
|
||||||
'index': '1',
|
'index': '1',
|
||||||
'title': 'Without saying what the category is, what are your top five?',
|
'title': 'Without saying what the category is, what are your top five?',
|
||||||
'score': '144655 pts',
|
'score': '144655',
|
||||||
'likes': True,
|
'likes': True,
|
||||||
'comments': '26584 comments',
|
'comments': '26584',
|
||||||
'created': '10month',
|
'created': '10month',
|
||||||
'edited': '(edit 5month)',
|
'edited': '(edit 5month)',
|
||||||
'author': 'reddit_user',
|
'author': 'reddit_user',
|
||||||
@@ -858,7 +858,8 @@ def test_subreddit_page__create_format(terminal, subreddit_page):
|
|||||||
assert format_list[6][0](data) == expected_str['%n'] + ' '
|
assert format_list[6][0](data) == expected_str['%n'] + ' '
|
||||||
else:
|
else:
|
||||||
# General case
|
# General case
|
||||||
assert format_list[1][0](data) == expected_str[fmt]
|
assert format_list[1][0](data) == expected_str[fmt], \
|
||||||
|
"On specifier {0}".format(fmt)
|
||||||
format_list[1][1](data)
|
format_list[1][1](data)
|
||||||
|
|
||||||
terminal.attr.assert_called_with(expected_attr[fmt])
|
terminal.attr.assert_called_with(expected_attr[fmt])
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ class Content(object):
|
|||||||
data['body'] = comment.body
|
data['body'] = comment.body
|
||||||
data['html'] = comment.body_html
|
data['html'] = comment.body_html
|
||||||
data['created'] = cls.humanize_timestamp(comment.created_utc)
|
data['created'] = cls.humanize_timestamp(comment.created_utc)
|
||||||
data['score'] = '{0} pts'.format(
|
data['score'] = '{0}'.format(
|
||||||
'-' if comment.score_hidden else comment.score)
|
'-' if comment.score_hidden else comment.score)
|
||||||
data['author'] = name
|
data['author'] = name
|
||||||
data['is_author'] = (name == sub_name)
|
data['is_author'] = (name == sub_name)
|
||||||
@@ -187,7 +187,7 @@ class Content(object):
|
|||||||
data['nsfw'] = comment.over_18
|
data['nsfw'] = comment.over_18
|
||||||
data['subreddit'] = six.text_type(comment.subreddit)
|
data['subreddit'] = six.text_type(comment.subreddit)
|
||||||
data['url_type'] = 'selfpost'
|
data['url_type'] = 'selfpost'
|
||||||
data['score'] = '{0} pts'.format(
|
data['score'] = '{0}'.format(
|
||||||
'-' if comment.score_hidden else comment.score)
|
'-' if comment.score_hidden else comment.score)
|
||||||
data['likes'] = comment.likes
|
data['likes'] = comment.likes
|
||||||
data['created'] = cls.humanize_timestamp(comment.created_utc)
|
data['created'] = cls.humanize_timestamp(comment.created_utc)
|
||||||
@@ -233,8 +233,8 @@ class Content(object):
|
|||||||
data['html'] = sub.selftext_html or ''
|
data['html'] = sub.selftext_html or ''
|
||||||
data['created'] = cls.humanize_timestamp(sub.created_utc)
|
data['created'] = cls.humanize_timestamp(sub.created_utc)
|
||||||
data['created_long'] = cls.humanize_timestamp(sub.created_utc, True)
|
data['created_long'] = cls.humanize_timestamp(sub.created_utc, True)
|
||||||
data['comments'] = '{0} comments'.format(sub.num_comments)
|
data['comments'] = sub.num_comments
|
||||||
data['score'] = '{0} pts'.format('-' if sub.hide_score else sub.score)
|
data['score'] = '{0}'.format('-' if sub.hide_score else sub.score)
|
||||||
data['author'] = name
|
data['author'] = name
|
||||||
data['permalink'] = sub.permalink
|
data['permalink'] = sub.permalink
|
||||||
data['subreddit'] = six.text_type(sub.subreddit)
|
data['subreddit'] = six.text_type(sub.subreddit)
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ class SubmissionPage(Page):
|
|||||||
|
|
||||||
attr = self.term.attr('Score')
|
attr = self.term.attr('Score')
|
||||||
self.term.add_space(win)
|
self.term.add_space(win)
|
||||||
self.term.add_line(win, '{score}'.format(**data), attr=attr)
|
self.term.add_line(win, '{score} pts'.format(**data), attr=attr)
|
||||||
|
|
||||||
attr = self.term.attr('Created')
|
attr = self.term.attr('Created')
|
||||||
self.term.add_space(win)
|
self.term.add_space(win)
|
||||||
@@ -385,7 +385,7 @@ class SubmissionPage(Page):
|
|||||||
|
|
||||||
row = len(data['split_title']) + len(split_text) + 3
|
row = len(data['split_title']) + len(split_text) + 3
|
||||||
attr = self.term.attr('Score')
|
attr = self.term.attr('Score')
|
||||||
self.term.add_line(win, '{score}'.format(**data), row, 1, attr=attr)
|
self.term.add_line(win, '{score} pts'.format(**data), row, 1, attr=attr)
|
||||||
|
|
||||||
arrow, attr = self.term.get_arrow(data['likes'])
|
arrow, attr = self.term.get_arrow(data['likes'])
|
||||||
self.term.add_space(win)
|
self.term.add_space(win)
|
||||||
@@ -393,7 +393,7 @@ class SubmissionPage(Page):
|
|||||||
|
|
||||||
attr = self.term.attr('CommentCount')
|
attr = self.term.attr('CommentCount')
|
||||||
self.term.add_space(win)
|
self.term.add_space(win)
|
||||||
self.term.add_line(win, '{comments}'.format(**data), attr=attr)
|
self.term.add_line(win, '{comments} comments'.format(**data), attr=attr)
|
||||||
|
|
||||||
if data['gold']:
|
if data['gold']:
|
||||||
attr = self.term.attr('Gold')
|
attr = self.term.attr('Gold')
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ class SubredditPage(Page):
|
|||||||
lambda data: self._submission_attr(data), first))
|
lambda data: self._submission_attr(data), first))
|
||||||
elif item == "%s":
|
elif item == "%s":
|
||||||
# Need to cut off the characters that aren't the score number
|
# Need to cut off the characters that aren't the score number
|
||||||
form.append((lambda data: data['score'][:-4],
|
form.append((lambda data: str(data['score']),
|
||||||
lambda data: self.term.attr('Score'), first))
|
lambda data: self.term.attr('Score'), first))
|
||||||
elif item == "%v":
|
elif item == "%v":
|
||||||
# This isn't great, self.term.get_arrow gets called twice
|
# This isn't great, self.term.get_arrow gets called twice
|
||||||
@@ -324,7 +324,7 @@ class SubredditPage(Page):
|
|||||||
lambda data: self.term.get_arrow(data['likes'])[1], first))
|
lambda data: self.term.get_arrow(data['likes'])[1], first))
|
||||||
elif item == "%c":
|
elif item == "%c":
|
||||||
form.append((
|
form.append((
|
||||||
lambda data: '{0}'.format(data['comments'][:-9])
|
lambda data: data['comments']
|
||||||
if data['comments'] else None, # Don't try to subscript null items
|
if data['comments'] else None, # Don't try to subscript null items
|
||||||
lambda data: self.term.attr('CommentCount'),
|
lambda data: self.term.attr('CommentCount'),
|
||||||
first))
|
first))
|
||||||
@@ -483,7 +483,7 @@ class SubredditPage(Page):
|
|||||||
|
|
||||||
if row in valid_rows:
|
if row in valid_rows:
|
||||||
attr = self.term.attr('Score')
|
attr = self.term.attr('Score')
|
||||||
self.term.add_line(win, '{score}'.format(**data), row, 1, attr)
|
self.term.add_line(win, '{score} pts'.format(**data), row, 1, attr)
|
||||||
self.term.add_space(win)
|
self.term.add_space(win)
|
||||||
|
|
||||||
arrow, attr = self.term.get_arrow(data['likes'])
|
arrow, attr = self.term.get_arrow(data['likes'])
|
||||||
@@ -500,7 +500,7 @@ class SubredditPage(Page):
|
|||||||
|
|
||||||
attr = self.term.attr('CommentCount')
|
attr = self.term.attr('CommentCount')
|
||||||
self.term.add_space(win)
|
self.term.add_space(win)
|
||||||
self.term.add_line(win, '{comments}'.format(**data), attr=attr)
|
self.term.add_line(win, '{comments} comments'.format(**data), attr=attr)
|
||||||
|
|
||||||
if data['saved']:
|
if data['saved']:
|
||||||
attr = self.term.attr('Saved')
|
attr = self.term.attr('Saved')
|
||||||
|
|||||||
Reference in New Issue
Block a user