<s> import os <EOL> import terminal <EOL> from nose . tools import raises <EOL> def test_colorize ( ) : <EOL> print ( terminal . colorize ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print ( terminal . colorize ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print ( terminal . colorize ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print ( terminal . colorize ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print ( terminal . colorize ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print ( terminal . colorize ( '<STR_LIT>' , ( <NUM_LIT:255> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ) <EOL> print ( terminal . colorize ( '<STR_LIT>' , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> print ( terminal . colorize ( '<STR_LIT>' , '<STR_LIT>' , True ) ) <EOL> def test_colors ( ) : <EOL> print ( terminal . cyan ( '<STR_LIT>' ) ) <EOL> print ( terminal . blue ( '<STR_LIT>' ) ) <EOL> print ( terminal . yellow ( '<STR_LIT>' ) ) <EOL> print ( terminal . magenta ( '<STR_LIT>' ) ) <EOL> print ( terminal . black ( '<STR_LIT>' ) ) <EOL> print ( terminal . white ( '<STR_LIT>' ) ) <EOL> print ( terminal . gray ( '<STR_LIT>' ) ) <EOL> print ( terminal . grey ( '<STR_LIT>' ) ) <EOL> print ( terminal . red ( terminal . green ( '<STR_LIT>' ) ) ) <EOL> print ( terminal . cyan_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . blue_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . yellow_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . magenta_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . black_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . white_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . gray_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . grey_bg ( '<STR_LIT>' ) ) <EOL> print ( terminal . red_bg ( terminal . green_bg ( '<STR_LIT>' ) ) ) <EOL> def test_styles ( ) : <EOL> print ( terminal . bold ( '<STR_LIT>' ) ) <EOL> print ( terminal . faint ( '<STR_LIT>' ) ) <EOL> print ( terminal . italic ( '<STR_LIT>' ) ) <EOL> print ( terminal . underline ( '<STR_LIT>' ) ) <EOL> print ( terminal . blink ( '<STR_LIT>' ) ) <EOL> print ( terminal . overline ( '<STR_LIT>' ) ) <EOL> print ( terminal . inverse ( '<STR_LIT>' ) ) <EOL> print ( terminal . conceal ( '<STR_LIT>' ) ) <EOL> print ( terminal . strike ( '<STR_LIT>' ) ) <EOL> print ( terminal . bold ( terminal . underline ( '<STR_LIT>' ) ) ) <EOL> @ raises ( ValueError ) <EOL> def test_hex2ansi ( ) : <EOL> terminal . hex2ansi ( '<STR_LIT>' ) <EOL> @ raises ( ValueError ) <EOL> def test_raise_colorize ( ) : <EOL> print ( terminal . colorize ( '<STR_LIT:text>' , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) ) <EOL> def test_256color ( ) : <EOL> env = Environ ( ) <EOL> env . enable_256color ( ) <EOL> print ( terminal . gray ( '<STR_LIT>' ) ) <EOL> print ( terminal . gray_bg ( '<STR_LIT>' ) ) <EOL> env . reset ( ) <EOL> class Environ ( object ) : <EOL> def __init__ ( self ) : <EOL> self . term = os . environ . get ( '<STR_LIT>' , None ) <EOL> def enable_256color ( self ) : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def enable_color ( self ) : <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def reset ( self ) : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in os . environ : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> if self . term : <EOL> os . environ [ '<STR_LIT>' ] = self . term <EOL> class TestColor ( object ) : <EOL> def test_property ( self ) : <EOL> env = Environ ( ) <EOL> env . enable_color ( ) <EOL> s = terminal . Color ( '<STR_LIT:text>' ) <EOL> print ( s . bold . red . underline ) <EOL> print ( s . green_bg ) <EOL> env . reset ( ) <EOL> def test_set_attribute ( self ) : <EOL> env = Environ ( ) <EOL> env . enable_256color ( ) <EOL> s = terminal . Color ( '<STR_LIT:text>' ) <EOL> s . bgcolor = '<STR_LIT>' <EOL> s . fgcolor = '<STR_LIT>' <EOL> print ( s ) <EOL> s . bgcolor = '<STR_LIT>' <EOL> print ( s ) <EOL> env . reset ( ) <EOL> @ raises ( AttributeError ) <EOL> def test_property_raise ( self ) : <EOL> s = terminal . Color ( '<STR_LIT:text>' ) <EOL> print ( s . unknown ) <EOL> @ raises ( AttributeError ) <EOL> def test_unknown_bg ( self ) : <EOL> s = terminal . Color ( '<STR_LIT:text>' ) <EOL> print ( s . unknown_bg ) <EOL> def test_plus ( self ) : <EOL> foo = terminal . Color ( '<STR_LIT:foo>' ) <EOL> print ( foo . green + '<STR_LIT:bar>' ) <EOL> print ( '<STR_LIT:bar>' + foo ) <EOL> assert len ( foo ) == <NUM_LIT:3> <EOL> assert len ( '<STR_LIT:bar>' + foo ) == <NUM_LIT:6> <EOL> bar = terminal . Color ( '<STR_LIT:foo>' ) <EOL> print ( foo . green + bar ) <EOL> print ( bar + foo ) <EOL> @ raises ( TypeError ) <EOL> def test_add_raise ( self ) : <EOL> foo = terminal . Color ( '<STR_LIT:foo>' ) <EOL> print ( foo . green + <NUM_LIT:1> ) <EOL> @ raises ( TypeError ) <EOL> def test_radd_raise ( self ) : <EOL> foo = terminal . Color ( '<STR_LIT:foo>' ) <EOL> print ( <NUM_LIT:1> + foo . green ) <EOL> def test_repr ( self ) : <EOL> foo = terminal . Color ( '<STR_LIT:foo>' ) <EOL> foo . fgcolor = '<STR_LIT>' <EOL> assert repr ( foo ) == repr ( str ( foo ) ) </s>
