<s> import os <EOL> import types <EOL> from focus_unittest import FocusTestCase <EOL> from focus . environment . io import IOStream <EOL> class TestIOStream ( FocusTestCase ) : <EOL> class Mock ( object ) : <EOL> def read ( self ) : <EOL> return '<STR_LIT>' <EOL> def write ( self , s ) : <EOL> self . test__data = s <EOL> def setUp ( self ) : <EOL> super ( TestIOStream , self ) . setUp ( ) <EOL> self . io = IOStream ( inputs = self . Mock ( ) , outputs = self . Mock ( ) , <EOL> errors = self . Mock ( ) ) <EOL> def tearDown ( self ) : <EOL> self . io = None <EOL> super ( TestIOStream , self ) . tearDown ( ) <EOL> def test__read ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . io . read ( ) , '<STR_LIT>' ) <EOL> def test__write ( self ) : <EOL> """<STR_LIT>""" <EOL> testval = '<STR_LIT>' <EOL> self . io . write ( testval , newline = False ) <EOL> self . assertEqual ( self . io . _output . test__data , testval ) <EOL> self . io . write ( testval , newline = True ) <EOL> self . assertEqual ( self . io . _output . test__data , testval + os . linesep ) <EOL> def test__success ( self ) : <EOL> """<STR_LIT>""" <EOL> testval = '<STR_LIT>' <EOL> color_testval = '<STR_LIT>' . format ( self . io . ESCAPE_GREEN , <EOL> self . io . ESCAPE_CLEAR ) <EOL> self . io . set_colored ( True ) <EOL> self . io . success ( testval , newline = False ) <EOL> self . assertEqual ( self . io . _output . test__data , color_testval ) <EOL> self . io . success ( testval , newline = True ) <EOL> self . assertEqual ( self . io . _output . test__data , color_testval + <EOL> os . linesep ) <EOL> self . io . set_colored ( False ) <EOL> self . io . success ( testval , newline = False ) <EOL> self . assertEqual ( self . io . _output . test__data , testval ) <EOL> self . io . success ( testval , newline = True ) <EOL> self . assertEqual ( self . io . _output . test__data , testval + os . linesep ) <EOL> def test__error ( self ) : <EOL> """<STR_LIT>""" <EOL> testval = '<STR_LIT>' <EOL> color_testval = '<STR_LIT>' . format ( self . io . ESCAPE_RED , <EOL> self . io . ESCAPE_CLEAR ) <EOL> self . io . set_colored ( True ) <EOL> self . io . error ( testval , newline = False ) <EOL> self . assertEqual ( self . io . _error . test__data , color_testval ) <EOL> self . io . error ( testval , newline = True ) <EOL> self . assertEqual ( self . io . _error . test__data , color_testval + os . linesep ) <EOL> self . io . set_colored ( False ) <EOL> self . io . error ( testval , newline = False ) <EOL> self . assertEqual ( self . io . _error . test__data , testval ) <EOL> self . io . error ( testval , newline = True ) <EOL> self . assertEqual ( self . io . _error . test__data , testval + os . linesep ) <EOL> def test__set_colored ( self ) : <EOL> """<STR_LIT>""" <EOL> self . io . set_colored ( False ) <EOL> self . assertFalse ( self . io . _colored ) <EOL> self . io . set_colored ( True ) <EOL> self . assertTrue ( self . io . _colored ) <EOL> self . io . set_colored ( <NUM_LIT:0> ) <EOL> self . assertFalse ( self . io . _colored ) <EOL> self . io . set_colored ( <NUM_LIT:1> ) <EOL> self . assertTrue ( self . io . _colored ) <EOL> def test__isatty ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertFalse ( self . io . isatty ) <EOL> self . io . _input . isatty = types . MethodType ( lambda self : True , <EOL> self . io . _input ) <EOL> self . assertTrue ( self . io . isatty ) <EOL> self . io . _input . isatty = types . MethodType ( lambda self : False , <EOL> self . io . _input ) <EOL> self . assertFalse ( self . io . isatty ) </s>
