HEX
Server: Apache
System: Linux p102.lithium.hosting 4.18.0-553.141.1.el8_10.x86_64 #1 SMP Fri Jul 10 17:48:02 UTC 2026 x86_64
User: bvzmoamr (9955)
PHP: 8.1.34
Disabled: syslog
Upload Files
File: //usr/local/share/python/pyenv/plugins/pyenv-virtualenv/test/activate.bats
#!/usr/bin/env bats

load test_helper

setup() {
  export HOME="${TMP}"
  export PYENV_ROOT="${TMP}/pyenv"
  unset PYENV_VERSION
  unset PYENV_ACTIVATE_SHELL
  unset VIRTUAL_ENV
  unset CONDA_DEFAULT_ENV
  unset PYTHONHOME
  unset _OLD_VIRTUAL_PYTHONHOME
  unset PYENV_VIRTUALENV_VERBOSE_ACTIVATE
  unset PYENV_VIRTUALENV_DISABLE_PROMPT
  unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
  unset VIRTUAL_ENV_DISABLE_PROMPT
  unset _OLD_VIRTUAL_PS1
}

@test "activate virtualenv from current version" {
  export PYENV_VIRTUALENV_INIT=1

  stub pyenv-version-name "echo venv"
  stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate

  assert_success
  assert_output <<EOS
deactivated
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(venv) \${PS1}";
EOS

  unstub pyenv-version-name
  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from current version (quiet)" {
  export PYENV_VIRTUALENV_INIT=1

  stub pyenv-version-name "echo venv"
  stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate --quiet

  assert_success
  assert_output <<EOS
deactivated
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(venv) \${PS1}";
EOS

  unstub pyenv-version-name
  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from current version (verbose)" {
  export PYENV_VIRTUALENV_INIT=1
  export PYENV_VIRTUALENV_VERBOSE_ACTIVATE=1

  stub pyenv-version-name "echo venv"
  stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate --verbose

  assert_success
  assert_output <<EOS
deactivated
pyenv-virtualenv: activate venv
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(venv) \${PS1}";
EOS

  unstub pyenv-version-name
  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from current version (without pyenv-virtualenv-init)" {
  export PYENV_VIRTUALENV_INIT=

  stub pyenv-version-name "echo venv"
  stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate

  assert_success
  assert_output <<EOS
deactivated
export PYENV_VERSION="venv";
export PYENV_ACTIVATE_SHELL=1;
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(venv) \${PS1}";
EOS

  unstub pyenv-version-name
  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from current version (fish)" {
  export PYENV_VIRTUALENV_INIT=1

  stub pyenv-version-name "echo venv"
  stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate

  assert_success
  assert_output <<EOS
deactivated
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing not working for fish.
EOS

  unstub pyenv-version-name
  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from current version (fish) (without pyenv-virtualenv-init)" {
  export PYENV_VIRTUALENV_INIT=

  stub pyenv-version-name "echo venv"
  stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate

  assert_success
  assert_output <<EOS
deactivated
set -gx PYENV_VERSION "venv";
set -gx PYENV_ACTIVATE_SHELL 1;
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
pyenv-virtualenv: prompt changing not working for fish.
EOS

  unstub pyenv-version-name
  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from command-line argument" {
  export PYENV_VIRTUALENV_INIT=1

  stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"

  assert_success
  assert_output <<EOS
deactivated
export PYENV_VERSION="venv27";
export PYENV_ACTIVATE_SHELL=1;
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(venv27) \${PS1}";
EOS

  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from command-line argument (without pyenv-virtualenv-init)" {
  export PYENV_VIRTUALENV_INIT=

  stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"

  assert_success
  assert_output <<EOS
deactivated
export PYENV_VERSION="venv27";
export PYENV_ACTIVATE_SHELL=1;
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(venv27) \${PS1}";
EOS

  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from command-line argument (fish)" {
  export PYENV_VIRTUALENV_INIT=1

  stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"

  assert_success
  assert_output <<EOS
deactivated
set -gx PYENV_VERSION "venv27";
set -gx PYENV_ACTIVATE_SHELL 1;
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
pyenv-virtualenv: prompt changing not working for fish.
EOS

  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "activate virtualenv from command-line argument (fish) (without pyenv-virtualenv-init)" {
  export PYENV_VIRTUALENV_INIT=

  stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"

  PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate "venv27"

  assert_success
  assert_output <<EOS
deactivated
set -gx PYENV_VERSION "venv27";
set -gx PYENV_ACTIVATE_SHELL 1;
set -gx PYENV_VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
set -gx VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
pyenv-virtualenv: prompt changing not working for fish.
EOS

  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
  unstub pyenv-sh-deactivate
}

@test "unset invokes deactivate" {
  export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
  export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
  export PYENV_ACTIVATE_SHELL=

  stub pyenv-sh-deactivate " : echo deactivated"

  run pyenv-sh-activate --unset

  assert_success
  assert_output <<EOS
deactivated
EOS

  unstub pyenv-sh-deactivate
}

@test "should fail if the version is not a virtualenv" {
  stub pyenv-virtualenv-prefix "3.3.3 : false"
  stub pyenv-version-name " : echo 3.3.3"
  stub pyenv-virtualenv-prefix "3.3.3/envs/3.3.3 : false"

  run pyenv-sh-activate "3.3.3"

  assert_failure
  assert_output <<EOS
pyenv-virtualenv: version \`3.3.3' is not a virtualenv
false
EOS

  unstub pyenv-virtualenv-prefix
  unstub pyenv-version-name
}

@test "should fail if the version is not a virtualenv (quiet)" {
  stub pyenv-virtualenv-prefix "3.3.3 : false"
  stub pyenv-version-name " : echo 3.3.3"
  stub pyenv-virtualenv-prefix "3.3.3/envs/3.3.3 : false"

  run pyenv-sh-activate --quiet "3.3.3"

  assert_failure
  assert_output <<EOS
false
EOS

  unstub pyenv-virtualenv-prefix
  unstub pyenv-version-name
}

@test "should fail if there are multiple versions" {
  stub pyenv-virtualenv-prefix "venv : true"
  stub pyenv-virtualenv-prefix "venv27 : true"

  run pyenv-sh-activate "venv" "venv27"

  assert_failure
  assert_output <<EOS
pyenv-virtualenv: cannot activate multiple versions at once: venv venv27
false
EOS

  unstub pyenv-virtualenv-prefix
}

@test "should fail if there are multiple virtualenvs (quiet)" {
  stub pyenv-virtualenv-prefix "venv : true"
  stub pyenv-virtualenv-prefix "venv27 : true"

  run pyenv-sh-activate --quiet "venv" "venv27"

  assert_failure
  assert_output <<EOS
false
EOS

  unstub pyenv-virtualenv-prefix
}

@test "should fail if the first version is not a virtualenv" {
  export PYENV_VIRTUALENV_INIT=1

  stub pyenv-virtualenv-prefix "2.7.10 : false"
  stub pyenv-version-name " : echo 2.7.10"
  stub pyenv-virtualenv-prefix "2.7.10/envs/2.7.10 : false"

  run pyenv-sh-activate "2.7.10" "venv27"

  assert_failure
  assert_output <<EOS
pyenv-virtualenv: version \`2.7.10' is not a virtualenv
false
EOS

  unstub pyenv-virtualenv-prefix
  unstub pyenv-version-name
}

@test "activate if the first virtualenv is a virtualenv" {
  export PYENV_VIRTUALENV_INIT=1

  stub pyenv-sh-deactivate "--force --quiet : echo deactivated"
  stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
  stub pyenv-virtualenv-prefix "2.7.10 : false"
  stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""

  PYENV_SHELL="bash" run pyenv-sh-activate "venv27" "2.7.10"

  assert_success
  assert_output <<EOS
deactivated
export PYENV_VERSION="venv27:2.7.10";
export PYENV_ACTIVATE_SHELL=1;
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
export _OLD_VIRTUAL_PS1="\${PS1}";
export PS1="(venv27) \${PS1}";
EOS

  unstub pyenv-sh-deactivate
  unstub pyenv-virtualenv-prefix
  unstub pyenv-prefix
}

@test "should fail if activate is invoked as a command" {
  run pyenv-activate

  assert_failure
}