Merge branch 'master' into themes
# Conflicts: # rtv/__main__.py # rtv/page.py # rtv/submission_page.py # rtv/subreddit_page.py # rtv/subscription_page.py # rtv/terminal.py # rtv/theme.py
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
assert not any(args[0][3] == curses.A_REVERSE
|
||||
for args in window.subwin.addch.call_args_list)
|
||||
|
||||
# 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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,6 +9,7 @@ import codecs
|
||||
import six
|
||||
import pytest
|
||||
|
||||
from rtv.theme import Theme
|
||||
from rtv.docs import HELP, COMMENT_EDIT_FILE
|
||||
from rtv.exceptions import TemporaryFileError, BrowserError
|
||||
|
||||
@@ -20,14 +21,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, \
|
||||
@@ -60,6 +57,8 @@ def test_terminal_properties(terminal, config):
|
||||
assert terminal.MIN_HEIGHT is not None
|
||||
assert terminal.MIN_WIDTH is not None
|
||||
|
||||
assert terminal.theme is not None
|
||||
|
||||
|
||||
def test_terminal_functions(terminal):
|
||||
|
||||
@@ -558,3 +557,42 @@ def test_strip_textpad(terminal):
|
||||
text = 'alpha bravo\ncharlie \ndelta \n echo \n\nfoxtrot\n\n\n'
|
||||
assert terminal.strip_textpad(text) == (
|
||||
'alpha bravocharlie delta\n echo\n\nfoxtrot')
|
||||
|
||||
|
||||
def test_add_space(terminal, stdscr):
|
||||
|
||||
stdscr.x, stdscr.y = 10, 20
|
||||
terminal.add_space(stdscr)
|
||||
stdscr.addstr.assert_called_with(20, 10, ' ')
|
||||
|
||||
# Not enough room to add a space
|
||||
stdscr.reset_mock()
|
||||
stdscr.x = 10
|
||||
stdscr.ncols = 11
|
||||
terminal.add_space(stdscr)
|
||||
assert not stdscr.addstr.called
|
||||
|
||||
|
||||
def test_attr(terminal):
|
||||
|
||||
assert terminal.attr('cursor') == 0
|
||||
assert terminal.attr('cursor.selected') == curses.A_REVERSE
|
||||
assert terminal.attr('neutral_vote') == curses.A_BOLD
|
||||
|
||||
with terminal.theme.set_modifier('selected'):
|
||||
assert terminal.attr('cursor') == curses.A_REVERSE
|
||||
assert terminal.attr('neutral_vote') == curses.A_BOLD
|
||||
|
||||
|
||||
def test_set_theme(terminal, stdscr):
|
||||
|
||||
stdscr.reset_mock()
|
||||
terminal.set_theme()
|
||||
assert not terminal.theme.monochrome
|
||||
stdscr.bkgd.assert_called_once_with(' ', 0)
|
||||
|
||||
stdscr.reset_mock()
|
||||
theme = Theme(monochrome=True)
|
||||
terminal.set_theme(theme=theme)
|
||||
assert terminal.theme.monochrome
|
||||
stdscr.bkgd.assert_called_once_with(' ', 0)
|
||||
|
||||
Reference in New Issue
Block a user