def test_cmd_exe_basic(self): activator = Activator('cmd.exe') self.make_dot_d_files(activator.script_extension) activate_result = activator.activate(self.prefix) with open(activate_result) as fh: activate_data = fh.read() rm_rf(activate_result) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" @SET "CONDA_DEFAULT_ENV=%(prefix)s" @SET "CONDA_PREFIX=%(prefix)s" @SET "CONDA_PROMPT_MODIFIER=(%(prefix)s) " @SET "CONDA_PYTHON_EXE=%(sys_executable)s" @SET "CONDA_SHLVL=1" @SET "PATH=%(new_path)s" @CALL "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.bat') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_result = activator.reactivate() with open(reactivate_result) as fh: reactivate_data = fh.read() rm_rf(reactivate_result) assert reactivate_data == dals(""" @CALL "%(deactivate1)s" @CALL "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.bat'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.bat'), } deactivate_result = activator.deactivate() with open(deactivate_result) as fh: deactivate_data = fh.read() rm_rf(deactivate_result) new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" @SET CONDA_DEFAULT_ENV= @SET CONDA_PREFIX= @SET CONDA_PROMPT_MODIFIER= @SET CONDA_PYTHON_EXE= @SET "CONDA_SHLVL=0" @SET "PATH=%(new_path)s" @CALL "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.bat'), }
def test_xonsh_basic(self): activator = Activator('xonsh') self.make_dot_d_files(activator.script_extension) activate_result = activator.activate(self.prefix) with open(activate_result) as fh: activate_data = fh.read() rm_rf(activate_result) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" $CONDA_DEFAULT_ENV = "%(prefix)s" $CONDA_PREFIX = "%(prefix)s" $CONDA_PROMPT_MODIFIER = "(%(prefix)s) " $CONDA_PYTHON_EXE = "%(sys_executable)s" $CONDA_SHLVL = "1" $PATH = "%(new_path)s" source "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.xsh') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_result = activator.reactivate() with open(reactivate_result) as fh: reactivate_data = fh.read() rm_rf(reactivate_result) assert reactivate_data == dals(""" source "%(deactivate1)s" source "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.xsh'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.xsh'), } deactivate_result = activator.deactivate() with open(deactivate_result) as fh: deactivate_data = fh.read() rm_rf(deactivate_result) new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" del $CONDA_DEFAULT_ENV del $CONDA_PREFIX del $CONDA_PROMPT_MODIFIER del $CONDA_PYTHON_EXE $CONDA_SHLVL = "0" $PATH = "%(new_path)s" source "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.xsh'), }
def test_remove_prefix_from_path_1(self): activator = Activator('posix') original_path = tuple(activator._get_starting_path_list()) keep_path = activator.path_conversion('/keep/this/path') final_path = (keep_path,) + original_path final_path = activator.path_conversion(final_path) test_prefix = join(os.getcwd(), 'mytestpath') new_paths = tuple(activator._get_path_dirs(test_prefix)) prefix_added_path = (keep_path,) + new_paths + original_path new_path = activator._remove_prefix_from_path(test_prefix, prefix_added_path) assert final_path == new_path
def test_remove_prefix_from_path_2(self): # this time prefix doesn't actually exist in path activator = Activator('posix') original_path = tuple(activator._get_starting_path_list()) keep_path = activator.path_conversion('/keep/this/path') final_path = (keep_path,) + original_path final_path = activator.path_conversion(final_path) test_prefix = join(os.getcwd(), 'mytestpath') prefix_added_path = (keep_path,) + original_path new_path = activator._remove_prefix_from_path(test_prefix, prefix_added_path) assert final_path == new_path
def test_powershell_basic(self): activator = Activator('powershell') self.make_dot_d_files(activator.script_extension) activate_data = activator.activate(self.prefix) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" $env:CONDA_DEFAULT_ENV = "%(prefix)s" $env:CONDA_PREFIX = "%(prefix)s" $env:CONDA_PROMPT_MODIFIER = "(%(prefix)s) " $env:CONDA_PYTHON_EXE = "%(sys_executable)s" $env:CONDA_SHLVL = "1" $env:PATH = "%(new_path)s" . "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.ps1') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_data = activator.reactivate() assert reactivate_data == dals(""" . "%(deactivate1)s" . "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.ps1'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.ps1'), } deactivate_data = activator.deactivate() new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" Remove-Variable CONDA_DEFAULT_ENV Remove-Variable CONDA_PREFIX Remove-Variable CONDA_PROMPT_MODIFIER Remove-Variable CONDA_PYTHON_EXE $env:CONDA_SHLVL = "0" $env:PATH = "%(new_path)s" . "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.ps1'), }
def test_fish_basic(self): activator = Activator('fish') self.make_dot_d_files(activator.script_extension) activate_data = activator.activate(self.prefix) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" set -gx CONDA_DEFAULT_ENV "%(prefix)s" set -gx CONDA_PREFIX "%(prefix)s" set -gx CONDA_PROMPT_MODIFIER "(%(prefix)s) " set -gx CONDA_PYTHON_EXE "%(sys_executable)s" set -gx CONDA_SHLVL "1" set -gx PATH "%(new_path)s" source "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.fish') } with env_var('CONDA_PREFIX', self.prefix): with env_var('CONDA_SHLVL', '1'): with env_var('PATH', os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],)))): reactivate_data = activator.reactivate() assert reactivate_data == dals(""" source "%(deactivate1)s" source "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.fish'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.fish'), } deactivate_data = activator.deactivate() new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" set -e CONDA_DEFAULT_ENV set -e CONDA_PREFIX set -e CONDA_PROMPT_MODIFIER set -e CONDA_PYTHON_EXE set -gx CONDA_SHLVL "0" set -gx PATH "%(new_path)s" source "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.fish'), }
def test_powershell_basic(self): activator = Activator('powershell') self.make_dot_d_files(activator.script_extension) with captured() as c: rc = activate_main(('', 'shell.powershell', 'activate', self.prefix)) assert not c.stderr assert rc == 0 activate_data = c.stdout new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" $env:CONDA_DEFAULT_ENV = "%(prefix)s" $env:CONDA_PREFIX = "%(prefix)s" $env:CONDA_PROMPT_MODIFIER = "(%(prefix)s) " $env:CONDA_PYTHON_EXE = "%(sys_executable)s" $env:CONDA_SHLVL = "1" $env:PATH = "%(new_path)s" . "%(activate1)s" """) % { 'prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': sys.executable, 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.ps1') } with env_vars({ 'CONDA_PREFIX': self.prefix, 'CONDA_SHLVL': '1', 'PATH': os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],))), }): with captured() as c: rc = activate_main(('', 'shell.powershell', 'reactivate')) assert not c.stderr assert rc == 0 reactivate_data = c.stdout assert reactivate_data == dals(""" $env:CONDA_PROMPT_MODIFIER = "(%(prefix)s) " $env:CONDA_SHLVL = "1" . "%(deactivate1)s" . "%(activate1)s" """) % { 'activate1': join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.ps1'), 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.ps1'), 'prefix': self.prefix, } with captured() as c: rc = activate_main(('', 'shell.powershell', 'deactivate')) assert not c.stderr assert rc == 0 deactivate_data = c.stdout new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" Remove-Variable CONDA_DEFAULT_ENV Remove-Variable CONDA_PREFIX Remove-Variable CONDA_PROMPT_MODIFIER Remove-Variable CONDA_PYTHON_EXE $env:CONDA_SHLVL = "0" $env:PATH = "%(new_path)s" . "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.ps1'), }
def test_fish_basic(self): activator = Activator('fish') self.make_dot_d_files(activator.script_extension) with captured() as c: rc = activate_main(('', 'shell.fish', 'activate', self.prefix)) assert not c.stderr assert rc == 0 activate_data = c.stdout new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" set -gx CONDA_DEFAULT_ENV "%(native_prefix)s" set -gx CONDA_PREFIX "%(native_prefix)s" set -gx CONDA_PROMPT_MODIFIER "(%(native_prefix)s) " set -gx CONDA_PYTHON_EXE "%(sys_executable)s" set -gx CONDA_SHLVL "1" set -gx PATH "%(new_path)s" source "%(activate1)s" """) % { 'converted_prefix': activator.path_conversion(self.prefix), 'native_prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': activator.path_conversion(sys.executable), 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.fish')), } with env_vars({ 'CONDA_PREFIX': self.prefix, 'CONDA_SHLVL': '1', 'PATH': os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],))), }): with captured() as c: rc = activate_main(('', 'shell.fish', 'reactivate')) assert not c.stderr assert rc == 0 reactivate_data = c.stdout assert reactivate_data == dals(""" set -gx CONDA_PROMPT_MODIFIER "(%(native_prefix)s) " set -gx CONDA_SHLVL "1" source "%(deactivate1)s" source "%(activate1)s" """) % { 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.fish')), 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.fish')), 'native_prefix': self.prefix, } with captured() as c: rc = activate_main(('', 'shell.fish', 'deactivate')) assert not c.stderr assert rc == 0 deactivate_data = c.stdout new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" set -e CONDA_DEFAULT_ENV set -e CONDA_PREFIX set -e CONDA_PROMPT_MODIFIER set -e CONDA_PYTHON_EXE set -gx CONDA_SHLVL "0" set -gx PATH "%(new_path)s" source "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.fish')), }
def test_xonsh_basic(self): activator = Activator('xonsh') self.make_dot_d_files(activator.script_extension) with captured() as c: rc = activate_main(('', 'shell.xonsh', 'activate', self.prefix)) assert not c.stderr assert rc == 0 activate_result = c.stdout with open(activate_result) as fh: activate_data = fh.read() rm_rf(activate_result) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" $CONDA_DEFAULT_ENV = "%(native_prefix)s" $CONDA_PREFIX = "%(native_prefix)s" $CONDA_PROMPT_MODIFIER = "(%(native_prefix)s) " $CONDA_PYTHON_EXE = "%(sys_executable)s" $CONDA_SHLVL = "1" $PATH = "%(new_path)s" source "%(activate1)s" """) % { 'converted_prefix': activator.path_conversion(self.prefix), 'native_prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': activator.path_conversion(sys.executable), 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.xsh')), } with env_vars({ 'CONDA_PREFIX': self.prefix, 'CONDA_SHLVL': '1', 'PATH': os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],))), }): with captured() as c: assert activate_main(('', 'shell.xonsh', 'reactivate')) == 0 assert not c.stderr reactivate_result = c.stdout with open(reactivate_result) as fh: reactivate_data = fh.read() rm_rf(reactivate_result) assert reactivate_data == dals(""" $CONDA_PROMPT_MODIFIER = "(%(native_prefix)s) " $CONDA_SHLVL = "1" source "%(deactivate1)s" source "%(activate1)s" """) % { 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.xsh')), 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.xsh')), 'native_prefix': self.prefix, } with captured() as c: assert activate_main(('', 'shell.xonsh', 'deactivate')) == 0 assert not c.stderr deactivate_result = c.stdout with open(deactivate_result) as fh: deactivate_data = fh.read() rm_rf(deactivate_result) new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" del $CONDA_DEFAULT_ENV del $CONDA_PREFIX del $CONDA_PROMPT_MODIFIER del $CONDA_PYTHON_EXE $CONDA_SHLVL = "0" $PATH = "%(new_path)s" source "%(deactivate1)s" """) % { 'new_path': new_path, 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.xsh')), }
def test_cmd_exe_basic(self): activator = Activator('cmd.exe') self.make_dot_d_files(activator.script_extension) with captured() as c: rc = activate_main(('', 'shell.cmd.exe', 'activate', '', self.prefix)) assert not c.stderr assert rc == 0 activate_result = c.stdout with open(activate_result) as fh: activate_data = fh.read() rm_rf(activate_result) new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" @SET "CONDA_DEFAULT_ENV=%(native_prefix)s" @SET "CONDA_PREFIX=%(converted_prefix)s" @SET "CONDA_PROMPT_MODIFIER=(%(native_prefix)s) " @SET "CONDA_PYTHON_EXE=%(sys_executable)s" @SET "CONDA_SHLVL=1" @SET "PATH=%(new_path)s" @SET "PYTHONIOENCODING=%(PYTHONIOENCODING)s" @CALL "%(activate1)s" """) % { 'converted_prefix': activator.path_conversion(self.prefix), 'native_prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': activator.path_conversion(sys.executable), 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.bat')), 'PYTHONIOENCODING': PYTHONIOENCODING, } with env_vars({ 'CONDA_PREFIX': self.prefix, 'CONDA_SHLVL': '1', 'PATH': os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],))), }): with captured() as c: assert activate_main(('', 'shell.cmd.exe', 'reactivate')) == 0 assert not c.stderr reactivate_result = c.stdout with open(reactivate_result) as fh: reactivate_data = fh.read() rm_rf(reactivate_result) assert reactivate_data == dals(""" @CALL "%(deactivate1)s" @SET "CONDA_PROMPT_MODIFIER=(%(native_prefix)s) " @SET "CONDA_SHLVL=1" @CALL "%(activate1)s" """) % { 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.bat')), 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.bat')), 'native_prefix': self.prefix, } with captured() as c: assert activate_main(('', 'shell.cmd.exe', 'deactivate')) == 0 assert not c.stderr deactivate_result = c.stdout with open(deactivate_result) as fh: deactivate_data = fh.read() rm_rf(deactivate_result) new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" @CALL "%(deactivate1)s" @SET CONDA_DEFAULT_ENV= @SET CONDA_PREFIX= @SET CONDA_PROMPT_MODIFIER= @SET CONDA_PYTHON_EXE= @SET "CONDA_SHLVL=0" @SET "PATH=%(new_path)s" """) % { 'new_path': new_path, 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.bat')), }
def test_posix_basic(self): activator = Activator('posix') self.make_dot_d_files(activator.script_extension) with captured() as c: rc = activate_main(('', 'shell.posix', 'activate', self.prefix)) assert not c.stderr assert rc == 0 activate_data = c.stdout new_path_parts = activator._add_prefix_to_path(self.prefix) assert activate_data == dals(""" PS1='%(ps1)s' export CONDA_DEFAULT_ENV='%(native_prefix)s' export CONDA_PREFIX='%(native_prefix)s' export CONDA_PROMPT_MODIFIER='(%(native_prefix)s) ' export CONDA_PYTHON_EXE='%(sys_executable)s' export CONDA_SHLVL='1' export PATH='%(new_path)s' . "%(activate1)s" """) % { 'converted_prefix': activator.path_conversion(self.prefix), 'native_prefix': self.prefix, 'new_path': activator.pathsep_join(new_path_parts), 'sys_executable': activator.path_conversion(sys.executable), 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.sh')), 'ps1': '(%s) ' % self.prefix + os.environ.get('PS1', '') } with env_vars({ 'CONDA_PREFIX': self.prefix, 'CONDA_SHLVL': '1', 'PATH': os.pathsep.join(concatv(new_path_parts, (os.environ['PATH'],))), }): with captured() as c: rc = activate_main(('', 'shell.posix', 'reactivate')) assert not c.stderr assert rc == 0 reactivate_data = c.stdout assert reactivate_data == dals(""" . "%(deactivate1)s" export CONDA_PROMPT_MODIFIER='(%(native_prefix)s) ' export CONDA_SHLVL='1' . "%(activate1)s" """) % { 'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.sh')), 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.sh')), 'native_prefix': self.prefix, } with captured() as c: rc = activate_main(('', 'shell.posix', 'deactivate')) assert not c.stderr assert rc == 0 deactivate_data = c.stdout new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix)) assert deactivate_data == dals(""" . "%(deactivate1)s" unset CONDA_DEFAULT_ENV unset CONDA_PREFIX unset CONDA_PROMPT_MODIFIER unset CONDA_PYTHON_EXE PS1='%(ps1)s' export CONDA_SHLVL='0' export PATH='%(new_path)s' """) % { 'new_path': new_path, 'deactivate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1.sh')), 'ps1': os.environ.get('PS1', ''), }