<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import unittest <EOL> import qisys . sh <EOL> import qisys . envsetter <EOL> import qibuild . config <EOL> class EnvSetterTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . environ_back = os . environ . copy ( ) <EOL> os . environ = dict ( ) <EOL> if sys . platform . startswith ( "<STR_LIT>" ) : <EOL> os . environ [ "<STR_LIT>" ] = r"<STR_LIT>" <EOL> self . unlikely = r"<STR_LIT>" <EOL> self . absurd = r"<STR_LIT>" <EOL> else : <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . unlikely = "<STR_LIT>" <EOL> self . absurd = "<STR_LIT>" <EOL> def tearDown ( self ) : <EOL> os . environ = self . environ_back . copy ( ) <EOL> def _check_is_in_path ( self , directory , path_env ) : <EOL> """<STR_LIT>""" <EOL> paths = path_env . split ( os . path . pathsep ) <EOL> mess = "<STR_LIT>" % ( directory , paths ) <EOL> self . assertTrue ( directory in paths , mess ) <EOL> def test_create_new_env ( self ) : <EOL> envsetter = qisys . envsetter . EnvSetter ( ) <EOL> envsetter . set_env_var ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> build_env = envsetter . get_build_env ( ) <EOL> self . assertTrue ( build_env . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> def test_prepend_to_path ( self ) : <EOL> previous_path = os . environ [ "<STR_LIT>" ] <EOL> envsetter = qisys . envsetter . EnvSetter ( ) <EOL> envsetter . prepend_to_path ( self . unlikely ) <EOL> build_env = envsetter . get_build_env ( ) <EOL> self . assertEquals ( os . environ [ "<STR_LIT>" ] , previous_path ) <EOL> new_path = build_env [ "<STR_LIT>" ] <EOL> self . _check_is_in_path ( self . unlikely , new_path ) <EOL> def test_prepend_to_path_twice_the_same ( self ) : <EOL> previous_path = os . environ [ "<STR_LIT>" ] <EOL> envsetter = qisys . envsetter . EnvSetter ( ) <EOL> envsetter . prepend_to_path ( self . unlikely ) <EOL> path_env1 = envsetter . get_build_env ( ) [ "<STR_LIT>" ] <EOL> envsetter . prepend_to_path ( self . unlikely ) <EOL> path_env2 = envsetter . get_build_env ( ) [ "<STR_LIT>" ] <EOL> self . assertEquals ( os . environ [ "<STR_LIT>" ] , previous_path ) <EOL> self . assertEquals ( path_env1 , path_env2 ) <EOL> self . _check_is_in_path ( self . unlikely , path_env1 ) <EOL> def test_prepend_to_path_multi ( self ) : <EOL> envsetter = qisys . envsetter . EnvSetter ( ) <EOL> to_add = self . unlikely + os . path . pathsep + self . absurd <EOL> envsetter . prepend_to_path ( to_add ) <EOL> env_path = envsetter . get_build_env ( ) [ "<STR_LIT>" ] <EOL> self . _check_is_in_path ( self . unlikely , env_path ) <EOL> self . _check_is_in_path ( self . absurd , env_path ) <EOL> def test_prepend_to_path_several_times ( self ) : <EOL> previous_path = os . environ [ "<STR_LIT>" ] <EOL> envsetter = qisys . envsetter . EnvSetter ( ) <EOL> envsetter . prepend_to_path ( self . unlikely ) <EOL> envsetter . prepend_to_path ( self . absurd ) <EOL> path_env = envsetter . get_build_env ( ) [ "<STR_LIT>" ] <EOL> self . assertEquals ( os . environ [ "<STR_LIT>" ] , previous_path ) <EOL> self . _check_is_in_path ( self . unlikely , path_env ) <EOL> self . _check_is_in_path ( self . absurd , path_env ) <EOL> def test_no_side_effects ( self ) : <EOL> envsetter = qisys . envsetter . EnvSetter ( ) <EOL> build_env = envsetter . get_build_env ( ) <EOL> build_env [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . assertTrue ( envsetter . get_build_env ( ) . get ( "<STR_LIT>" ) is None ) <EOL> if sys . platform . startswith ( "<STR_LIT>" ) : <EOL> def test_source_bat ( self ) : <EOL> vc_path = r'<STR_LIT>' <EOL> lib_path = r'<STR_LIT>' <EOL> with qisys . sh . TempDir ( ) as tmp : <EOL> sourceme = os . path . join ( tmp , "<STR_LIT>" ) <EOL> to_write = r"""<STR_LIT>""" . format ( vc_path , lib_path ) <EOL> with open ( sourceme , "<STR_LIT:w>" ) as fp : <EOL> fp . write ( to_write ) <EOL> envsetter = qisys . envsetter . EnvSetter ( ) <EOL> envsetter . source_bat ( sourceme ) <EOL> build_env = envsetter . get_build_env ( ) <EOL> build_env_path = build_env [ "<STR_LIT>" ] <EOL> self . _check_is_in_path ( vc_path , build_env [ "<STR_LIT>" ] ) <EOL> self . _check_is_in_path ( lib_path , build_env [ "<STR_LIT>" ] ) <EOL> envsetter . source_bat ( sourceme ) <EOL> build_env_path2 = envsetter . get_build_env ( ) [ "<STR_LIT>" ] <EOL> self . assertEquals ( build_env_path2 , build_env_path ) <EOL> def test_reads_env_vars_from_config ( tmpdir ) : <EOL> qibuild_xml = tmpdir . join ( "<STR_LIT>" ) <EOL> qibuild_xml . write ( """<STR_LIT>""" ) <EOL> qibuild_cfg = qibuild . config . QiBuildConfig ( ) <EOL> qibuild_cfg . read ( qibuild_xml . strpath ) <EOL> qibuild_cfg . set_active_config ( "<STR_LIT>" ) <EOL> env_setter = qisys . envsetter . EnvSetter ( ) <EOL> env_setter . read_config ( qibuild_cfg ) <EOL> build_env = env_setter . get_build_env ( ) <EOL> assert build_env [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> assert build_env [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> def test_updating_env_vars ( tmpdir ) : <EOL> qibuild_xml = tmpdir . join ( "<STR_LIT>" ) <EOL> qibuild_xml . write ( """<STR_LIT>""" ) <EOL> qibuild_cfg = qibuild . config . QiBuildConfig ( ) <EOL> qibuild_cfg . read ( qibuild_xml . strpath ) <EOL> qibuild_cfg . set_active_config ( "<STR_LIT>" ) <EOL> env_setter = qisys . envsetter . EnvSetter ( ) <EOL> env_setter . read_config ( qibuild_cfg ) <EOL> build_env = env_setter . get_build_env ( ) <EOL> assert build_env [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> def test_prepending_variable_already_here ( ) : <EOL> env = { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> envsetter = qisys . envsetter . EnvSetter ( build_env = env ) <EOL> envsetter . prepend_to_path ( "<STR_LIT>" ) <EOL> envsetter . prepend_to_path ( "<STR_LIT>" ) <EOL> actual = envsetter . get_build_env ( ) [ "<STR_LIT>" ] <EOL> assert actual == "<STR_LIT>" <EOL> def main ( ) : <EOL> unittest . main ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
