mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Add color utility.
This commit is contained in:
parent
e98d2e1e79
commit
6a1f945e31
2 changed files with 67 additions and 0 deletions
35
tests/color_test.py
Normal file
35
tests/color_test.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
import mock
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
from pre_commit.color import format_color
|
||||
from pre_commit.color import GREEN
|
||||
from pre_commit.color import use_color
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('in_text', 'in_color', 'in_use_color', 'expected'), (
|
||||
('foo', GREEN, True, '{0}foo\033[0m'.format(GREEN)),
|
||||
('foo', GREEN, False, 'foo'),
|
||||
))
|
||||
def test_format_color(in_text, in_color, in_use_color, expected):
|
||||
ret = format_color(in_text, in_color, in_use_color)
|
||||
assert ret == expected
|
||||
|
||||
|
||||
def test_use_color_never():
|
||||
assert use_color('never') is False
|
||||
|
||||
|
||||
def test_use_color_always():
|
||||
assert use_color('always') is True
|
||||
|
||||
|
||||
def test_use_color_no_tty():
|
||||
with mock.patch.object(sys.stdout, 'isatty', return_value=False):
|
||||
assert use_color('auto') is False
|
||||
|
||||
|
||||
def test_use_color_tty():
|
||||
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
||||
assert use_color('auto') is True
|
||||
Loading…
Add table
Add a link
Reference in a new issue