11from __future__ import annotations
22
3+ import os
4+ import sys
5+
36import pytest
47
58from 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