Skip to content

Commit 29e9698

Browse files
r5dgaborbernat
andauthored
activate.fish: update fish major version check (#2891)
Co-authored-by: Bernát Gábor <[email protected]>
1 parent 07e6110 commit 29e9698

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

src/virtualenv/activation/fish/activate.fish

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function deactivate -d 'Exit virtualenv mode and return to the normal environmen
1818
# reset old environment variables
1919
if test -n "$_OLD_VIRTUAL_PATH"
2020
# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
21-
if test (echo $FISH_VERSION | head -c 1) -lt 3
21+
if test (string sub -s 1 -l 1 $FISH_VERSION) -lt 3
2222
set -gx PATH (_fishify_path "$_OLD_VIRTUAL_PATH")
2323
else
2424
set -gx PATH $_OLD_VIRTUAL_PATH
@@ -61,7 +61,7 @@ deactivate nondestructive
6161
set -gx VIRTUAL_ENV __VIRTUAL_ENV__
6262

6363
# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
64-
if test (echo $FISH_VERSION | head -c 1) -lt 3
64+
if test (string sub -s 1 -l 1 $FISH_VERSION) -lt 3
6565
set -gx _OLD_VIRTUAL_PATH (_bashify_path $PATH)
6666
else
6767
set -gx _OLD_VIRTUAL_PATH $PATH

tests/unit/activation/test_fish.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import annotations
22

3+
import os
4+
import sys
5+
36
import pytest
47

58
from virtualenv.activation import FishActivator
@@ -20,4 +23,54 @@ def __init__(self, session) -> None:
2023
def print_prompt(self):
2124
return "fish_prompt"
2225

26+
def _get_test_lines(self, activate_script):
27+
return [
28+
self.print_python_exe(),
29+
self.print_os_env_var("VIRTUAL_ENV"),
30+
self.print_os_env_var("VIRTUAL_ENV_PROMPT"),
31+
self.print_os_env_var("PATH"),
32+
self.activate_call(activate_script),
33+
self.print_python_exe(),
34+
self.print_os_env_var("VIRTUAL_ENV"),
35+
self.print_os_env_var("VIRTUAL_ENV_PROMPT"),
36+
self.print_os_env_var("PATH"),
37+
self.print_prompt(),
38+
# \\ loads documentation from the virtualenv site packages
39+
self.pydoc_call,
40+
self.deactivate,
41+
self.print_python_exe(),
42+
self.print_os_env_var("VIRTUAL_ENV"),
43+
self.print_os_env_var("VIRTUAL_ENV_PROMPT"),
44+
self.print_os_env_var("PATH"),
45+
"", # just finish with an empty new line
46+
]
47+
48+
def assert_output(self, out, raw, _):
49+
# pre-activation
50+
assert out[0], raw
51+
assert out[1] == "None", raw
52+
assert out[2] == "None", raw
53+
# post-activation
54+
expected = self._creator.exe.parent / os.path.basename(sys.executable)
55+
assert self.norm_path(out[4]) == self.norm_path(expected), raw
56+
assert self.norm_path(out[5]) == self.norm_path(self._creator.dest).replace("\\\\", "\\"), raw
57+
assert out[6] == self._creator.env_name
58+
# Some attempts to test the prompt output print more than 1 line.
59+
# So we need to check if the prompt exists on any of them.
60+
prompt_text = f"({self._creator.env_name}) "
61+
assert any(prompt_text in line for line in out[7:-5]), raw
62+
63+
assert out[-5] == "wrote pydoc_test.html", raw
64+
content = tmp_path / "pydoc_test.html"
65+
assert content.exists(), raw
66+
# post deactivation, same as before
67+
assert out[-4] == out[0], raw
68+
assert out[-3] == "None", raw
69+
assert out[-2] == "None", raw
70+
71+
# Check that the PATH is restored
72+
assert out[3] == out[13], raw
73+
# Check that PATH changed after activation
74+
assert out[3] != out[8], raw
75+
2376
activation_tester(Fish)

0 commit comments

Comments
 (0)