File: conftest.py

package info (click to toggle)
python-blessed 1.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,296 kB
  • sloc: python: 7,215; makefile: 13; sh: 7
file content (84 lines) | stat: -rw-r--r-- 2,086 bytes parent folder | download | duplicates (2)
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
83
84
"""Configure test fixtures"""

# std imports
import os
import platform
import subprocess

# 3rd party
import pytest

IS_WINDOWS = platform.system() == 'Windows'

all_terms_params = 'xterm screen ansi vt220 rxvt cons25 linux'.split()
many_lines_params = [40, 80]
# we must test a '1' column for conditional in _handle_long_word
many_columns_params = [1, 10]


def envvar_enabled(envvar):
    """
    Return True if environment variable is set and enabled

    unset values, 'no', 0, and 'false' and treated as False regardless of case
    All other values are considered True
    """

    value = os.environ.get(envvar, False)

    if value is False:
        return value

    if value.lower() in ('no', 'false'):
        return False

    try:
        return bool(int(value))
    except ValueError:
        return True


TEST_FULL = envvar_enabled('TEST_FULL')
TEST_KEYBOARD = envvar_enabled('TEST_KEYBOARD')
TEST_QUICK = envvar_enabled('TEST_QUICK')
TEST_RAW = envvar_enabled('TEST_RAW')


if TEST_FULL:
    try:
        all_terms_params = [
            # use all values of the first column of data in output of 'toe -a'
            _term.split(None, 1)[0] for _term in
            subprocess.Popen(('toe', '-a'),  # pylint: disable=consider-using-with
                             stdout=subprocess.PIPE,
                             close_fds=True)
            .communicate()[0].splitlines()]
    except OSError:
        pass
elif IS_WINDOWS:
    all_terms_params = ['vtwin10', ]
elif TEST_QUICK:
    all_terms_params = 'xterm screen ansi linux'.split()


if TEST_QUICK:
    many_lines_params = [80, ]
    many_columns_params = [25, ]


@pytest.fixture(params=all_terms_params)
def all_terms(request):
    """Common kind values for all kinds of terminals."""
    return request.param


@pytest.fixture(params=many_lines_params)
def many_lines(request):
    """Various number of lines for screen height."""
    return request.param


@pytest.fixture(params=many_columns_params)
def many_columns(request):
    """Various number of columns for screen width."""
    return request.param