<s> from mock import Mock , patch <EOL> import sys <EOL> try : <EOL> from unittest2 import TestCase , main , skipUnless <EOL> except ImportError : <EOL> from unittest import TestCase , main , skipUnless <EOL> from . . winterm import WinColor , WinStyle , WinTerm <EOL> class WinTermTest ( TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> def testInit ( self , mockWin32 ) : <EOL> mockAttr = Mock ( ) <EOL> mockAttr . wAttributes = <NUM_LIT:7> + <NUM_LIT:6> * <NUM_LIT:16> + <NUM_LIT:8> <EOL> mockWin32 . GetConsoleScreenBufferInfo . return_value = mockAttr <EOL> term = WinTerm ( ) <EOL> self . assertEqual ( term . _fore , <NUM_LIT:7> ) <EOL> self . assertEqual ( term . _back , <NUM_LIT:6> ) <EOL> self . assertEqual ( term . _style , <NUM_LIT:8> ) <EOL> @ skipUnless ( sys . platform . startswith ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def testGetAttrs ( self ) : <EOL> term = WinTerm ( ) <EOL> term . _fore = <NUM_LIT:0> <EOL> term . _back = <NUM_LIT:0> <EOL> term . _style = <NUM_LIT:0> <EOL> self . assertEqual ( term . get_attrs ( ) , <NUM_LIT:0> ) <EOL> term . _fore = WinColor . YELLOW <EOL> self . assertEqual ( term . get_attrs ( ) , WinColor . YELLOW ) <EOL> term . _back = WinColor . MAGENTA <EOL> self . assertEqual ( <EOL> term . get_attrs ( ) , <EOL> WinColor . YELLOW + WinColor . MAGENTA * <NUM_LIT:16> ) <EOL> term . _style = WinStyle . BRIGHT <EOL> self . assertEqual ( <EOL> term . get_attrs ( ) , <EOL> WinColor . YELLOW + WinColor . MAGENTA * <NUM_LIT:16> + WinStyle . BRIGHT ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def testResetAll ( self , mockWin32 ) : <EOL> mockAttr = Mock ( ) <EOL> mockAttr . wAttributes = <NUM_LIT:1> + <NUM_LIT:2> * <NUM_LIT:16> + <NUM_LIT:8> <EOL> mockWin32 . GetConsoleScreenBufferInfo . return_value = mockAttr <EOL> term = WinTerm ( ) <EOL> term . set_console = Mock ( ) <EOL> term . _fore = - <NUM_LIT:1> <EOL> term . _back = - <NUM_LIT:1> <EOL> term . _style = - <NUM_LIT:1> <EOL> term . reset_all ( ) <EOL> self . assertEqual ( term . _fore , <NUM_LIT:1> ) <EOL> self . assertEqual ( term . _back , <NUM_LIT:2> ) <EOL> self . assertEqual ( term . _style , <NUM_LIT:8> ) <EOL> self . assertEqual ( term . set_console . called , True ) <EOL> @ skipUnless ( sys . platform . startswith ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def testFore ( self ) : <EOL> term = WinTerm ( ) <EOL> term . set_console = Mock ( ) <EOL> term . _fore = <NUM_LIT:0> <EOL> term . fore ( <NUM_LIT:5> ) <EOL> self . assertEqual ( term . _fore , <NUM_LIT:5> ) <EOL> self . assertEqual ( term . set_console . called , True ) <EOL> @ skipUnless ( sys . platform . startswith ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def testBack ( self ) : <EOL> term = WinTerm ( ) <EOL> term . set_console = Mock ( ) <EOL> term . _back = <NUM_LIT:0> <EOL> term . back ( <NUM_LIT:5> ) <EOL> self . assertEqual ( term . _back , <NUM_LIT:5> ) <EOL> self . assertEqual ( term . set_console . called , True ) <EOL> @ skipUnless ( sys . platform . startswith ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def testStyle ( self ) : <EOL> term = WinTerm ( ) <EOL> term . set_console = Mock ( ) <EOL> term . _style = <NUM_LIT:0> <EOL> term . style ( <NUM_LIT> ) <EOL> self . assertEqual ( term . _style , <NUM_LIT> ) <EOL> self . assertEqual ( term . set_console . called , True ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def testSetConsole ( self , mockWin32 ) : <EOL> mockAttr = Mock ( ) <EOL> mockAttr . wAttributes = <NUM_LIT:0> <EOL> mockWin32 . GetConsoleScreenBufferInfo . return_value = mockAttr <EOL> term = WinTerm ( ) <EOL> term . windll = Mock ( ) <EOL> term . set_console ( ) <EOL> self . assertEqual ( <EOL> mockWin32 . SetConsoleTextAttribute . call_args , <EOL> ( ( mockWin32 . STDOUT , term . get_attrs ( ) ) , { } ) <EOL> ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def testSetConsoleOnStderr ( self , mockWin32 ) : <EOL> mockAttr = Mock ( ) <EOL> mockAttr . wAttributes = <NUM_LIT:0> <EOL> mockWin32 . GetConsoleScreenBufferInfo . return_value = mockAttr <EOL> term = WinTerm ( ) <EOL> term . windll = Mock ( ) <EOL> term . set_console ( on_stderr = True ) <EOL> self . assertEqual ( <EOL> mockWin32 . SetConsoleTextAttribute . call_args , <EOL> ( ( mockWin32 . STDERR , term . get_attrs ( ) ) , { } ) <EOL> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
