forked from cernopendata/opendata.cern.ch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-tests.sh
executable file
·144 lines (124 loc) · 3.96 KB
/
run-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
#!/usr/bin/env bash
#
# This file is part of CERN Open Data Portal.
# Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020 CERN.
#
# CERN Open Data Portal is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# CERN Open Data Portal is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CERN Open Data Portal; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
# quit on errors and potentially unbound symbols:
set -o errexit
set -o nounset
check_script () {
shellcheck run-tests.sh
}
check_black () {
black --check .
}
check_fixtures () {
# check for possibly incorrect JSON files:
find cernopendata/modules/fixtures/data/ -name "*.json" -exec jsonlint -q {} \;
# check record ID uniqueness:
dupes=$(jq '.[].recid' cernopendata/modules/fixtures/data/records/*.json | sort | uniq -d)
if [ "x${dupes}" != "x" ]; then
echo "[ERROR] Found duplicate record IDs:"
echo "${dupes}"
exit 1
fi
# check DOI uniqueness:
dupes=$(jq '.[].doi' cernopendata/modules/fixtures/data/records/*.json | sort | grep -v null | uniq -d)
if [ "x${dupes}" != "x" ]; then
echo "[ERROR] Found duplicate record DOIs:"
echo "${dupes}"
exit 1
fi
# check docs slug uniqueness:
# shellcheck disable=SC2044
dupes=$(for file in $(find cernopendata/modules/fixtures/data/docs -name "*.json"); do jq '.[].slug' "$file"; done | sort | grep -v null | uniq -d)
if [ "x${dupes}" != "x" ]; then
echo "[ERROR] Found duplicate docs slugs:"
echo "${dupes}"
exit 1
fi
# check trailing whitespace:
whitespace_found_p=0
for file in $(git ls-files | grep -E '.(py|html|css|json|md|sh|txt|yml)$'); do
if grep -q ' $' "$file"; then
whitespace_found_p=1
echo "[ERROR] Found trailing whitespace in ${file}."
fi
done
if [ "${whitespace_found_p}" != "0" ]; then
exit 1
fi
# check for empty secondary type in fixtures
# shellcheck disable=SC2044
for file in $(find cernopendata/modules/fixtures/data/{records,docs}/ -name "*.json"); do
secondaries=$(jq '.[].type.secondary' "$file" -c | sort | uniq)
if echo "$secondaries" | grep -q -e '\[\]' -e "null"; then
echo "[Warning] empty type.secondary field in $file"
fi
done
}
check_pycodestyle () {
pycodestyle --max-line-length=120 cernopendata
}
check_pydocstyle () {
pydocstyle cernopendata
}
check_isort () {
isort -rc -c -df --profile black -- **/*.py
}
check_manifest () {
check-manifest --ignore "*.crt,*.key,.htpasswd"
}
check_docker_build () {
docker-compose build
}
check_pytest () {
python setup.py test
}
check_all () {
check_script
check_fixtures
check_pycodestyle
check_black
check_pydocstyle
check_isort
check_manifest
check_docker_build
check_pytest
}
if [ $# -eq 0 ]; then
check_all
exit 0
fi
for arg in "$@"
do
case $arg in
--check-shellscript) check_script;;
--check-fixtures) check_fixtures;;
--check-pycodestyle) check_pycodestyle;;
--check-pydocstyle) check_pydocstyle;;
--check-isort) check_isort;;
--check-manifest) check_manifest;;
--check-docker-build) check_docker_build;;
--check-pytest) check_pytest;;
*)
esac
done