File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 22terminal.
33'''
44
5+ import os
56import sys
67
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+
718try :
819 import colorama
920
10- colorama .init (strip = ( not sys . stdout . isatty () ))
21+ colorama .init (strip = not color_enabled ( ))
1122 GREEN , YELLOW , RED = (
1223 colorama .Fore .GREEN ,
1324 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