<s> from __future__ import unicode_literals <EOL> import os <EOL> import sys <EOL> import uuid <EOL> from six . moves import cStringIO as StringIO <EOL> from rbtools . utils . filesystem import cleanup_tempfiles , make_tempdir <EOL> from rbtools . testing import TestCase <EOL> class RBTestBase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . _old_cwd = os . getcwd ( ) <EOL> self . set_user_home_tmp ( ) <EOL> def tearDown ( self ) : <EOL> os . chdir ( self . _old_cwd ) <EOL> cleanup_tempfiles ( ) <EOL> def create_tmp_dir ( self ) : <EOL> """<STR_LIT>""" <EOL> return make_tempdir ( ) <EOL> def chdir_tmp ( self , dir = None ) : <EOL> """<STR_LIT>""" <EOL> dirname = make_tempdir ( parent = dir ) <EOL> os . chdir ( dirname ) <EOL> return dirname <EOL> def gen_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> return str ( uuid . uuid4 ( ) ) <EOL> def get_user_home ( self ) : <EOL> """<STR_LIT>""" <EOL> return os . environ [ '<STR_LIT>' ] <EOL> def reset_cl_args ( self , values = [ ] ) : <EOL> """<STR_LIT>""" <EOL> sys . argv = values <EOL> def set_user_home ( self , path ) : <EOL> """<STR_LIT>""" <EOL> os . environ [ '<STR_LIT>' ] = path <EOL> def set_user_home_tmp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . set_user_home ( make_tempdir ( ) ) <EOL> def catch_output ( self , func ) : <EOL> stdout = sys . stdout <EOL> outbuf = StringIO ( ) <EOL> sys . stdout = outbuf <EOL> func ( ) <EOL> sys . stdout = stdout <EOL> return outbuf . getvalue ( ) </s>
