-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestinit.sh
87 lines (76 loc) · 1.86 KB
/
testinit.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
abspath() {
python -c "import os; print os.path.realpath('${1}')"
}
BASEDIR=$(abspath $(dirname $0))
PIPELINEDIR="${BASEDIR}/../zlp-script"
STDERRFILE=/tmp/test.stderr
STDOUTFILE=/tmp/test.stdout
setup_environment() {
export PYTHONPATH=${BASEDIR}:${BASEDIR}/testdata:${PIPELINEDIR}/scripts:${PYTHONPATH}
OUTFILE=$(find ${BASEDIR}/testdata -name 'output.fits')
if [ ! -z ${OUTFILE} ]; then
if [ -f ${OUTFILE} ]; then
rm ${OUTFILE}
fi
fi
}
run_test() {
local readonly filelist_name=$(create_filelist)
python ./bin/ZLP_create_outfile.py \
--outdir ${BASEDIR}/testdata \
${filelist_name} \
--apsize 2 \
--nproc 1
}
assert_output() {
assert_npts_correct
assert_tmid_sorted
}
assert_tmid_sorted() {
python - <<EOF
import fitsio
import numpy as np
with fitsio.FITS("testdata/output.fits") as infile:
imagelist = infile['imagelist'].read()
tmid = imagelist['TMID']
assert (tmid == np.sort(tmid)).all(), tmid
EOF
}
assert_npts_correct() {
python - <<EOF
import fitsio
with fitsio.FITS("testdata/output.fits") as infile:
catalogue = infile['catalogue']
keys = catalogue.get_colnames()
value_ind = keys.index('NPTS')
nrows = catalogue.get_nrows()
flux = infile['flux'].read()
assert flux.shape[0] == nrows
for (lc, cat_row) in zip(flux, catalogue):
value = cat_row[value_ind]
target = lc[lc == lc].size
assert value == target, (value, target)
EOF
}
check_for_failure() {
if [[ "$?" == "0" ]]; then
echo "Pass"
else
echo "Fail"
cat ${STDERRFILE}
exit 1
fi
}
main() {
(cd ${BASEDIR}
setup_environment
echo -n "Running test... "
set +e
run_test 2>${STDERRFILE} >${STDOUTFILE}
check_for_failure
set -e
echo -n "Running test... "
assert_output
check_for_failure
)
}