File tree 2 files changed +34
-1
lines changed 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 2
2
terminal.
3
3
'''
4
4
5
+ import os
5
6
import sys
6
7
8
+
9
+ def color_enabled ():
10
+ COLOR_ENV = os .getenv ('COLOR' , 'auto' )
11
+ if COLOR_ENV == 'auto' and sys .stdout .isatty ():
12
+ return True
13
+ if COLOR_ENV == 'yes' :
14
+ return True
15
+ return False
16
+
17
+
7
18
try :
8
19
import colorama
9
20
10
- colorama .init (strip = ( not sys . stdout . isatty () ))
21
+ colorama .init (strip = not color_enabled ( ))
11
22
GREEN , YELLOW , RED = (
12
23
colorama .Fore .GREEN ,
13
24
colorama .Fore .YELLOW ,
Original file line number Diff line number Diff line change
1
+ import radon .cli .colors as colors
2
+
3
+
4
+ def test_color_enabled_yes (monkeypatch ):
5
+ monkeypatch .setenv ("COLOR" , "yes" )
6
+ assert colors .color_enabled ()
7
+
8
+
9
+ def test_color_enabled_no (monkeypatch ):
10
+ monkeypatch .setenv ("COLOR" , "no" )
11
+ assert not colors .color_enabled ()
12
+
13
+
14
+ def test_color_enabled_auto (monkeypatch , mocker ):
15
+ monkeypatch .setenv ("COLOR" , "auto" )
16
+ isatty_mock = mocker .patch ('sys.stdout.isatty' )
17
+
18
+ isatty_mock .return_value = True
19
+ assert colors .color_enabled ()
20
+
21
+ isatty_mock .return_value = False
22
+ assert not colors .color_enabled ()
You can’t perform that action at this time.
0 commit comments