f2893492002fdeb3cf7c6b7a09972f62b784bb39

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
Michael Aquilina <michaelaquilina@gmail.com>
Date

Message

Display message when a python project is detected

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index de99fce853351be4e2ee39cca11fbc14547272e8..51d49c8d7bbeb8a2eb57cd56f328f6ab5c095da8 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -79,11 +79,6 @@ function _check_venv_path()
 6 # Automatically switch virtualenv when .venv file detected
 7 function check_venv()
 8 {
 9-    if [[ -f "requirements.txt" ]] && [[ ! -f ".venv" ]]; then
10-        printf "Python project detected. "
11-        printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
12-    fi
13-
14     SWITCH_TO=""
15 
16     # Get the .venv file, scanning parent directories
17@@ -110,6 +105,9 @@ function check_venv()
18         else
19             SWITCH_TO="$(<"$venv_path")"
20         fi
21+    elif [[ -f "$PWD/requirements.txt" ]]; then
22+        printf "Python project detected. "
23+        printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
24     fi
25 
26     if [[ -n "$SWITCH_TO" ]]; then
27diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
28index 79a858695882a6742fe28a3afecf1c41731ababa..cab07d2dd4be4a56c416c2677685454327ea6eaf 100644
29--- a/tests/test_check_venv.zunit
30+++ b/tests/test_check_venv.zunit
31@@ -25,6 +25,16 @@
32     rm -rf Pipfile
33 }
34 
35+@test 'check_venv - Displays message on project detection' {
36+    PWD="$TARGET"
37+    touch "$TARGET/requirements.txt"
38+
39+    run check_venv
40+
41+    assert $status equals 0
42+    assert "$output" same_as "Python project detected. Run \e[35mmkvenv\e[0m to setup autoswitching"
43+}
44+
45 
46 @test 'check_venv - Security warning for weak writeable by group permissions' {
47     PWD="$TARGET"