diff options
| author | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 | 
|---|---|---|
| committer | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 | 
| commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
| tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/python/prompt-toolkit/py2/tests/test_print_tokens.py | |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/python/prompt-toolkit/py2/tests/test_print_tokens.py')
| -rw-r--r-- | contrib/python/prompt-toolkit/py2/tests/test_print_tokens.py | 50 | 
1 files changed, 50 insertions, 0 deletions
| diff --git a/contrib/python/prompt-toolkit/py2/tests/test_print_tokens.py b/contrib/python/prompt-toolkit/py2/tests/test_print_tokens.py new file mode 100644 index 00000000000..c3b5826b36c --- /dev/null +++ b/contrib/python/prompt-toolkit/py2/tests/test_print_tokens.py @@ -0,0 +1,50 @@ +""" +Test `shortcuts.print_tokens`. +""" +from __future__ import unicode_literals +from prompt_toolkit.shortcuts import print_tokens +from prompt_toolkit.token import Token +from prompt_toolkit.styles import style_from_dict + + +class _Capture: +    " Emulate an stdout object. " +    encoding = 'utf-8' + +    def __init__(self): +        self._data = [] + +    def write(self, data): +        self._data.append(data) + +    @property +    def data(self): +        return b''.join(self._data) + +    def flush(self): +        pass + +    def isatty(self): +        return True + + +def test_print_tokens(): +    f = _Capture() +    print_tokens([(Token, 'hello'), (Token, 'world')], file=f) +    assert b'hello' in f.data +    assert b'world' in f.data + + +def test_with_style(): +    f = _Capture() +    style = style_from_dict({ +        Token.Hello: '#ff0066', +        Token.World: '#44ff44 italic', +    }) +    tokens = [ +        (Token.Hello, 'Hello '), +        (Token.World, 'world'), +    ] +    print_tokens(tokens, style=style, file=f) +    assert b'\x1b[0;38;5;197mHello' in f.data +    assert b'\x1b[0;38;5;83;3mworld' in f.data | 
