Repair and test logic to avoid printing None strings
This commit is contained in:
@@ -870,6 +870,12 @@ def test_subreddit_page__draw_item_format(terminal, subreddit_page):
|
|||||||
assert not terminal.add_line.called
|
assert not terminal.add_line.called
|
||||||
terminal.add_line.reset_mock()
|
terminal.add_line.reset_mock()
|
||||||
|
|
||||||
|
# add_line shouldn't be called if the string field is none
|
||||||
|
subreddit_page.format = [(None, lambda data: None, False)]
|
||||||
|
subreddit_page._draw_item_format(win, None, None, 0)
|
||||||
|
|
||||||
|
assert not terminal.add_line.called
|
||||||
|
|
||||||
# Check for newline handling and attribute reusing in the call of a null
|
# Check for newline handling and attribute reusing in the call of a null
|
||||||
# attribute
|
# attribute
|
||||||
subreddit_page.format = [("string", lambda data: terminal.attr("Link"), True),
|
subreddit_page.format = [("string", lambda data: terminal.attr("Link"), True),
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ class SubredditPage(Page):
|
|||||||
for get_data, get_attr, first in self.format:
|
for get_data, get_attr, first in self.format:
|
||||||
# add_line wants strings, make sure we give it strings
|
# add_line wants strings, make sure we give it strings
|
||||||
if callable(get_data):
|
if callable(get_data):
|
||||||
string = str(get_data(data))
|
string = get_data(data)
|
||||||
else:
|
else:
|
||||||
# Start writing to the next line if we hit a newline
|
# Start writing to the next line if we hit a newline
|
||||||
if get_data == "\n":
|
if get_data == "\n":
|
||||||
@@ -399,17 +399,20 @@ class SubredditPage(Page):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Otherwise, proceed on the same line
|
# Otherwise, proceed on the same line
|
||||||
string = str(get_data)
|
string = get_data
|
||||||
|
|
||||||
|
# Don't try to write None strings to the screen. This happens in
|
||||||
|
# places like user pages, where data['comments'] is None
|
||||||
|
if not string and first is False:
|
||||||
|
continue
|
||||||
|
|
||||||
|
string = str(string)
|
||||||
|
|
||||||
# We only want to print a maximum of one line of data
|
# We only want to print a maximum of one line of data
|
||||||
# TODO - support line wrapping
|
# TODO - support line wrapping
|
||||||
string = string.split('\n')[0]
|
string = string.split('\n')[0]
|
||||||
|
|
||||||
# Don't try to write null strings to the screen. This happens in
|
if string is ' ':
|
||||||
# places like user pages, where data['comments'] is None
|
|
||||||
if string is None:
|
|
||||||
continue
|
|
||||||
elif string is ' ':
|
|
||||||
# Make sure spaces aren't treated like normal strings and print
|
# Make sure spaces aren't treated like normal strings and print
|
||||||
# them to the window this way. This ensures they won't be drawn
|
# them to the window this way. This ensures they won't be drawn
|
||||||
# with an attribute.
|
# with an attribute.
|
||||||
|
|||||||
Reference in New Issue
Block a user