Cherry picking backwards-compatible changes from the themes branch

This commit is contained in:
Michael Lazar
2017-09-08 01:10:32 -04:00
parent 0268408f71
commit 982861560a
16 changed files with 414 additions and 248 deletions

View File

@@ -52,6 +52,9 @@ class MockStdscr(mock.MagicMock):
def getyx(self):
return self.y, self.x
def getbegyx(self):
return 0, 0
def getmaxyx(self):
return self.nlines, self.ncols
@@ -154,12 +157,14 @@ def stdscr():
patch('curses.curs_set'), \
patch('curses.init_pair'), \
patch('curses.color_pair'), \
patch('curses.has_colors'), \
patch('curses.start_color'), \
patch('curses.use_default_colors'):
out = MockStdscr(nlines=40, ncols=80, x=0, y=0)
curses.initscr.return_value = out
curses.newwin.side_effect = lambda *args: out.derwin(*args)
curses.color_pair.return_value = 23
curses.has_colors.return_value = True
curses.ACS_VLINE = 0
yield out

View File

@@ -12,7 +12,7 @@ import requests
from six.moves import reload_module
from rtv import exceptions
from rtv.objects import Color, Controller, Navigator, Command, KeyMap, \
from rtv.objects import Controller, Navigator, Command, KeyMap, \
curses_session, patch_webbrowser
try:
@@ -189,21 +189,6 @@ def test_objects_load_screen_nested_complex(terminal, stdscr, use_ascii):
stdscr.subwin.addstr.assert_called_once_with(1, 1, error_message)
def test_objects_color(stdscr):
colors = ['RED', 'GREEN', 'YELLOW', 'BLUE', 'MAGENTA', 'CYAN', 'WHITE']
# Check that all colors start with the default value
for color in colors:
assert getattr(Color, color) == curses.A_NORMAL
Color.init()
# Check that all colors are populated
for color in colors:
assert getattr(Color, color) == 23
def test_objects_curses_session(stdscr):
# Normal setup and cleanup

View File

@@ -79,15 +79,16 @@ def test_submission_page_construct(reddit, terminal, config, oauth):
# Comment
comment_data = page.content.get(0)
text = comment_data['split_body'][0].encode('utf-8')
window.subwin.addstr.assert_any_call(1, 1, text)
window.subwin.addstr.assert_any_call(1, 1, text, curses.A_NORMAL)
# More Comments
comment_data = page.content.get(1)
text = comment_data['body'].encode('utf-8')
window.subwin.addstr.assert_any_call(0, 1, text)
window.subwin.addstr.assert_any_call(0, 1, text, curses.A_NORMAL)
# Cursor should not be drawn when the page is first opened
assert not window.subwin.chgat.called
# TODO: Add a new test for this
# assert not window.subwin.chgat.called
# Reload with a smaller terminal window
terminal.stdscr.ncols = 20
@@ -264,7 +265,7 @@ def test_submission_comment_not_enough_space(submission_page, terminal):
text = '(Not enough space to display)'.encode('ascii')
window = terminal.stdscr.subwin
window.subwin.addstr.assert_any_call(6, 1, text)
window.subwin.addstr.assert_any_call(6, 1, text, curses.A_NORMAL)
def test_submission_vote(submission_page, refresh_token):

View File

@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import curses
import six
from rtv import __version__
@@ -38,7 +40,7 @@ def test_subreddit_page_construct(reddit, terminal, config, oauth):
window.subwin.addstr.assert_any_call(0, 1, text, 2097152)
# Cursor should have been drawn
assert window.subwin.chgat.called
window.subwin.addch.assert_any_call(0, 0, ' ', curses.A_REVERSE)
# Reload with a smaller terminal window
terminal.stdscr.ncols = 20

View File

@@ -45,8 +45,8 @@ def test_subscription_page_construct(reddit, terminal, config, oauth,
window.addstr.assert_any_call(0, 0, menu)
# Cursor - 2 lines
window.subwin.chgat.assert_any_call(0, 0, 1, 262144)
window.subwin.chgat.assert_any_call(1, 0, 1, 262144)
window.subwin.addch.assert_any_call(0, 0, ' ', 262144)
window.subwin.addch.assert_any_call(1, 0, ' ', 262144)
# Reload with a smaller terminal window
terminal.stdscr.ncols = 20

View File

@@ -20,14 +20,10 @@ except ImportError:
def test_terminal_properties(terminal, config):
assert len(terminal.up_arrow) == 2
assert isinstance(terminal.up_arrow[0], six.text_type)
assert len(terminal.down_arrow) == 2
assert isinstance(terminal.down_arrow[0], six.text_type)
assert len(terminal.neutral_arrow) == 2
assert isinstance(terminal.neutral_arrow[0], six.text_type)
assert len(terminal.guilded) == 2
assert isinstance(terminal.guilded[0], six.text_type)
assert isinstance(terminal.up_arrow, six.text_type)
assert isinstance(terminal.down_arrow, six.text_type)
assert isinstance(terminal.neutral_arrow, six.text_type)
assert isinstance(terminal.guilded, six.text_type)
terminal._display = None
with mock.patch('rtv.terminal.sys') as sys, \