351413a41e9112edd47c36e6e5b61b8ac720611c

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

Message

Merge pull request #32 from MichaelAquilina/more_tests

Add integration tests for entire plugin

Diff

 1diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..0ce348a5596ba99e8463694fd4669b932f3beb29
 4--- /dev/null
 5+++ b/tests/test_plugin.zunit
 6@@ -0,0 +1,64 @@
 7+#!/usr/bin/env zunit
 8+
 9+@setup {
10+    load =virtualenvwrapper.sh
11+
12+    if [[ ! -d "$HOME/.virtualenvs/foobar/" ]]; then
13+        echo "Creating test virtualenv"
14+        run mkvirtualenv foobar --python=python3
15+    fi
16+    unset VIRTUAL_ENV
17+    PYTHON_VERSION="$(python3 --version)"
18+}
19+
20+
21+@test 'plugin - does nothing on load if no default set' {
22+    unset AUTOSWITCH_DEFAULTENV
23+
24+    run load ../autoswitch_virtualenv.plugin.zsh
25+
26+    assert $status equals 0
27+    assert "$output" is_empty
28+}
29+
30+@test 'plugin - runs default env on load' {
31+    AUTOSWITCH_DEFAULTENV="foobar"
32+    run load ../autoswitch_virtualenv.plugin.zsh
33+
34+    assert $status equals 0
35+    assert "$output" same_as "Switching virtualenv: foobar  [$PYTHON_VERSION]"
36+}
37+
38+@test 'plugin - does nothing if switching to directory without .venv' {
39+    unset AUTOSWITCH_DEFAULTENV
40+    load ../autoswitch_virtualenv.plugin.zsh
41+
42+    TEMP_DIR="$(mktemp -d)"
43+
44+    run cd "$TEMP_DIR"
45+
46+    assert $status equals 0
47+    assert "$output" is_empty
48+}
49+
50+@test 'plugin - switches env when .venv found' {
51+    unset AUTOSWITCH_DEFAULTENV
52+    load ../autoswitch_virtualenv.plugin.zsh
53+
54+    TEMP_DIR="$(mktemp -d)"
55+    echo "foobar" > "$TEMP_DIR/.venv"
56+    chmod 600 "$TEMP_DIR/.venv"
57+
58+    run cd "$TEMP_DIR"
59+
60+    assert $status equals 0
61+    assert "$output" same_as "Switching virtualenv: foobar  [$PYTHON_VERSION]"
62+
63+    mkdir "$TEMP_DIR/foo"
64+
65+    # switches even in project subdirectories
66+    run cd "$TEMP_DIR/foo"
67+
68+    assert $status equals 0
69+    assert "$output" same_as "Switching virtualenv: foobar  [$PYTHON_VERSION]"
70+}