<s> from __future__ import unicode_literals <EOL> import sys <EOL> import mock <EOL> import pytest <EOL> from pre_commit . color import format_color <EOL> from pre_commit . color import GREEN <EOL> from pre_commit . color import InvalidColorSetting <EOL> from pre_commit . color import use_color <EOL> @ pytest . mark . parametrize ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , ( <EOL> ( '<STR_LIT:foo>' , GREEN , True , '<STR_LIT>' . format ( GREEN ) ) , <EOL> ( '<STR_LIT:foo>' , GREEN , False , '<STR_LIT:foo>' ) , <EOL> ) ) <EOL> def test_format_color ( in_text , in_color , in_use_color , expected ) : <EOL> ret = format_color ( in_text , in_color , in_use_color ) <EOL> assert ret == expected <EOL> def test_use_color_never ( ) : <EOL> assert use_color ( '<STR_LIT>' ) is False <EOL> def test_use_color_always ( ) : <EOL> assert use_color ( '<STR_LIT>' ) is True <EOL> def test_use_color_no_tty ( ) : <EOL> with mock . patch . object ( sys . stdout , '<STR_LIT>' , return_value = False ) : <EOL> assert use_color ( '<STR_LIT>' ) is False <EOL> def test_use_color_tty ( ) : <EOL> with mock . patch . object ( sys . stdout , '<STR_LIT>' , return_value = True ) : <EOL> assert use_color ( '<STR_LIT>' ) is True <EOL> def test_use_color_raises_if_given_shenanigans ( ) : <EOL> with pytest . raises ( InvalidColorSetting ) : <EOL> use_color ( '<STR_LIT>' ) </s>
