コード例 #1
0
ファイル: test_terminal.py プロジェクト: proycon/tuir
def test_terminal_set_theme(terminal, stdscr):

    # Default with color enabled
    stdscr.reset_mock()
    terminal.set_theme()
    assert terminal.theme.use_color
    assert terminal.theme.display_string == 'default (built-in)'
    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)'
コード例 #2
0
def test_theme_from_name():

    with _ephemeral_directory() as dirname:
        with NamedTemporaryFile(mode='w+', suffix='.cfg', dir=dirname) as fp:
            path, filename = os.path.split(fp.name)
            theme_name = filename[:-4]

            fp.write('[theme]\n')
            fp.write('Upvote = default default\n')
            fp.flush()

            # Full file path
            theme = Theme.from_name(fp.name, path=path)
            assert theme.name == theme_name
            assert theme.source == 'custom'
            assert theme.elements['Upvote'] == (-1, -1, curses.A_NORMAL)

            # Relative to the directory
            theme = Theme.from_name(theme_name, path=path)
            assert theme.name == theme_name
            assert theme.source == 'installed'
            assert theme.elements['Upvote'] == (-1, -1, curses.A_NORMAL)

            # Invalid theme name
            with pytest.raises(ConfigError):
                theme.from_name('invalid_theme_name', path=path)
コード例 #3
0
ファイル: test_terminal.py プロジェクト: proycon/tuir
def test_terminal_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)
コード例 #4
0
ファイル: demo_theme.py プロジェクト: proycon/tuir
def main():

    locale.setlocale(locale.LC_ALL, '')

    if len(sys.argv) > 1:
        theme = Theme.from_name(sys.argv[1])
    else:
        theme = Theme()

    vcr = initialize_vcr()
    with vcr.use_cassette('demo_theme.yaml') as cassette, \
            curses_session() as stdscr:

        config = Config()
        if vcr.record_mode == 'once':
            config.load_refresh_token()
        else:
            config.refresh_token = 'mock_refresh_token'

        reddit = praw.Reddit(user_agent='RTV Theme Demo',
                             decode_html_entities=False,
                             disable_update_check=True)
        reddit.config.api_request_delay = 0

        config.history.add('https://api.reddit.com/comments/6llvsl/_/djutc3s')
        config.history.add('http://i.imgur.com/Z9iGKWv.gifv')
        config.history.add(
            'https://www.reddit.com/r/Python/comments/6302cj/rpython_official_job_board/'
        )

        term = Terminal(stdscr, config)
        term.set_theme()
        oauth = OAuthHelper(reddit, term, config)
        oauth.authorize()

        theme_list = ThemeList()

        while True:
            term = Terminal(stdscr, config)
            term.set_theme(theme)
            threads = draw_screen(stdscr, reddit, config, theme, oauth)

            try:
                ch = term.show_notification(theme.display_string)
            except KeyboardInterrupt:
                ch = Terminal.ESCAPE

            for thread, term in threads:
                term.pause_getch = False
                thread.join()

            if vcr.record_mode == 'once':
                break
            else:
                cassette.play_counts = Counter()

            theme_list.reload()

            if ch == curses.KEY_RIGHT:
                theme = theme_list.next(theme)
            elif ch == curses.KEY_LEFT:
                theme = theme_list.previous(theme)
            elif ch == Terminal.ESCAPE:
                break
            else:
                # Force the theme to reload
                theme = theme_list.next(theme)
                theme = theme_list.previous(theme)