FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pre-commit/tests/color_test.py at v5 · pre-commit/pre-commit · GitHub
pre-commit
pre-commit
Repository navigation
Code
Issues
17
(17)
Pull requests
8
(8)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
pre-commit
/
tests
/
color_test.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (42 loc) · 1.85 KB
Breadcrumbs
pre-commit
/
tests
/
color_test.py
Copy path
File metadata and controls
61 lines (42 loc) · 1.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
__future__
import
annotations
import
sys
from
unittest
import
mock
import
pytest
from
pre_commit
import
envcontext
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
,
f'
{
GREEN
}
foo
\033
[m'
),
(
'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
.
stderr
,
'isatty'
,
return_value
=
False
):
assert
use_color
(
'auto'
)
is
False
def
test_use_color_tty_with_color_support
():
with
mock
.
patch
.
object
(
sys
.
stderr
,
'isatty'
,
return_value
=
True
):
with
mock
.
patch
(
'pre_commit.color.terminal_supports_color'
,
True
):
with
envcontext
.
envcontext
(((
'TERM'
,
envcontext
.
UNSET
),)):
assert
use_color
(
'auto'
)
is
True
def
test_use_color_tty_without_color_support
():
with
mock
.
patch
.
object
(
sys
.
stderr
,
'isatty'
,
return_value
=
True
):
with
mock
.
patch
(
'pre_commit.color.terminal_supports_color'
,
False
):
with
envcontext
.
envcontext
(((
'TERM'
,
envcontext
.
UNSET
),)):
assert
use_color
(
'auto'
)
is
False
def
test_use_color_dumb_term
():
with
mock
.
patch
.
object
(
sys
.
stderr
,
'isatty'
,
return_value
=
True
):
with
mock
.
patch
(
'pre_commit.color.terminal_supports_color'
,
True
):
with
envcontext
.
envcontext
(((
'TERM'
,
'dumb'
),)):
assert
use_color
(
'auto'
)
is
False
def
test_use_color_raises_if_given_shenanigans
():
with
pytest
.
raises
(
ValueError
):
use_color
(
'herpaderp'
)
Back
|
FazBrowse Home
|
New Git URL