4bc5ffb88986b757892dc8f3e522c2f787f6a184

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

Message

Add tests for _maybeworkon

Diff

 1diff --git a/.travis.yml b/.travis.yml
 2index 38ee3ae2ca97810816711122067ae29fa2fe24ee..27c635b13f1793f6be0ed67ec2fe821fab79a738 100644
 3--- a/.travis.yml
 4+++ b/.travis.yml
 5@@ -2,6 +2,8 @@ dist: trusty
 6 sudo: required
 7 
 8 language: python
 9+python:
10+  - "3.6"
11 
12 env:
13  - ZSH_VERSION=5.3.1 URL="https://downloads.sourceforge.net/project/zsh/zsh/5.3.1/zsh-5.3.1.tar.xz"
14@@ -25,6 +27,9 @@ before_install:
15     - cd -
16     - export PATH="$LOCAL/bin:$PATH"
17 
18+install:
19+    - pip install virtualenvwrapper
20+
21 before_script:
22     - mkdir -p ~/bin
23     - curl -L "https://raw.githubusercontent.com/molovo/revolver/master/revolver" > ~/bin/revolver
24diff --git a/tests/test_maybeworkon.zunit b/tests/test_maybeworkon.zunit
25new file mode 100644
26index 0000000000000000000000000000000000000000..adc40156a65d2ee2833be91fe9d8e6af8dd0dfd8
27--- /dev/null
28+++ b/tests/test_maybeworkon.zunit
29@@ -0,0 +1,59 @@
30+#!/usr/bin/env zunit
31+
32+
33+@setup {
34+    source =virtualenvwrapper.sh
35+
36+    if [[ ! -d "$HOME/.virtualenvs/foobar/" ]]; then
37+        echo "Creating test virtualenv"
38+        run mkvirtualenv foobar --python=python3
39+    fi
40+
41+    PYTHON_VERSION="$(python3 --version 2>&1)"
42+
43+    export DISABLE_AUTOSWITCH_VENV="1"
44+    load "../autoswitch_virtualenv.plugin.zsh"
45+    TARGET="$(mktemp -d)"
46+}
47+
48+@teardown {
49+    rm -rf "$TARGET"
50+}
51+
52+
53+@test 'switches virtualenv if nothing is activated' {
54+    VIRTUAL_ENV=""
55+
56+    run _maybeworkon foobar
57+
58+    assert $state equals 0
59+    assert "$output" same_as "Switching virtualenv: foobar  [$PYTHON_VERSION]"
60+}
61+
62+@test 'switches virtualenv if current virtualenv is different' {
63+    VIRTUAL_ENV="default_venv"
64+
65+    run _maybeworkon foobar
66+
67+    assert $state equals 0
68+    assert "$output" contains "Switching virtualenv: foobar  [$PYTHON_VERSION]"
69+}
70+
71+@test 'switches virtualenv if current virtualenv is different (silent)' {
72+    VIRTUAL_ENV="default_venv"
73+    AUTOSWITCH_SILENT="1"
74+
75+    run _maybeworkon foobar
76+
77+    assert $state equals 0
78+    assert "$output" is_empty
79+}
80+
81+@test 'does not switch to already activated virtualenv' {
82+    VIRTUAL_ENV="bwaaah"
83+
84+    run _maybeworkon bwaaah
85+
86+    assert $state equals 0
87+    assert "$output" is_empty
88+}