File: test_terminalwriter_linewidth.py

package info (click to toggle)
python-py 1.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,512 kB
  • sloc: python: 11,660; makefile: 119; sh: 7
file content (62 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (4)
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
# coding: utf-8
from __future__ import unicode_literals

import pytest

from py._io.terminalwriter import TerminalWriter


def test_terminal_writer_line_width_init():
    tw = TerminalWriter()
    assert tw.chars_on_current_line == 0
    assert tw.width_of_current_line == 0


def test_terminal_writer_line_width_update():
    tw = TerminalWriter()
    tw.write('hello world')
    assert tw.chars_on_current_line == 11
    assert tw.width_of_current_line == 11


def test_terminal_writer_line_width_update_with_newline():
    tw = TerminalWriter()
    tw.write('hello\nworld')
    assert tw.chars_on_current_line == 5
    assert tw.width_of_current_line == 5


def test_terminal_writer_line_width_update_with_wide_text():
    tw = TerminalWriter()
    tw.write('乇乂ㄒ尺卂 ㄒ卄丨匚匚')
    assert tw.chars_on_current_line == 11
    assert tw.width_of_current_line == 21  # 5*2 + 1 + 5*2


@pytest.mark.skipif(
    'sys.version_info > (3,)',
    reason='Bytes are not accepted'
           ' https://github.com/pytest-dev/pytest/issues/4861')
def test_terminal_writer_line_width_update_with_wide_bytes():
    tw = TerminalWriter()
    tw.write('乇乂ㄒ尺卂 ㄒ卄丨匚匚'.encode('utf-8'))
    assert tw.chars_on_current_line == 11
    assert tw.width_of_current_line == 21


def test_terminal_writer_line_width_composed():
    tw = TerminalWriter()
    text = 'café food'
    assert len(text) == 9
    tw.write(text)
    assert tw.chars_on_current_line == 9
    assert tw.width_of_current_line == 9


def test_terminal_writer_line_width_combining():
    tw = TerminalWriter()
    text = 'café food'
    assert len(text) == 10
    tw.write(text)
    assert tw.chars_on_current_line == 10
    assert tw.width_of_current_line == 9