File: test_output.py

package info (click to toggle)
meson-python 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,264 kB
  • sloc: python: 3,005; ansic: 326; makefile: 8
file content (32 lines) | stat: -rw-r--r-- 1,021 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
# SPDX-FileCopyrightText: 2021 The meson-python developers
#
# SPDX-License-Identifier: MIT

import pytest

import mesonpy


@pytest.mark.parametrize(('tty', 'env', 'colors'), [
    (False, {}, False),
    (True, {}, True),
    (False, {'NO_COLOR': ''}, False),
    (True, {'NO_COLOR': ''}, False),
    (False, {'FORCE_COLOR': ''}, True),
    (True, {'FORCE_COLOR': ''}, True),
    (True, {'FORCE_COLOR': '', 'NO_COLOR': ''}, False),
    (True, {'TERM': ''}, True),
    (True, {'TERM': 'dumb'}, False),
])
def test_use_ansi_escapes(mocker, monkeypatch, tty, env, colors):
    mocker.patch('sys.stdout.isatty', return_value=tty)
    mocker.patch('mesonpy._util.setup_windows_console', return_value=True)
    monkeypatch.delenv('NO_COLOR', raising=False)
    monkeypatch.delenv('FORCE_COLOR', raising=False)
    for key, value in env.items():
        monkeypatch.setenv(key, value)

    # Clear caching by functools.lru_cache().
    mesonpy._use_ansi_escapes.cache_clear()

    assert mesonpy._use_ansi_escapes() == colors