<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> from __future__ import division <EOL> from __future__ import absolute_import <EOL> import unittest <EOL> import io <EOL> import sys <EOL> from pyexperiment . utils . stdout_redirector import stdout_redirector , stdout_err_redirector <EOL> class TestStdoutRedirector ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def test_captures_stdout ( self ) : <EOL> """<STR_LIT>""" <EOL> message = "<STR_LIT>" <EOL> buf = io . StringIO ( ) <EOL> with stdout_redirector ( buf ) : <EOL> print ( message ) <EOL> self . assertEqual ( buf . getvalue ( ) , message + '<STR_LIT:\n>' ) <EOL> def test_captures_stdout_stderr ( self ) : <EOL> """<STR_LIT>""" <EOL> message1 = "<STR_LIT>" <EOL> message2 = "<STR_LIT>" <EOL> buf_out = io . StringIO ( ) <EOL> buf_err = io . StringIO ( ) <EOL> with stdout_err_redirector ( buf_out , buf_err ) : <EOL> print ( message1 ) <EOL> print ( message2 , file = sys . stderr ) <EOL> self . assertEqual ( buf_out . getvalue ( ) , message1 + '<STR_LIT:\n>' ) <EOL> self . assertEqual ( buf_err . getvalue ( ) , message2 + '<STR_LIT:\n>' ) </s>
