File: test_terminal.py

package info (click to toggle)
python-cleo 2.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: python: 8,293; makefile: 22; sh: 2
file content (57 lines) | stat: -rw-r--r-- 1,358 bytes parent folder | download
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
from __future__ import annotations

import os

from typing import TYPE_CHECKING

import pytest

from cleo.terminal import Terminal


if TYPE_CHECKING:
    from pytest_mock import MockerFixture


def test_size() -> None:
    terminal = Terminal()
    w, h = terminal.size
    assert terminal.width == w

    terminal = Terminal(width=99, height=101)
    w, h = terminal.size
    assert w == 99 and h == 101


@pytest.mark.parametrize(
    "columns_env_value, init_value, expected",
    (
        ("314", None, 314),
        ("200", 40, 40),
        ("random", 40, 40),
        ("random", None, 80),
    ),
)
def test_columns_env(
    mocker: MockerFixture, columns_env_value: str, init_value: int | None, expected: int
) -> None:
    mocker.patch.dict(os.environ, {"COLUMNS": columns_env_value}, clear=False)
    console = Terminal(width=init_value)
    assert console.width == expected


@pytest.mark.parametrize(
    "lines_env_value, init_value, expected",
    (
        ("314", None, 314),
        ("200", 40, 40),
        ("random", 40, 40),
        ("random", None, 25),
    ),
)
def test_lines_env(
    mocker: MockerFixture, lines_env_value: str, init_value: int | None, expected: int
) -> None:
    mocker.patch.dict(os.environ, {"LINES": lines_env_value}, clear=False)
    console = Terminal(height=init_value)
    assert console.height == expected