diff --git a/pytest.ini b/pytest.ini index bba118e895f6302c543b733895544aba3bc2b2dc..59e6ffee636db88150ed955890dc5eead21371cc 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,3 @@ -# remove tests, you don't want to run not here, but in tsuite.sh +# remove tests, you don't want to run not here, but in test2run.inc [pytest] python_functions=test_\* diff --git a/test2run.inc b/test2run.inc new file mode 100644 index 0000000000000000000000000000000000000000..408c987c492f0b0be71eab9fbe99e55339f12542 --- /dev/null +++ b/test2run.inc @@ -0,0 +1,16 @@ +# (Un-)Comment lines to allow only specific tests to be run + +# all tests +export RUN_THESE="test_\*" + +#export RUN_THESE="${RUN_THESE} test_cd_and_absorb_aug" +# just the cases meant for libtorbeamB.so +#export RUN_THESE="${RUN_THESE} test_cases_B" +# just reflectometry stuff +#export RUN_THESE="${RUN_THESE} test_refllib" +#export RUN_THESE="${RUN_THESE} test_rtlib" +#export RUN_THESE="${RUN_THESE} test_random_inputs_farina" +#export RUN_THESE="${RUN_THESE} test_random_inputs_westerhof" +#export RUN_THESE="${RUN_THESE} test_iter_rngfreq" +# NAG-dependent tests +#export RUN_THESE="test_nag_relativistic" diff --git a/test_ctbm.py b/test_ctbm.py index fb1479143a4806930777865582e34c0955b112c6..e98fdfd4df49ab5925e7370eefed3cfbcff48bf3 100755 --- a/test_ctbm.py +++ b/test_ctbm.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +'''Suite of tests to be run under python2/3+hypothesis +''' import os import sys @@ -13,21 +15,20 @@ try: from hypothesis import given, strategies as st from hypothesis import settings #embed() -except Exception: - print ("Need module hypothesis for running unittests") - print ("Exiting now.") +except ImportError as err: + print("Need module hypothesis for running unittests") + print(err) + print("Exiting now.") sys.exit(1) -basepath = '../libtorbeam/tests/' +BASEPATH = '../libtorbeam/tests/' -def decode_libdir(libdir): - res = '../'+libdir.replace('^', '/')[3:] if libdir.startswith('^^^') else libdir.replace('^', '/') +def decode_libdir(ldir): + ''' Backconvert encoded pathspec into proper string + ''' + res = '../'+ldir.replace('^', '/')[3:] if ldir.startswith('^^^') else ldir.replace('^', '/') return res -#print ('================================') -#print (settings.verbosity.name) -#print ('================================') - @pytest.hookimpl(tryfirst=True, hookwrapper=True) def pytest_runtest_makereport(item, call): # execute all other hooks to obtain the report object @@ -37,18 +38,18 @@ def pytest_runtest_makereport(item, call): # we only look at actual failing test calls, not setup/teardown if rep.when == "call" and rep.failed: mode = "a" if os.path.exists("failures") else "w" - with open("failures", mode) as f: + with open("failures", mode) as ffile: # let's also access a fixture for the fun of it if "tmpdir" in item.fixturenames: extra = " (%s)" % item.funcargs["tmpdir"] else: extra = "" - f.write(rep.nodeid + extra + "\n") + ffile.write(rep.nodeid + extra + "\n") @given(c=st.integers(min_value=0, max_value=1), a=st.integers(min_value=0, max_value=1)) def test_cd_and_absorb_aug(c, a, libdir): - path = basepath + 'test_rem' + path = BASEPATH + 'test_rem' m, n, eqdata = ctbm.readTopfile3(path+'/topfile') k, l, prdata = ctbm.readPrdata(path+'/ne.dat', path+'/Te.dat') intinbeam, dblinbeam = ctbm.readInbeam(path+'/inbeam.dat') @@ -59,40 +60,31 @@ def test_cd_and_absorb_aug(c, a, libdir): # randomize absorption method and profile calculation intinbeam[11] = c intinbeam[13] = a -# rhoresult, t1data, t1tdata, t2data, t2n_data, icnt, ibgout, nv, volprof = \ -# ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, -# mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) + result = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, - mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) + mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) rhoresult = result[0] assert rhoresult[19] == 0 sys.stdout.write('.') sys.stdout.flush() assert np.abs(rhoresult[0]-0.6524) < 1e-3 -@pytest.mark.xfail('NAG_KUSARI_FILE' not in os.environ.keys(), reason="No NAG licence") @given(path=st.sampled_from(['test_X3'])) def test_nag_relativistic(path, libdir): - try: - checkthis = os.environ['NAG_KUSARI_FILE'] + "" - checkthis.replace('.', '-') - except Exception: - pytest.skip("No NAG license, cannot pass this test, skipping it.") - return - path = basepath + path + path = BASEPATH + path m, n, eqdata = ctbm.readTopfile3(path+'/topfile') k, l, prdata = ctbm.readPrdata(path+'/ne.dat', path+'/Te.dat') intinbeam, dblinbeam = ctbm.readInbeam(path+'/inbeam.dat') intinbeam[6] = intinbeam[6] % 10 intinbeam[8] = 1 # no extra output result = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, - mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) + mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) rhoresult = result[0] assert rhoresult[19] == 0 assert np.abs(rhoresult[0] - 0.161) < 1e-3 -@given(path=st.sampled_from([basepath + 'test_rem', 'tcvdata/', 'augdata/', \ - basepath + 'test_rtprofiles'])) +@given(path=st.sampled_from([BASEPATH + 'test_rem', 'tcvdata/', 'augdata/', \ + BASEPATH + 'test_rtprofiles'])) def test_cases_B(path, libdir): m, n, eqdata = ctbm.readTopfile3(path+'/topfile') k, l, prdata = ctbm.readPrdata(path+'/ne.dat', path+'/Te.dat') @@ -106,11 +98,11 @@ def test_cases_B(path, libdir): # ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, # mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) result = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, - mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) + mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) rhoresult = result[0] assert rhoresult[19] == 0 if settings.verbosity.name == "verbose": - print (path, rhoresult[0], '(0.32 < x < 0.68)\n') + print(path, rhoresult[0], '(0.32 < x < 0.68)\n') else: sys.stdout.write('.') sys.stdout.flush() @@ -137,7 +129,7 @@ def test_refllib(xf, libdir): 0.70989436, 0.67004873]) #myspline = interp1d(xxf, yyf) # directory for base-cas - path = basepath + 'test_aug_refl/' + path = BASEPATH + 'test_aug_refl/' m, n, eqdata = ctbm.readTopfile3(path+'topfile') k, l, prdata = ctbm.readPrdata(path+'ne.dat', path+'/Te.dat') intinbeam, dblinbeam = ctbm.readInbeam(path+'/inbeam.dat') @@ -148,13 +140,13 @@ def test_refllib(xf, libdir): mode = ctbm.TBM_MODE_REFL | ctbm.TBM_MODE_NORMAL #rhoresult, t1data, t1tdata, t2data, t2n_data, icnt, ibgout, nv, volprof, reflout = \ result = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, - mode=mode, libdir=decode_libdir(libdir)) + mode=mode, libdir=decode_libdir(libdir)) reflout = result[9] assert result[0][19] == 3 rhoturn = reflout[0, np.argmin(reflout[2, :])] if settings.verbosity.name == "verbose": - print ("xf:", xf/1e9, "e9 tgtrho:", target_rho, " got: ", rhoturn, " delta: ", \ - np.abs(rhoturn - target_rho) ) + print("xf:", xf/1e9, "e9 tgtrho:", target_rho, " got: ", rhoturn, " delta: ", \ + np.abs(rhoturn - target_rho)) else: sys.stdout.write('.') sys.stdout.flush() @@ -163,7 +155,7 @@ def test_refllib(xf, libdir): @given(xf=st.floats(min_value=130e9, max_value=145e9)) def test_rtlib(xf, libdir): - path = basepath + 'test_rem/' + path = BASEPATH + 'test_rem/' m, n, eqdata = ctbm.readTopfile3(path+'topfile') k, l, prdata = ctbm.readPrdata(path+'ne.dat', path+'/Te.dat') intinbeam, dblinbeam = ctbm.readInbeam(path+'/inbeam.dat') @@ -171,16 +163,16 @@ def test_rtlib(xf, libdir): intinbeam[8] = 1 #rhonormal, t1data, t1tdata, t2data, t2n_data, icnt, ibgout, nv, volprof =\ result = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, - mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) + mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) rhonormal = result[0] assert rhonormal[19] == 0 - + rhoresult = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, mode=ctbm.TBM_MODE_RT, libdir=decode_libdir(libdir)) assert rhoresult[19] == 0 if settings.verbosity.name == "verbose": - print ("chosen freq: ", dblinbeam[0], " rho_rt: ", rhoresult[0], " rho_norm: ",\ - rhonormal[0], " delta: ", np.abs(rhoresult[0]-rhonormal[0]) ) + print("chosen freq: ", dblinbeam[0], " rho_rt: ", rhoresult[0], " rho_norm: ",\ + rhonormal[0], " delta: ", np.abs(rhoresult[0]-rhonormal[0])) else: sys.stdout.write('.') sys.stdout.flush() @@ -189,7 +181,7 @@ def test_rtlib(xf, libdir): @given(xf=st.floats(min_value=165e9, max_value=180e9)) def test_iter_rngfreq(xf, libdir): - path = basepath + 'test_iter/' + path = BASEPATH + 'test_iter/' m, n, eqdata = ctbm.readTopfile3(path+'topfile') k, l, prdata = ctbm.readPrdata(path+'ne.dat', path+'/Te.dat') intinbeam, dblinbeam = ctbm.readInbeam(path+'/inbeam.dat') @@ -197,11 +189,12 @@ def test_iter_rngfreq(xf, libdir): intinbeam[8] = 1 #rhonormal, t1data, t1tdata, t2data, t2n_data, icnt, ibgout, nv, volprof = \ result = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, - mode=ctbm.TBM_MODE_NORMAL | ctbm.TBM_MODE_ITER, libdir=decode_libdir(libdir)) + mode=ctbm.TBM_MODE_NORMAL | ctbm.TBM_MODE_ITER, + libdir=decode_libdir(libdir)) rhonormal = result[0] assert rhonormal[19] == 0 if settings.verbosity.name == 'verbose': - print ("chosen freq: ", dblinbeam[0], " rho_norm: ", rhonormal[0]) + print("chosen freq: ", dblinbeam[0], " rho_norm: ", rhonormal[0]) else: sys.stdout.write('.') sys.stdout.flush() @@ -209,7 +202,7 @@ def test_iter_rngfreq(xf, libdir): assert np.abs(rhonormal[0]-0.5) < 5e-1 def random_inputs(xf, ints, dbls, cd, harm, int11, tmpdir, libdir): - path = basepath + 'test_rem/' + path = BASEPATH + 'test_rem/' m, n, eqdata = ctbm.readTopfile3(path+'topfile') k, l, prdata = ctbm.readPrdata(path+'ne.dat', path+'/Te.dat') intinbeam, dblinbeam = ctbm.readInbeam(path+'inbeam.dat') @@ -237,12 +230,12 @@ def random_inputs(xf, ints, dbls, cd, harm, int11, tmpdir, libdir): dblinbeam[23] = dbls[4] dblinbeam[34] = 1 + dbls[5] # fix invalid parameter combination with NAG-using relativistic absorption - intinbeam[10] = intinbeam[10] if intinbeam[9] == 0 else max(3, intinbeam[9]) + intinbeam[10] = intinbeam[10] if intinbeam[9] == 0 else max(3, intinbeam[9]) result = ctbm.call_torbeam(intinbeam, dblinbeam, m, n, eqdata, k, l, prdata, - mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) + mode=ctbm.TBM_MODE_NORMAL, libdir=decode_libdir(libdir)) rhoresult = result[0] if settings.verbosity.name == "verbose": - print ('--------- ', dblinbeam[0], intinbeam[4], intinbeam[10], '=>', rhoresult[0]) + print('--------- ', dblinbeam[0], intinbeam[4], intinbeam[10], '=>', rhoresult[0]) else: sys.stdout.write('.') sys.stdout.flush() @@ -253,33 +246,12 @@ def random_inputs(xf, ints, dbls, cd, harm, int11, tmpdir, libdir): return rhoresult[0] -# @given(xf=st.floats(min_value=130e9, max_value=145e9), -# ints=st.lists(elements=st.integers(min_value=0, max_value=1), max_size=4), -# cd=st.integers(min_value=0, max_value=3), -# harm=st.integers(min_value=1, max_value=5), -# dbls=st.lists(st.floats(min_value=0.01, max_value=1.0), max_size=6)) -# def disabled_test_random_inputs_farina(tmpdir, xf, ints, dbls, cd, harm): -# result = random_inputs(xf, ints, dbls, cd, harm, 1, str(tmpdir)) - -# assert np.abs(result-0.5) <= 0.5 - -@pytest.mark.xfail('NAG_KUSARI_FILE' not in os.environ.keys(), reason="No NAG licence") @given(xf=st.floats(min_value=130e9, max_value=145e9), ints=st.lists(elements=st.integers(min_value=0, max_value=1), max_size=4), cd=st.integers(min_value=0, max_value=3), harm=st.integers(min_value=1, max_value=5), dbls=st.lists(st.floats(min_value=0.01, max_value=1.0), max_size=6)) def test_random_inputs_westerhof(xf, ints, dbls, cd, harm, libdir): - try: - checkthis = os.environ['NAG_KUSARI_FILE'] + "" - checkthis.replace('.', '-') - except Exception: - pytest.skip("No NAG license, cannot pass this test, skipping it.") - return result = random_inputs(xf, ints, dbls, cd, harm, 0, 'tmpdir', libdir) assert np.abs(result-0.5) <= 0.5 - -#print (("call me using test.py or tsuite.sh !!")) - -#test_nag_relativistic() diff --git a/tsuite.sh b/tsuite.sh index 9e8140f2a3c1ca90df1c1aa62fd4f9e3c54eb453..9eea13ea8f69425c57e942cd7ae399807ab2752b 100755 --- a/tsuite.sh +++ b/tsuite.sh @@ -13,64 +13,96 @@ function contains() { return 1 } -# (Un-)Comment lines to allow only specific tests to be run +# include tests to be run export RUN_THESE="" -export RUN_THESE="test_\*" -#export RUN_THESE="${RUN_THESE} test_cd_and_absorb_aug" -#export RUN_THESE="${RUN_THESE} test_cases_B" -#export RUN_THESE="${RUN_THESE} test_refllib" -#export RUN_THESE="${RUN_THESE} test_rtlib" -#export RUN_THESE="${RUN_THESE} test_random_inputs_farina" -#export RUN_THESE="${RUN_THESE} test_random_inputs_westerhof" -#export RUN_THESE="${RUN_THESE} test_iter_rngfreq" -#export RUN_THESE="test_nag_relativistic" +export script=`which $0` +export dn=`dirname $script ` +source ${dn}/test2run.inc + +echo "# remove tests, you don't want to run not here, but in test2run.inc" > pytest.ini +echo \[pytest\] >> pytest.ini +echo python_functions=${RUN_THESE} >> pytest.ini # some more defaults export PYTHON=python export HYPOTHESIS_PROFILE=full export PYTHONPATH=${PYTHONPATH} -# Solaris (11) specific settings -if [[ `uname -s` = SunOS ]]; then - echo " ... on IPP-SOLARIS 64-bit" - if [[ `uname -r` = 5.11 ]]; then - if [[ `uname -i` = i86pc ]]; then - echo "Testing on Solaris 11 in BETA stage !!!" - echo "Testing on Solaris 11 in BETA stage !!!" - echo "Testing on Solaris 11 in BETA stage !!!" - echo "Testing on Solaris 11 in BETA stage !!!" - echo "Testing on Solaris 11 in BETA stage !!!" - export PATH=/afs/ipp/aug/ads-diags/sunx86_511/python2.7/bin:${PATH} - export PYTHON_HOME=/afs/ipp/aug/ads-diags/sunx86_511/python2.7/ - export PYTHONPATH=/afs/ipp/aug/ads-diags/sunx86_510/python2.7/64/lib/python2.7/site-packages:${PYTHONPATH} - export PYTHON=/afs/ipp/aug/ads-diags/sunx86_511/python2.7/bin/python2.7 +#exit 0 + +### IPP specific changes to the environment... +# +if [[ $DOMAIN == *"mpg.de" ]] ; then + if [[ `uname -s` == "SunOS" ]] ; then + if [[ `uname -r` == "5.11" ]] ; then + if [[ `uname -i` == "i86pc" ]] ; then + # Solaris 11, x86 + echo Solaris 11 x86 + export PATH=/afs/ipp/aug/ads-diags/sunx86_511/python2.7/bin:${PATH} + export PYTHON_HOME=/afs/ipp/aug/ads-diags/sunx86_511/python2.7/ + export PYTHONPATH=/afs/ipp/aug/ads-diags/sunx86_510/python2.7/64/lib/python2.7/site-packages:${PYTHONPATH} + export PYTHON=/afs/ipp/aug/ads-diags/sunx86_511/python2.7/bin/python2.7 + else + # Solaris 11, SPARC + echo Solaris 11, whooohoo!!! + export PATH=/afs/ipp/aug/ads-diags/sun4x_511/python2.7/bin:${PATH} + export PYTHON_HOME=/afs/ipp/aug/ads-diags/sun4x_511/python2.7/ + export PYTHONPATH=/afs/ipp/aug/ads-diags/sun4x_510/python2.7/64/lib/python2.7/site-packages:${PYTHONPATH} + export PYTHON=/afs/ipp/aug/ads-diags/sun4x_511/python2.7/bin/python2.7 + echo No chance to test using python on this platform + exit 0 + fi else - echo "Tesing on Solaris 11 SPARC not supported !" - exit 1 + if [[ `uname -r` == "5.10" ]] ; then + if [[ `uname -i` == "i86pc" ]] ; then + # Solaris 10, x86 + echo Solaris 10, x86 + export PATH=/afs/ipp/aug/ads-diags/sunx86_510/python2.7/bin:${PATH} + export PYTHON_HOME=/afs/ipp/aug/ads-diags/sunx86_510/python2.7/ + export PYTHONPATH=/afs/ipp/aug/ads-diags/sunx86_510/python2.7/64/lib/python2.7/site-packages:${PYTHONPATH} + export PYTHON=/afs/ipp/aug/ads-diags/sunx86_510/python2.7/bin/python2.7 + else + # Solaris 10, SPARC + echo Solaris 10, SPARC + export PATH=/afs/ipp/aug/ads-diags/sun4x_510/python2.7/bin:${PATH} + export PYTHON_HOME=/afs/ipp/aug/ads-diags/sun4x_510/python2.7/ + export PYTHONPATH=/afs/ipp/aug/ads-diags/sun4x_510/python2.7/lib/python2.7:${PYTHONPATH} + export PYTHON=/afs/ipp/aug/ads-diags/sun4x_510/python2.7/bin/python2.7 + echo No chance to test using python on this platform + exit 0 + fi + else + echo "unknown OS:" + uname -a + exit 1 + fi fi else - # load proper modules and env variables for this compile run only (Solaris 10) - modcmd="/afs/@cell/common/usr/modules/@sys/Modules/$MODULE_VERSION/bin/modulecmd ksh" - eval `$modcmd purge` - eval `$modcmd load sunstudio/12.6` - eval `$modcmd load nag_flib` - eval `$modcmd load python/2.7` + if [ `uname -s` == "Linux" ] ; then + # Linux OS, assume x86 + #echo Linux-x86 + PYTHON_VER=`python -c 'import sys; print(sys.version_info.major)'` + if [[ $PYTHON_VER != "2" ]] ; then + if [[ $PYTHON_VER != "3" ]] ; then + PYTHON3=`which python3 2> /dev/null` + if [[ $PYTHON3 == *"/python3" ]]; then + export PYTHON=`which python3` + else + echo Need working python 2.x or 3.x + exit 1 + fi + fi + fi + else + echo "unknown OS:" + uname -a + exit 1 + fi fi fi -# Linux specific settings -if [[ `uname -s` = Linux ]]; then - echo " ... on IPP-LINUX 64-bit" - if [ -z $GCC_HOME ] && [ -z $INTEL_HOME ] ; then - # load proper modules and env variables for this compile run only - modcmd="/afs/ipp/common/usr/modules.2014/amd64_sles11/Modules/$MODULE_VERSION/bin/modulecmd ksh" - eval `$modcmd purge` - eval `$modcmd load intel/17.0` - # eval `$modcmd load nag_flib/intel/mk24` - eval `$modcmd load anaconda/2` - export FC=ifort - fi -fi +#$PYTHON --version +## end IPP specific changes dependent on hostOS for arg in "$@"; do if [ $arg == help ] || [ $arg == --help ] ; then @@ -103,10 +135,6 @@ if [[ $(contains "$@" "nocompile") == "-1" ]] ; then cd - fi -if [ $(contains "$@" "NAG") != "-1" ]; then - export NAG_KUSARI_FILE=lserv1.rzg.mpg.de:7733 -fi - if [ $(contains "$@" "debug") != "-1" ]; then export HYPOTHESIS_PROFILE=debug fi @@ -114,7 +142,7 @@ if [ $(contains "$@" "dev") != "-1" ]; then export HYPOTHESIS_PROFILE=dev fi -if [ $(contains "$@" "--verbose") != "-1" ]; then +if [ $(contains "$@" "--verbose") != "-1" ]; then export VERBOSE=" --verbose " else if [ $(contains "$@" "-v") != "-1" ]; then @@ -124,11 +152,6 @@ else fi fi - -echo "# remove tests, you don't want to run not here, but in tsuite.sh" > pytest.ini -echo \[pytest\] >> pytest.ini -echo python_functions=${RUN_THESE} >> pytest.ini - echo "execute: ${PYTHON} -m pytest -s --hypothesis-show-statistics --hypothesis-profile" $HYPOTHESIS_PROFILE $VERBOSE --libdir $libdir ${PYTHON} -m pytest -s --hypothesis-show-statistics --hypothesis-profile $HYPOTHESIS_PROFILE $VERBOSE --libdir $libdir @@ -144,4 +167,3 @@ else echo Something failed, better double check the log... exit 1 fi -