def test_theme_from_file_invalid(line): with _ephemeral_directory() as dirname: with NamedTemporaryFile(mode='w+', dir=dirname) as fp: fp.write('[theme]\n') fp.write(line) fp.flush() with pytest.raises(ConfigError): Theme.from_file(fp.name, 'installed')
def test_theme_from_file(): with _ephemeral_directory() as dirname: with NamedTemporaryFile(mode='w+', dir=dirname) as fp: with pytest.raises(ConfigError): Theme.from_file(fp.name, 'installed') fp.write('[theme]\n') fp.write('Unknown = - -\n') fp.write('Upvote = - red\n') fp.write('Downvote = ansi_255 default bold\n') fp.write('NeutralVote = #000000 #ffffff bold+reverse\n') fp.flush() theme = Theme.from_file(fp.name, 'installed') assert theme.source == 'installed' assert 'Unknown' not in theme.elements assert theme.elements['Upvote'] == (-1, curses.COLOR_RED, curses.A_NORMAL) assert theme.elements['Downvote'] == (255, -1, curses.A_BOLD) assert theme.elements['NeutralVote'] == (16, 231, curses.A_BOLD | curses.A_REVERSE)
def test_theme_default_cfg_matches_builtin(): filename = os.path.join(Config.DEFAULT_THEMES, 'default.cfg.example') default_theme = Theme.from_file(filename, 'built-in') # The default theme file should match the hardcoded values assert default_theme.elements == Theme().elements # Make sure that the elements passed into the constructor exactly match # up with the hardcoded elements class MockTheme(Theme): def __init__(self, name=None, source=None, elements=None): assert name == 'default.cfg' assert source == 'preset' assert elements == Theme.DEFAULT_ELEMENTS MockTheme.from_file(filename, 'preset')