diff options
| author | nkozlovskiy <[email protected]> | 2023-09-29 12:24:06 +0300 |
|---|---|---|
| committer | nkozlovskiy <[email protected]> | 2023-09-29 12:41:34 +0300 |
| commit | e0e3e1717e3d33762ce61950504f9637a6e669ed (patch) | |
| tree | bca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/prompt-toolkit/py2/tests/test_print_tokens.py | |
| parent | 38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff) | |
add ydb deps
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 |
