c0dc2eab568ef1624b88b63c813cfb2963ae5fed
- Author
- Michael Aquilina <michaelaquilina@gmail.com>
- Committer
- Michael Aquilina <michaelaquilina@gmail.com>
- Date
Message
Add tests for install_requirements
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index c692d0b34a9afefe6f985914bfb361b73c4fc885..0536d8cc6d7bbbffe1a7604ab1669a3f6f733142 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -195,7 +195,7 @@ function mkvenv()
6 function install_requirements() {
7 setopt nullglob
8 if [[ -f "$PWD/setup.py" ]]; then
9- printf "Found a ${PURPLE}setup.py${NORMAL} file. Install dependencies?: "
10+ printf "Found a ${PURPLE}setup.py${NORMAL} file. Install dependencies? [y/N]: "
11 read ans
12
13 if [[ "$ans" = "y" || "$ans" = "Y" ]]; then
14diff --git a/tests/test_install_requirements.txt b/tests/test_install_requirements.txt
15new file mode 100644
16index 0000000000000000000000000000000000000000..3ce2192e67ddb2cf63bcdab3dac37c0fc26efafb
17--- /dev/null
18+++ b/tests/test_install_requirements.txt
19@@ -0,0 +1,85 @@
20+#!/usr/bin/env zunit
21+
22+@setup {
23+ export DISABLE_AUTOSWITCH_VENV="1"
24+ load "../autoswitch_virtualenv.plugin.zsh"
25+
26+ function read {
27+ eval $1=\"y\"
28+ echo y
29+ }
30+
31+ TARGET="$(mktemp -d)"
32+ cd "$TARGET"
33+}
34+
35+@teardown {
36+ rm -rf "$TARGET"
37+}
38+
39+@test 'install_requirements - does nothing if no files found' {
40+ run install_requirements
41+
42+ assert $status equals 0
43+ assert "$output" is_empty
44+}
45+
46+@test 'install_requirements - does not install with no input' {
47+ echo "django" > requirements.txt
48+ echo "pytest" > dev-requirements.txt
49+
50+ # override default mock to return nothing
51+ function read {
52+ eval $1=\"\"
53+ echo ""
54+ }
55+
56+ # mock pip to make it testable
57+ function pip {
58+ echo "pip $@"
59+ cat "$3"
60+ }
61+
62+ run install_requirements
63+
64+ assert $status equals 0
65+ assert "$lines[1]" same_as "Found a \e[35mdev-requirements.txt\e[0m file. Install? [y/N]: "
66+ assert "$lines[2]" same_as "Found a \e[35mrequirements.txt\e[0m file. Install? [y/N]: "
67+}
68+
69+@test 'install_requirements - installs *requirements.txt' {
70+ echo "django" > requirements.txt
71+ echo "pytest" > dev-requirements.txt
72+
73+ # mock pip to make it testable
74+ function pip {
75+ echo "pip $@"
76+ cat "$3"
77+ }
78+
79+ run install_requirements
80+
81+ assert $status equals 0
82+ assert "$lines[1]" same_as "Found a \e[35mdev-requirements.txt\e[0m file. Install? [y/N]: y"
83+ assert "$lines[2]" same_as "pip install -r dev-requirements.txt"
84+ assert "$lines[3]" same_as "pytest"
85+ assert "$lines[4]" same_as "Found a \e[35mrequirements.txt\e[0m file. Install? [y/N]: y"
86+ assert "$lines[5]" same_as "pip install -r requirements.txt"
87+ assert "$lines[6]" same_as "django"
88+}
89+
90+@test 'install_requirements - installs setup.py' {
91+ touch "setup.py"
92+ echo "django" > requirements.txt
93+
94+ # mock pip to make it testable
95+ function pip {
96+ echo "pip $@"
97+ }
98+
99+ run install_requirements
100+
101+ assert $status equals 0
102+ assert "$lines[1]" same_as "Found a \e[35msetup.py\e[0m file. Install dependencies? [y/N]: y"
103+ assert "$lines[2]" same_as "pip install ."
104+}