0adff8e8cb486a6984c44111e21b656d2098304b

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

Message

Add tests for rmvenv

Diff

 1diff --git a/tests/test_rmvenv.zunit b/tests/test_rmvenv.zunit
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..3be698bb120cbba4a129c6627c6ab8c726eb0208
 4--- /dev/null
 5+++ b/tests/test_rmvenv.zunit
 6@@ -0,0 +1,49 @@
 7+#!/usr/bin/env zunit
 8+
 9+@setup {
10+    source =virtualenvwrapper.sh
11+
12+    export DISABLE_AUTOSWITCH_VENV="1"
13+    load "../autoswitch_virtualenv.plugin.zsh"
14+    TARGET="$(mktemp -d)"
15+    cd "$TARGET"
16+}
17+
18+@teardown {
19+    rm -rf "$TARGET"
20+}
21+
22+
23+@test 'rmvenv - shows warning if no .venv present' {
24+    run rmvenv
25+
26+    assert $state equals 0
27+    assert "$output" same_as "No .venv file in the current directory!"
28+}
29+
30+
31+@test 'rmvenv - removes .venv if present' {
32+    # lightweight simulation of creating a virtualenv
33+    mkdir -p "$HOME/.virtualenvs/12345"
34+
35+    echo "12345" > .venv
36+
37+    run rmvenv
38+
39+    assert $state equals 0
40+    assert "$output" same_as "Removing 12345..."
41+    test ! -f .venv
42+    test ! -d "$HOME/.virtualenvs/12345"
43+}
44+
45+@test 'rmvenv - removes .venv and deactivates if currently active' {
46+    test_venv="$(basename $PWD)"
47+    run mkvenv
48+
49+    run rmvenv
50+
51+    assert $state equals 0
52+    assert "$output" same_as "Removing $test_venv..."
53+    test ! -f .venv
54+    test ! -d "$HOME/.virtualenvs/$test_venv"
55+}