forked from cernopendata/opendata.cern.ch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests.sh
executable file
·88 lines (78 loc) · 2.88 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
#!/usr/bin/env bash
#
# This file is part of CERN Open Data Portal.
# Copyright (C) 2015, 2016, 2017, 2018 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 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:
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
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
# do we need to continue?
if [[ "$@" = *"--check-fixtures-only"* ]]; then
exit 0
fi
# check source code style:
pycodestyle cernopendata
pydocstyle cernopendata
isort -rc -c -df **/*.py
check-manifest --ignore ".travis-*"
# check our test suite:
python setup.py test