1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# -*- coding: utf-8 -*-
"""
colorful
~~~~~~~~
Terminal string styling done right, in Python.
:copyright: (c) 2017 by Timo Furrer <tuxtimo@gmail.com>
:license: MIT, see LICENSE for more details.
"""
import os
import sys
import pytest
# do not overwrite module
os.environ['COLORFUL_NO_MODULE_OVERWRITE'] = '1'
import colorful.terminal as terminal # noqa
@pytest.mark.skipif(not sys.stdout.isatty(), reason='fails without a tty')
@pytest.mark.parametrize('env,expected', [
# test force color settings
({'COLORFUL_DISABLE': '1'}, terminal.NO_COLORS),
({'COLORFUL_FORCE_8_COLORS': '1'}, terminal.ANSI_8_COLORS),
({'COLORFUL_FORCE_16_COLORS': '1'}, terminal.ANSI_16_COLORS),
({'COLORFUL_FORCE_256_COLORS': '1'}, terminal.ANSI_256_COLORS),
({'COLORFUL_FORCE_TRUE_COLORS': '1'}, terminal.TRUE_COLORS),
# test recommended $COLORTERM variable
({'COLORTERM': 'truecolor'}, terminal.TRUE_COLORS),
({'COLORTERM': '24bit'}, terminal.TRUE_COLORS),
({'COLORTERM': '8bit'}, terminal.ANSI_256_COLORS),
({'COLORTERM': 'XYZ'}, terminal.ANSI_16_COLORS),
# test $TERM_PROGRAM variable
({'TERM_PROGRAM': 'iTerm.app'}, terminal.TRUE_COLORS),
({'TERM_PROGRAM': 'Hyper'}, terminal.TRUE_COLORS),
({'TERM_PROGRAM': 'Apple_Terminal'}, terminal.ANSI_256_COLORS),
# test $TERM variable values for 256 ANSI colors
({'TERM': 'screen-256'}, terminal.ANSI_256_COLORS),
({'TERM': 'screen-256color'}, terminal.ANSI_256_COLORS),
({'TERM': 'xterm-256'}, terminal.ANSI_256_COLORS),
({'TERM': 'xterm-256color'}, terminal.ANSI_256_COLORS),
# test $TERM variable values for 16 colors
({'TERM': 'screen'}, terminal.ANSI_16_COLORS),
({'TERM': 'xterm'}, terminal.ANSI_16_COLORS),
({'TERM': 'vt100'}, terminal.ANSI_16_COLORS),
({'TERM': 'color'}, terminal.ANSI_16_COLORS),
({'TERM': 'ansi'}, terminal.ANSI_16_COLORS),
({'TERM': 'cygwin'}, terminal.ANSI_16_COLORS),
({'TERM': 'linux'}, terminal.ANSI_16_COLORS),
# test fallback to 8 colors
({}, terminal.ANSI_8_COLORS),
# force disable overrules force colors
({
'COLORFUL_DISABLE': '1',
'COLORFUL_FORCE_8_COLORS': '1', 'COLORFUL_FORCE_16_COLORS': '1',
'COLORFUL_FORCE_256_COLORS': '1', 'COLORFUL_FORCE_TRUE_COLORS': '1'
}, terminal.NO_COLORS),
# force colors overrules $COLORTERM
({
'COLORFUL_FORCE_TRUE_COLORS': '1',
'COLORTERM': '24bit'
}, terminal.TRUE_COLORS),
# $COLORTERM overrules $TERM_PROGRAM
({
'COLORTERM': 'truecolor',
'TERM_PROGRAM': 'iTerm.app'
}, terminal.TRUE_COLORS),
# $TERM_PROGRAM overrules $TERM with 256 colors
({
'TERM_PROGRAM': 'iTerm.app',
'TERM': 'xterm-256color'
}, terminal.TRUE_COLORS)
])
def test_color_support_detection(env, expected):
"""
Test the terminal color support auto detection
"""
assert terminal.detect_color_support(env) == expected
|