<s> import StringIO <EOL> import unittest <EOL> from pikos . recorders . text_stream_recorder import TextStreamRecorder <EOL> from pikos . recorders . abstract_recorder import RecorderError <EOL> from pikos . tests . compat import TestCase <EOL> from pikos . tests . dummy_record import DummyRecord <EOL> class TestTextStreamRecorder ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . temp = StringIO . StringIO ( ) <EOL> self . maxDiff = None <EOL> def tearDown ( self ) : <EOL> self . temp . close ( ) <EOL> def test_prepare ( self ) : <EOL> header = '<STR_LIT>' <EOL> recorder = TextStreamRecorder ( self . temp ) <EOL> recorder . prepare ( DummyRecord ) <EOL> self . assertMultiLineEqual ( self . temp . getvalue ( ) , header ) <EOL> recorder . prepare ( DummyRecord ) <EOL> for x in range ( <NUM_LIT:10> ) : <EOL> recorder . prepare ( DummyRecord ) <EOL> self . assertMultiLineEqual ( self . temp . getvalue ( ) , header ) <EOL> def test_finalize ( self ) : <EOL> header = '<STR_LIT>' <EOL> recorder = TextStreamRecorder ( self . temp ) <EOL> recorder . prepare ( DummyRecord ) <EOL> for x in range ( <NUM_LIT:10> ) : <EOL> recorder . finalize ( ) <EOL> self . assertMultiLineEqual ( self . temp . getvalue ( ) , header ) <EOL> def test_record ( self ) : <EOL> record = DummyRecord ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> output = '<STR_LIT>' <EOL> recorder = TextStreamRecorder ( self . temp ) <EOL> recorder . prepare ( DummyRecord ) <EOL> recorder . record ( record ) <EOL> self . assertMultiLineEqual ( self . temp . getvalue ( ) , output ) <EOL> def test_filter ( self ) : <EOL> records = [ <EOL> DummyRecord ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> DummyRecord ( <NUM_LIT:12> , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> output = '<STR_LIT>' <EOL> def not_pikos ( values ) : <EOL> return not ( '<STR_LIT>' in values ) <EOL> recorder = TextStreamRecorder ( self . temp , filter_ = not_pikos ) <EOL> recorder . prepare ( DummyRecord ) <EOL> for record in records : <EOL> recorder . record ( record ) <EOL> self . assertMultiLineEqual ( self . temp . getvalue ( ) , output ) <EOL> def test_exceptions ( self ) : <EOL> record = DummyRecord ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> recorder = TextStreamRecorder ( self . temp ) <EOL> with self . assertRaises ( RecorderError ) : <EOL> recorder . record ( record ) <EOL> with self . assertRaises ( RecorderError ) : <EOL> recorder . finalize ( ) <EOL> def test_formatter_with_namedtuples ( self ) : <EOL> record = DummyRecord ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> output = '<STR_LIT>' <EOL> recorder = TextStreamRecorder ( self . temp , formatted = True ) <EOL> recorder . prepare ( DummyRecord ) <EOL> recorder . record ( record ) <EOL> self . assertMultiLineEqual ( self . temp . getvalue ( ) , output ) <EOL> def test_formatter_with_tuples ( self ) : <EOL> record = ( <NUM_LIT:5> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> output = '<STR_LIT>' <EOL> recorder = TextStreamRecorder ( self . temp , formatted = True ) <EOL> recorder . prepare ( tuple ) <EOL> recorder . record ( record ) <EOL> self . assertMultiLineEqual ( self . temp . getvalue ( ) , output ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
