예제 #1
0
    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'),
                    }
예제 #2
0
    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'),
                    }
예제 #3
0
    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'),

                    }
예제 #4
0
    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'),

                    }