Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
romirk committed Feb 12, 2024
1 parent 4e127dc commit 2454643
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 23 deletions.
22 changes: 11 additions & 11 deletions bin/pyenv-sh-activate
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,18 @@ if [ -z "${PYENV_VIRTUALENV_DISABLE_PROMPT}" ]; then
fish )
if [ -z "${QUIET}" ]; then
cat <<EOS
functions -e _pyenv_old_prompt # remove old prompt function if exists.
# since everything is in memory, it's safe to
# remove it.
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
functions -e _pyenv_old_prompt # remove old prompt function if exists.
# since everything is in memory, it's safe to
# remove it.
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
# from python-venv
function fish_prompt
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
# read exit status
echo -n "(${venv}) " # add virtualenv to prompt
string join -- \n \$prompt # handle multiline prompts
end
# from python-venv
function fish_prompt
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
# read exit status
echo -n "(${venv}) " # add virtualenv to prompt
string join -- \n \$prompt # handle multiline prompts
end
EOS
fi
;;
Expand Down
14 changes: 7 additions & 7 deletions bin/pyenv-sh-deactivate
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ esac
case "${shell}" in
fish )
cat <<EOS
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
EOS
;;
* )
Expand Down
52 changes: 48 additions & 4 deletions test/activate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ 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.
functions -e _pyenv_old_prompt # remove old prompt function if exists.
# since everything is in memory, it's safe to
# remove it.
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
# from python-venv
function fish_prompt
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
# read exit status
echo -n "(venv) " # add virtualenv to prompt
string join -- \n \$prompt # handle multiline prompts
end
EOS

unstub pyenv-version-name
Expand All @@ -164,7 +175,18 @@ 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.
functions -e _pyenv_old_prompt # remove old prompt function if exists.
# since everything is in memory, it's safe to
# remove it.
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
# from python-venv
function fish_prompt
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
# read exit status
echo -n "(venv) " # add virtualenv to prompt
string join -- \n \$prompt # handle multiline prompts
end
EOS

unstub pyenv-version-name
Expand Down Expand Up @@ -239,7 +261,18 @@ 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.
functions -e _pyenv_old_prompt # remove old prompt function if exists.
# since everything is in memory, it's safe to
# remove it.
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
# from python-venv
function fish_prompt
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
# read exit status
echo -n "(venv27) " # add virtualenv to prompt
string join -- \n \$prompt # handle multiline prompts
end
EOS

unstub pyenv-virtualenv-prefix
Expand All @@ -263,7 +296,18 @@ 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.
functions -e _pyenv_old_prompt # remove old prompt function if exists.
# since everything is in memory, it's safe to
# remove it.
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
# from python-venv
function fish_prompt
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
# read exit status
echo -n "(venv27) " # add virtualenv to prompt
string join -- \n \$prompt # handle multiline prompts
end
EOS

unstub pyenv-virtualenv-prefix
Expand Down
13 changes: 12 additions & 1 deletion test/conda-activate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ deactivated
set -gx PYENV_VIRTUAL_ENV "${TMP}/pyenv/versions/anaconda-2.3.0";
set -gx VIRTUAL_ENV "${TMP}/pyenv/versions/anaconda-2.3.0";
set -gx CONDA_DEFAULT_ENV "root";
pyenv-virtualenv: prompt changing not working for fish.
functions -e _pyenv_old_prompt # remove old prompt function if exists.
# since everything is in memory, it's safe to
# remove it.
functions -c fish_prompt _pyenv_old_prompt # backup old prompt function
# from python-venv
function fish_prompt
set -l prompt (_pyenv_old_prompt) # call old prompt function first since it might
# read exit status
echo -n "(anaconda-2.3.0) " # add virtualenv to prompt
string join -- \n \$prompt # handle multiline prompts
end
EOS

unstub pyenv-version-name
Expand Down
7 changes: 7 additions & 0 deletions test/conda-deactivate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
set -e _OLD_VIRTUAL_PYTHONHOME;
end;
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
if functions -q deactivate;
functions -e deactivate;
end;
Expand Down
35 changes: 35 additions & 0 deletions test/deactivate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
set -e _OLD_VIRTUAL_PYTHONHOME;
end;
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
if functions -q deactivate;
functions -e deactivate;
end;
Expand All @@ -251,6 +258,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
set -e _OLD_VIRTUAL_PYTHONHOME;
end;
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
if functions -q deactivate;
functions -e deactivate;
end;
Expand Down Expand Up @@ -279,6 +293,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
set -e _OLD_VIRTUAL_PYTHONHOME;
end;
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
if functions -q deactivate;
functions -e deactivate;
end;
Expand Down Expand Up @@ -307,6 +328,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
set -e _OLD_VIRTUAL_PYTHONHOME;
end;
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
if functions -q deactivate;
functions -e deactivate;
end;
Expand All @@ -333,6 +361,13 @@ if [ -n "\$_OLD_VIRTUAL_PYTHONHOME" ];
set -gx PYTHONHOME "\$_OLD_VIRTUAL_PYTHONHOME";
set -e _OLD_VIRTUAL_PYTHONHOME;
end;
# check if old prompt function exists
if functions -q _pyenv_old_prompt
# remove old prompt function if exists.
functions -e fish_prompt
functions -c _pyenv_old_prompt fish_prompt
functions -e _pyenv_old_prompt
end
if functions -q deactivate;
functions -e deactivate;
end;
Expand Down

0 comments on commit 2454643

Please sign in to comment.