Commit d502808c authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

updated README to be a 'tutorial' for writing cdo operator tests

parent 69000e84
Test the cdo-operators
======================
To test the cdo operators use:
make
or
make test
or
./test_operators
The cdo operators are tested with python-unittests using the python-bindings for cdo.
The python-bindings are located at cdo/contrib/python/cdo.py.
The use is roughly exlained at:
https://code.mpimet.mpg.de/projects/cdo/wiki/Cdo%7Brbpy%7D
TODO: Provide a more thorough documentation/tutorial.
The documentation of the python unittest framework can be found at:
http://docs.python.org/library/unittest.html
The tests are grouped by operator. An operator is tested with the help of its file test_operator.py, which can comprise several tests.
#=======================================================#
# TUTORIAL AND GUIDE FOR WRITING CDO TESTS! #
#=======================================================#
How to write Tests for CDO:
Important variables needed for test coverage checks:
- STATS: contains simple operators. Needs to be inside a test. Otherwise the test is not recognized
- OPERTYPES: contains a prefix for operators e.g: monmean -> mon is in OPERTYPES and mean is in STATS, muss eine string variable sein
- FORMATS: cdo format string which we can use to know what module is tested for which formats
General Variables:
- RSTAT: used to hold the the test status
General Structure/Example:
#autoconf will replace this with a fitting bash premable
#! @BASH@
#needed by autoconf to know how many tests are to be expected
echo 1..8 # Number of tests to be executed.
#
#automatically sets the paths if we are inside the test folder
#for make check inside the top build folder CDO and DATAPATH are set throuch ./configure
#here we also enable us to use debug variables when executing tests in the test folder
#e.g: CDO_DEBUG="-d" ./TestFileName.test <NTEST> executes a test with given testn with debug option "-d"
test -n "$CDO" || CDO="@abs_top_builddir@/src/cdo $CDO_DEBUG"
test -n "$DATAPATH" || DATAPATH="@abs_top_srcdir@/test/data/"
for FORMAT in $FORMATS; do
for TYPE in $OPERTYPES ; do
for OPER in $STATS; do
#this is if enables us to rerun a single test within the test folder
#./TestFileName.test <NTEST> runs the test
if [ -z "$1" ] || [ $NTEST == $1 ]; then
#do stuff
#check stuff
# autoconf needs the ok/not ok to know what the result of the test was
test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
test $RSTAT -eq 0 || echo "not ok $NTEST - $CDOTEST"
# there are options for SKIPING a test instead of ok/not ok example follows:
test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST # SKIP POSIX threads not enabled"
fi
done
done
done
#=======================================================#
# Complete example for operator monstat #
#=======================================================#
#! @BASH@
echo 1..4 # Number of tests to be executed.
#
test -n "$CDO" || CDO="@abs_top_builddir@/src/cdo $CDO_DEBUG"
test -n "$DATAPATH" || DATAPATH="@abs_top_srcdir@/test/data/"
#
IFILE1=$DATAPATH/ts_1d_1year
IFILE2=$DATAPATH/ts_mm_1991
#
FORMAT="-f srv -b 32"
STATS="monadd monsub monmul mondiv"
#
NTEST=1
#
for STAT in $STATS; do
if [ -z "$1" ] || [ $NTEST == $1 ]; then
RSTAT=0
RFILE=$DATAPATH/${STAT}_ref
CDOTEST="$STAT"
echo "Running test: $NTEST - $CDOTEST"
OFILE=${STAT}_res
CDOCOMMAND="$CDO $FORMAT ${STAT} $IFILE1 $IFILE2 $OFILE"
$CDOCOMMAND
test $? -eq 0 || let RSTAT+=1
$CDO diff $OFILE $RFILE
test $? -eq 0 || let RSTAT+=1
rm -f $OFILE
test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
test $RSTAT -eq 0 || echo "not ok $NTEST - $CDOTEST"
let NTEST+=1
done
#
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment