Adding tests

This commit is contained in:
Michael Lazar
2017-09-10 21:47:55 -04:00
parent 982861560a
commit 8b63e1c5de
3 changed files with 46 additions and 3 deletions

View File

@@ -282,7 +282,8 @@ class Terminal(object):
row, col = window.getyx()
_, max_cols = window.getmaxyx()
if max_cols - col - 1 <= 0:
n_cols = max_cols - col - 1
if n_cols <= 0:
# Trying to draw outside of the screen bounds
return

View File

@@ -87,8 +87,8 @@ def test_submission_page_construct(reddit, terminal, config, oauth):
window.subwin.addstr.assert_any_call(0, 1, text, curses.A_NORMAL)
# Cursor should not be drawn when the page is first opened
# TODO: Add a new test for this
# 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

View File

@@ -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
@@ -56,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):
@@ -554,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)