Fixing tests
This commit is contained in:
@@ -99,7 +99,7 @@ class Page(object):
|
||||
def previous_theme(self):
|
||||
|
||||
theme = self.term.theme_list.previous(self.term.theme)
|
||||
while not self.term.test_theme(theme):
|
||||
while not self.term.check_theme(theme):
|
||||
theme = self.term.theme_list.previous(theme)
|
||||
|
||||
self.term.set_theme(theme)
|
||||
@@ -111,7 +111,7 @@ class Page(object):
|
||||
def next_theme(self):
|
||||
|
||||
theme = self.term.theme_list.next(self.term.theme)
|
||||
while not self.term.test_theme(theme):
|
||||
while not self.term.check_theme(theme):
|
||||
theme = self.term.theme_list.next(theme)
|
||||
|
||||
self.term.set_theme(theme)
|
||||
|
||||
@@ -398,7 +398,7 @@ class Terminal(object):
|
||||
_logger.warning(stderr)
|
||||
self.show_notification(
|
||||
'Program exited with status={0}\n{1}'.format(
|
||||
code, stderr.strip()), style='error')
|
||||
code, stderr.strip()), style='Error')
|
||||
|
||||
else:
|
||||
# Non-blocking, open a background process
|
||||
@@ -827,13 +827,15 @@ class Terminal(object):
|
||||
"""
|
||||
Shortcut for fetching the color + attribute code for an element.
|
||||
"""
|
||||
# The theme must be initialized before calling this
|
||||
assert self.theme is not None
|
||||
|
||||
return self.theme.get(element)
|
||||
|
||||
@staticmethod
|
||||
def test_theme(theme):
|
||||
def check_theme(theme):
|
||||
"""
|
||||
Check if the given theme is supported by the terminal
|
||||
Check if the given theme is compatible with the terminal
|
||||
"""
|
||||
terminal_colors = curses.COLORS if curses.has_colors() else 0
|
||||
|
||||
|
||||
@@ -167,6 +167,8 @@ def stdscr():
|
||||
curses.color_pair.return_value = 23
|
||||
curses.has_colors.return_value = True
|
||||
curses.ACS_VLINE = 0
|
||||
curses.COLORS = 256
|
||||
curses.COLOR_PAIRS = 256
|
||||
yield out
|
||||
|
||||
|
||||
@@ -199,6 +201,7 @@ def reddit(vcr, request):
|
||||
@pytest.fixture()
|
||||
def terminal(stdscr, config):
|
||||
term = Terminal(stdscr, config=config)
|
||||
term.set_theme()
|
||||
# Disable the python 3.4 addch patch so that the mock stdscr calls are
|
||||
# always made the same way
|
||||
term.addch = lambda window, *args: window.addch(*args)
|
||||
|
||||
@@ -575,24 +575,78 @@ def test_add_space(terminal, stdscr):
|
||||
|
||||
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
|
||||
assert terminal.attr('CursorBlock') == 0
|
||||
assert terminal.attr('@CursorBlock') == curses.A_REVERSE
|
||||
assert terminal.attr('NeutralVote') == curses.A_BOLD
|
||||
|
||||
with terminal.theme.set_modifier('selected'):
|
||||
assert terminal.attr('cursor') == curses.A_REVERSE
|
||||
assert terminal.attr('neutral_vote') == curses.A_BOLD
|
||||
with terminal.theme.turn_on_selected():
|
||||
assert terminal.attr('CursorBlock') == curses.A_REVERSE
|
||||
assert terminal.attr('NeutralVote') == curses.A_BOLD
|
||||
|
||||
|
||||
def test_check_theme(terminal):
|
||||
|
||||
monochrome = Theme(use_color=False)
|
||||
default = Theme()
|
||||
color256 = Theme.from_name('molokai')
|
||||
|
||||
curses.has_colors.return_value = False
|
||||
assert terminal.check_theme(monochrome)
|
||||
assert not terminal.check_theme(default)
|
||||
assert not terminal.check_theme(color256)
|
||||
|
||||
curses.has_colors.return_value = True
|
||||
curses.COLORS = 0
|
||||
assert terminal.check_theme(monochrome)
|
||||
assert not terminal.check_theme(default)
|
||||
assert not terminal.check_theme(color256)
|
||||
|
||||
curses.COLORS = 8
|
||||
assert terminal.check_theme(monochrome)
|
||||
assert terminal.check_theme(default)
|
||||
assert not terminal.check_theme(color256)
|
||||
|
||||
curses.COLORS = 256
|
||||
assert terminal.check_theme(monochrome)
|
||||
assert terminal.check_theme(default)
|
||||
assert terminal.check_theme(color256)
|
||||
|
||||
curses.COLOR_PAIRS = 8
|
||||
assert terminal.check_theme(monochrome)
|
||||
assert terminal.check_theme(default)
|
||||
assert not terminal.check_theme(color256)
|
||||
|
||||
|
||||
def test_set_theme(terminal, stdscr):
|
||||
|
||||
# Default with color enabled
|
||||
stdscr.reset_mock()
|
||||
terminal.set_theme()
|
||||
assert not terminal.theme.monochrome
|
||||
assert terminal.theme.use_color
|
||||
assert terminal.theme.display_string == 'default (built-in)'
|
||||
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)
|
||||
# When the user passes in the --monochrome flag
|
||||
terminal.theme = None
|
||||
terminal.set_theme(Theme(use_color=False))
|
||||
assert not terminal.theme.use_color
|
||||
assert terminal.theme.display_string == 'monochrome (built-in)'
|
||||
|
||||
# When the terminal doesn't support colors
|
||||
curses.COLORS = 0
|
||||
terminal.theme = None
|
||||
terminal.set_theme()
|
||||
assert terminal.theme.display_string == 'monochrome (built-in)'
|
||||
|
||||
# When the terminal doesn't support 256 colors so it falls back to the
|
||||
# built-in default theme
|
||||
curses.COLORS = 8
|
||||
terminal.theme = None
|
||||
terminal.set_theme(Theme.from_name('molokai'))
|
||||
assert terminal.theme.display_string == 'default (built-in)'
|
||||
|
||||
# When the terminal does support the 256 color theme
|
||||
curses.COLORS = 256
|
||||
terminal.theme = None
|
||||
terminal.set_theme(Theme.from_name('molokai'))
|
||||
assert terminal.theme.display_string == 'molokai (preset)'
|
||||
|
||||
Reference in New Issue
Block a user