Changeset 8028176 in flex_extract.git


Ignore:
Timestamp:
Aug 5, 2020, 8:40:33 AM (4 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
b4ae1d6
Parents:
0a75335
Message:

updated unit tests

Files:
4 deleted
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • Source/Python/install.py

    rbbbe1e1 r8028176  
    376376                                      'CONTROL*').files]
    377377    testfiles = [os.path.relpath(x, ecd)
    378                  for x in UioFiles(_config.PATH_REL_TEST, '*').files]
     378                 for x in UioFiles(_config.PATH_REL_TEST+"/Installation", '*').files]
    379379    tempfiles = [os.path.relpath(x, ecd)
    380380                 for x in UioFiles(_config.PATH_REL_TEMPLATES, '*.template').files]
     
    387387    makefiles = [os.path.relpath(x, ecd)
    388388                 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, 'makefile*').files]
    389     jobdir = [_config.PATH_REL_JOBSCRIPTS]
     389    jobdir = [os.path.relpath(x, ecd)
     390               for x in UioFiles(_config.PATH_REL_JOBSCRIPTS, '*.md').files]
    390391
    391392    # concatenate single lists to one for a better looping
  • Source/Pythontest/TestInstall.py

    r76c37a9 r8028176  
    1919import pytest
    2020from mock import patch
     21import mock
    2122
    2223sys.path.append('../Python')
     
    5354
    5455
    55     @patch('tarfile.open', side_effect=[subprocess.CalledProcessError(1,'test'),
    56                                         OSError(errno.EEXIST)])
     56    @patch('tarfile.open', side_effect=[tarfile.TarError, OSError])
    5757    def test_fail_mk_tarball_local(self, mock_open):
     58        import tarfile
     59       # mock_open.side_effekt = tarfile.TarError
    5860        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
    5961        # create test tarball and list its content files
     
    6264        with pytest.raises(SystemExit):
    6365            mk_tarball(ecd + tarballname, 'local')
     66
    6467
    6568    def test_success_mk_tarball_local(self):
     
    119122        # list comparison files for tarball content
    120123        tar_test_dir = os.path.join(self.testdir, 'InstallTar')
    121         cmp_dir = _config.FLEXEXTRACT_DIRNAME + '_ecgate'
    122         tar_test_fedir = os.path.join(tar_test_dir, cmp_dir)
    123         comparison_list = []
    124         for path, subdirs, files in os.walk(tar_test_fedir):
    125             for name in files:
    126                 if 'tar' not in name:
    127                     comparison_list.append(os.path.relpath(
    128                         os.path.join(path, name), tar_test_fedir))
     124        tarballname = _config.FLEXEXTRACT_DIRNAME + '_ecgate.tar'
     125        with tarfile.open(os.path.join(tar_test_dir, tarballname), 'r') as tar_handle:
     126            comparison_list = tar_handle.getnames()
    129127
    130128        # untar in test directory
     
    132130        make_dir(test_dir)
    133131        os.chdir(test_dir)
    134         tarballname = _config.FLEXEXTRACT_DIRNAME + '_ecgate.tar'
    135132        un_tarball(os.path.join(tar_test_dir, tarballname))
    136133        tarfiles_list = []
     
    148145        # list comparison files for tarball content
    149146        tar_test_dir = os.path.join(self.testdir, 'InstallTar')
    150         cmp_dir = _config.FLEXEXTRACT_DIRNAME + '_local'
    151         tar_test_fedir = os.path.join(tar_test_dir, cmp_dir)
    152         comparison_list = []
    153         for path, subdirs, files in os.walk(tar_test_fedir):
    154             for name in files:
    155                 if 'tar' not in name:
    156                     comparison_list.append(os.path.relpath(
    157                         os.path.join(path, name), tar_test_fedir))
     147        tarballname = _config.FLEXEXTRACT_DIRNAME + '_local.tar'
     148        with tarfile.open(os.path.join(tar_test_dir, tarballname), 'r') as tar_handle:
     149            comparison_list = tar_handle.getnames()
    158150
    159151        # untar in test directory
     
    161153        make_dir(test_dir)
    162154        os.chdir(test_dir)
    163         tarballname = _config.FLEXEXTRACT_DIRNAME + '_local.tar'
    164155        un_tarball(os.path.join(tar_test_dir, tarballname))
    165156        tarfiles_list = []
     
    168159                tarfiles_list.append(os.path.relpath(
    169160                    os.path.join(path, name), test_dir))
    170 
     161                           
    171162        # test for equality
    172163        assert sorted(tarfiles_list) == sorted(comparison_list)
     
    205196                            'user@destination')
    206197
    207     @patch('__builtin__.open', side_effect=[OSError(errno.EPERM)])
    208     def test_fail_open_mk_env_vars(self, mock_open):
    209         with pytest.raises(SystemExit):
    210             mk_env_vars('testuser',
    211                         'testgroup',
    212                         'gateway.test.ac.at',
    213                         'user@destination')
    214 
    215198    @patch('_config.FILE_INSTALL_COMPILEJOB', _config_test.PATH_TESTFILES_DIR+'/compilejob_test.ksh')
    216199    def test_success_mk_compilejob(self):
     
    221204
    222205        mk_compilejob('Makefile.TEST',
    223                       '',
    224206                      'testuser',
    225207                      'testgroup',
     
    236218        with pytest.raises(SystemExit):
    237219            mk_compilejob('Makefile.TEST',
    238                           '',
    239220                          'testuser',
    240221                          'testgroup',
     
    246227            with pytest.raises(SystemExit):
    247228                mk_compilejob('Makefile.TEST',
    248                               '',
    249229                              'testuser',
    250230                              'testgroup',
    251231                              'fp_root_test_path')
    252232
    253     @patch('__builtin__.open', side_effect=[OSError(errno.EPERM)])
    254     def test_fail_open_mk_compilejob(self, mock_open):
    255         with pytest.raises(SystemExit):
    256             mk_compilejob('Makefile.TEST',
    257                           '',
    258                           'testuser',
    259                           'testgroup',
    260                           'fp_root_test_path')
    261 
    262     @patch('_config.TEMPFILE_JOB', _config_test.PATH_TESTFILES_DIR+'/job_temp.test_test')
     233#    @patch('builtins.open', side_effect=[OSError(errno.EPERM)])
     234#    def test_fail_open_mk_compilejob(self, mock_open):
     235#        with pytest.raises(SystemExit):
     236#            mk_compilejob('Makefile.TEST',
     237#                          'testuser',
     238#                          'testgroup',
     239#                          'fp_root_test_path')
     240
     241    @patch('_config.TEMPFILE_JOB', _config_test.PATH_TESTFILES_DIR+'/submitscript.template.test.comp')
    263242    def test_success_mk_job_template(self):
    264243        import filecmp
    265244
    266245        testfile = os.path.join(self.testfilesdir,
    267                                 'job.temp.test')
     246                                'submitscript.template.test')
    268247
    269248        mk_job_template('testuser',
    270249                        'testgroup',
    271                         'gateway.test.ac.at',
    272                         'dest@generic',
     250#                        'gateway.test.ac.at',
     251#                        'dest@generic',
    273252                        'fp_root_test_path')
    274253
     
    284263            mk_job_template('testuser',
    285264                            'testgroup',
    286                             'gateway.test.ac.at',
    287                             'dest@generic',
     265#                            'gateway.test.ac.at',
     266#                            'dest@generic',
    288267                            'fp_root_test_path')
    289268
     
    294273                mk_job_template('testuser',
    295274                                'testgroup',
    296                                 'gateway.test.ac.at',
    297                                 'dest@generic',
     275 #                               'gateway.test.ac.at',
     276 #                               'dest@generic',
    298277                                'fp_root_test_path')
    299278
    300     @patch('__builtin__.open', side_effect=[OSError(errno.EPERM)])
    301     def test_fail_open_mk_job_template(self, mock_open):
    302         with pytest.raises(SystemExit):
    303             mk_job_template('testuser',
    304                             'testgroup',
    305                             'gateway.test.ac.at',
    306                             'dest@generic',
    307                             'fp_root_test_path')
     279#    @patch('builtins.open', side_effect=[OSError(errno.EPERM)])
     280#    def test_fail_open_mk_job_template(self, mock_open):
     281#        with pytest.raises(SystemExit):
     282#            mk_job_template('testuser',
     283#                            'testgroup',
     284#                            'gateway.test.ac.at',
     285#                            'dest@generic',
     286#                            'fp_root_test_path')
    308287
    309288    @classmethod
  • Source/Pythontest/TestUIOFiles.py

    r76c37a9 r8028176  
    1 #!/usr/bin/env python
     1#!/usr/bin/env python3
    22# -*- coding: utf-8 -*-
    33
     
    5151    def test_str_(self):
    5252        """Test if list of file is correctly converted to string."""
    53         self.expected = "FCSH__SL.20160410.40429.16424.grb, "\
     53        self.expected = "FCOG__ML.20160410.40429.16424.grb, "\
     54                        "FCOG__SL.20160410.40429.16424.grb, "\
    5455                        "FCSH__ML.20160410.40429.16424.grb, "\
    55                         "FCOG__SL.20160410.40429.16424.grb, "\
    56                         "FCOG__ML.20160410.40429.16424.grb, "\
     56                        "FCSH__SL.20160410.40429.16424.grb, "\
    5757                        "OG_OROLSM__SL.20160410.40429.16424.grb, "\
    5858                        "FCGG__SL.20160410.40429.16424.grb, "\
  • Source/Pythontest/_config_test.py

    r76c37a9 r8028176  
    1010
    1111 @License:
    12     (C) Copyright 2014-2018.
     12    (C) Copyright 2014-2020.
    1313
    1414    This software is licensed under the terms of the Apache Licence Version 2.0
  • Testing/Regression/Unit/Controls/CONTROL.test

    rbe6c0a2 r8028176  
    1 DTIME 3
    2 TYPE AN FC FC FC FC FC AN FC FC FC FC FC AN FC FC FC FC FC AN FC FC FC FC FC
    3 TIME 00 00 00 00 00 00 06 00 00 00 00 00 12 12 12 12 12 12 18 12 12 12 12 12
    4 STEP 00 01 02 03 04 05 00 07 08 09 10 11 00 01 02 03 04 05 00 07 08 09 10 11
    5 CLASS EI
     1START_DATE 20180809
     2DTIME 1
     3TYPE AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN AN
     4TIME 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23
     5STEP 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
     6ACCTYPE FC
     7ACCTIME 06/18
     8ACCMAXSTEP 12
     9CLASS EA
    610STREAM OPER
    7 EXPVER 1
    8 GRID 5000 
    9 LEFT -10000
    10 LOWER 30000
    11 UPPER 40000
    12 RIGHT 10000
    13 LEVELIST 59/to/60
    14 RESOL 63
     11GRID 0.28125 
     12LEFT -24.
     13LOWER 9.875
     14UPPER 74.
     15RIGHT 60.375
     16LEVELIST 1/to/137
     17RESOL 799
     18ETA 1
     19FORMAT GRIB2
     20PREFIX EA
     21CWC 1
     22RRINT 1
     23ECTRANS 1
  • Testing/Regression/Unit/InstallTar/mk_install_tar.sh

    rbe6c0a2 r8028176  
    1111path=../../
    1212
    13 tarname='flex_extract_v7.1_local.tar'
     13tarname='flex_extract_v7.1.2_local.tar'
    1414pwd
    1515tar -zcvf ../../Testing/Regression/Unit/InstallTar/$tarname  \
     
    2121        ${path}Source/Fortran/*.h \
    2222        ${path}Source/Fortran/makefile* \
    23         ${path}Templates/convert.nl \
    24         ${path}Templates/*.temp \
    25         ${path}Templates/ecmwf_grib1_table_128 \
     23        ${path}Templates/* \
    2624        ${path}Run/run_local.sh \
    2725        ${path}Run/Control/CONTROL* \
    28         --exclude=${path}Run/Control/Testgrid \
    29         --exclude=${path}Run/Control/notPublic \
    30         ${path}Run/Jobscripts \
    31         ${path}LICENSE.md \
    32         ${path}CODE_OF_CONDUCT.md \
    33         ${path}README.md  \
    34         ${path}Testing/* \
     26        ${path}Run/Jobscripts/*.md \
     27        ${path}*.md \
     28        ${path}Testing/Installation/*.sh \
     29        ${path}Testing/Installation/Api_testscripts/* \
     30        ${path}Testing/Installation/Calc_etadot/* \
     31        ${path}Testing/Installation/First_extraction/* \
    3532        --exclude=*.ksh  \
    3633        --exclude=flex_extract_v7.1_*.tar
     
    3835                 
    3936                 
    40 tarname='flex_extract_v7.1_ecgate.tar'
     37tarname='flex_extract_v7.1.2_ecgate.tar'
    4138
    4239tar -zcvf ../../Testing/Regression/Unit/InstallTar/$tarname \
     
    4845        ${path}Source/Fortran/*.h \
    4946        ${path}Source/Fortran/makefile* \
    50         ${path}Templates/convert.nl \
    51         ${path}Templates/*.temp \
    52         ${path}Templates/ecmwf_grib1_table_128 \
     47        ${path}Templates/* \
    5348        ${path}Run/ECMWF_ENV \
    5449        ${path}Run/run.sh \
    5550        ${path}Run/Control/CONTROL* \
    56         --exclude=${path}Run/Control/Testgrid \
    57         --exclude=${path}Run/Control/notPublic \
    58         ${path}Run/Jobscripts \
     51        ${path}Run/Jobscripts/*.md \
    5952        ${path}LICENSE.md \
    6053        ${path}CODE_OF_CONDUCT.md \
    6154        ${path}README.md \
    62         ${path}Testing/* \
     55        ${path}Testing/Installation/*.sh \
     56        ${path}Testing/Installation/Api_testscripts/* \
     57        ${path}Testing/Installation/Calc_etadot/* \
     58        ${path}Testing/Installation/First_extraction/* \
    6359        --exclude=*.ksh  \
    6460        --exclude=flex_extract_v7.1_*.tar
  • Testing/Regression/Unit/Testfiles/compilejob.test

    rbe6c0a2 r8028176  
    2525
    2626set -x
    27 export VERSION=7.1
     27export VERSION=7.1.2
    2828case ${HOST} in
    2929  *ecg*)
    3030  module unload grib_api
    31   module unload eccodes
     31  module unload emos
     32  module load python3
    3233  module load eccodes
    33   module load python
    34   module unload emos
    3534  module load emos/455-r64
    3635  export FLEXPART_ROOT_SCRIPTS=fp_root_test_path
     
    3938  *cca*)
    4039  module switch PrgEnv-cray PrgEnv-intel
     40  module load python3
    4141  module load eccodes
    42   module load emos
    43   module load python
     42  module load emos/455-r64
    4443  echo ${GROUP}
    4544  echo ${HOME}
     
    5554cd ${FLEXPART_ROOT_SCRIPTS}/flex_extract_v${VERSION}   # if FLEXPART_ROOT is not set this means cd to the home directory
    5655tar -xvf ${HOME}/flex_extract_v${VERSION}.tar
    57 cd source/fortran
    58 \rm *.o *.mod CONVERT2
     56cd Source/Fortran
     57\rm *.o *.mod calc_etadot
    5958make -f ${MAKEFILE} >flexcompile 2>flexcompile
    6059
    61 ls -l CONVERT2 >>flexcompile
     60ls -l calc_etadot >>flexcompile
    6261if [ $? -eq 0 ]; then
    6362  echo 'SUCCESS!' >>flexcompile
  • Testing/Regression/Unit/Testfiles/submitscript.template.test

    rbe6c0a2 r8028176  
    1717##PBS -q np
    1818##PBS -S /usr/bin/ksh
    19 ## -o /scratch/ms/testgroup/testuser/flex_ecmwf.${PBS_JOBID}.out
     19## -o /scratch/ms/testgroup/testuser/flex_ecmwf.$${PBS_JOBID}.out
    2020## job output is in .ecaccess_DO_NOT_REMOVE
    2121##PBS -j oe
     
    2525
    2626set -x
    27 export VERSION=7.1
    28 case ${HOST} in
     27export VERSION=7.1.2
     28case $${HOST} in
    2929  *ecg*)
    30   module load python
    3130  module unload grib_api
    32   module unload eccodes
     31  module unload emos
     32  module load python3
    3333  module load eccodes
    34   module unload emos
    3534  module load emos/455-r64
    36   export PATH=${PATH}:fp_root_test_path/flex_extract_v7.1/source/python
     35  export PATH=$${PATH}:fp_root_test_path/flex_extract_v7.1.2/Source/Python
    3736  ;;
    3837  *cca*)
    3938  module switch PrgEnv-cray PrgEnv-intel
     39  module load python3
    4040  module load eccodes
    41   module load emos
    42   module load python
    43   export SCRATCH=${TMPDIR}
    44   export PATH=${PATH}:fp_root_test_path/flex_extract_v7.1/source/python
     41  module load emos/455-r64
     42  export SCRATCH=$${TMPDIR}
     43  export PATH=$${PATH}:fp_root_test_path/flex_extract_v7.1.2/Source/Python
    4544  ;;
    4645esac
    4746
    48 cd ${SCRATCH}
    49 mkdir -p python$$
    50 cd python$$
     47cd $${SCRATCH}
     48mkdir -p extract$$$$
     49cd extract$$$$
    5150
    5251export CONTROL=CONTROL
    5352
    54 cat >${CONTROL}<<EOF
     53cat >$${CONTROL}<<EOF
     54$control_content
    5555EOF
    5656
    5757
    58 submit.py --controlfile=${CONTROL} --inputdir=./work --outputdir=./work 1> prot 2>&1
     58submit.py --controlfile=$${CONTROL} --inputdir=./work --outputdir=./work 1> prot 2>&1
    5959
    6060if [ $? -eq 0 ] ; then
    6161  l=0
    62   for muser in `grep -i MAILOPS ${CONTROL}`; do
    63       if [ ${l} -gt 0 ] ; then
    64          mail -s flex.${HOST}.$$ ${muser} <prot
     62  for muser in `grep -i MAILOPS $${CONTROL}`; do
     63      if [ $${l} -gt 0 ] ; then
     64         mail -s flex.$${HOST}.$$$$ $${muser} <prot
    6565      fi
    66       l=$((${l}+1))
     66      l=$(($${l}+1))
    6767  done
    6868else
    6969  l=0
    70   for muser in `grep -i MAILFAIL ${CONTROL}`; do
    71       if [ ${l} -gt 0 ] ; then
    72          mail -s "ERROR! flex.${HOST}.$$" ${muser} <prot
     70  for muser in `grep -i MAILFAIL $${CONTROL}`; do
     71      if [ $${l} -gt 0 ] ; then
     72         mail -s "ERROR! flex.$${HOST}.$$$$" $${muser} <prot
    7373      fi
    74       l=$((${l}+1))
     74      l=$(($${l}+1))
    7575  done
    7676fi
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG