-
Notifications
You must be signed in to change notification settings - Fork 14
/
launch_tests.sh
executable file
·165 lines (116 loc) · 4.59 KB
/
launch_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
# django-check-seo super test-launching script
#
# requires python3-venv & python2 virtualenv
#
# Usage:
# ./launch_tests.sh activate venv2 & venv3 (or create them & activate them),
# launch tests, deactivate venv2 & venv3
# ./launch_tests.sh 2 activate venv2 (or create it & activate it),
# launch tests, deactivate venv2
# ./launch_tests.sh 3 activate venv3 (or create it & activate it),
# launch tests, deactivate venv3
# ./launch_tests.sh remove remove folders "venv2" & "venv3"
# ./launch_tests.sh help display this text
function remove {
if [[ -d "venv2" ]]; then
echo -e "\e[1;32m✅ test venv2 found\e[0m"
echo -e "\e[2m➡ removing venv2...\e[0m"
rm -r venv2
echo -e "\e[1;32m✅ test venv2 removed successfully\e[0m"
else
echo -e "\e[1;31m❌ test venv2 not found\e[0m"
echo -e "\e[1;32m✅ nothing to remove\e[0m"
fi
if [[ -d "venv3" ]]; then
echo -e "\e[1;32m✅ test venv3 found\e[0m"
echo -e "\e[2m➡ removing venv3...\e[0m"
rm -r venv3
echo -e "\e[1;32m✅ test venv3 removed successfully\e[0m"
else
echo -e "\e[1;31m❌ test venv3 not found\e[0m"
echo -e "\e[1;32m✅ nothing to remove\e[0m"
fi
}
function display_help {
echo -e "django-check-seo super test-launching script"
echo
echo -e "Usage:"
echo -e " ./launch_tests.sh \e[2mactivate venv2 & venv3 (or create them & activate them), launch tests, deactivate venv2 & venv3\e[0m"
echo -e " ./launch_tests.sh 2 \e[2mactivate venv2 (or create it & activate it), launch tests, deactivate venv2\e[0m"
echo -e " ./launch_tests.sh 3 \e[2mactivate venv3 (or create it & activate it), launch tests, deactivate venv3\e[0m"
echo -e " ./launch_tests.sh remove \e[2mremove folders \"venv2\" & \"venv3\"\e[0m"
echo -e " ./launch_tests.sh help \e[2mdisplay this text\e[0m"
}
function create_and_launch_venv2 {
if [[ -d "venv2" ]]; then
launch_venv2_tests
else
create_venv2
fi
}
function create_and_launch_venv3 {
if [[ -d "venv3" ]]; then
launch_venv3_tests
else
create_venv3
fi
}
function launch_venv2_tests {
echo -e "\e[1;32m✅ test venv2 found\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv2/bin/activate && python2 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate
}
function launch_venv3_tests {
echo -e "\e[1;32m✅ test venv3 found\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv3/bin/activate && python3 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate
}
function create_venv2 {
echo -e "\e[1;31m❌ test venv2 not found\e[0m"
echo -e "\e[2m➡ creating venv2...\e[0m"
python2 -m virtualenv -p python2.7 venv2 1>/dev/null && . venv2/bin/activate && python2 -m pip install "django<3" bs4 lxml "easy-thumbnails==2.3" "djangocms-page-meta==0.8.5" requests pytest pytest-django pytest-cov 1>/dev/null && deactivate
echo -e "\e[1;32m✅ venv2 created successfully\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv2/bin/activate && python2 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate
}
function create_venv3 {
echo -e "\e[1;31m❌ test venv3 not found\e[0m"
echo -e "\e[2m➡ creating venv3...\e[0m"
python3 -m venv venv3 1>/dev/null && . venv3/bin/activate && python3 -m pip install django bs4 lxml djangocms-page-meta requests pytest pytest-django pytest-cov 1>/dev/null && deactivate
echo -e "\e[1;32m✅ venv3 created successfully\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv3/bin/activate && python3 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate
}
if [[ $1 == "remove" ]]; then
remove
exit 1
elif [[ $1 == "help" ]]; then
display_help
exit 1
elif [[ $1 == "2" ]]; then
create_and_launch_venv2
exit $?
elif [[ $1 == "3" ]]; then
create_and_launch_venv3
exit $?
elif [[ "$#" -gt 0 ]]; then
if [[ $1 != ".pre-commit-config.yaml" || $2 != "launch_tests.sh" ]]
then
echo "Wrong args:"
echo $@
echo ""
display_help
exit 1
fi
fi
create_and_launch_venv2
exit1=$?
create_and_launch_venv3
exit2=$?
if [ "$exit1" -eq "0" ] && [ "$exit2" -eq "0" ]
then
exit 0
else
exit 1
fi