Changeset 3946de5 in flex_extract.git


Ignore:
Timestamp:
Nov 16, 2018, 8:07:45 PM (5 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
5e7c588
Parents:
1abf820
Message:

added testing for most of the install functions; improved install functions with exception handling

Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • source/python/_config.py

    r96e1533 r3946de5  
    9393# ------------------------------------------------------------------------------
    9494
    95 PATH_REL_PYTHON = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR)
     95PATH_REL_PYTHON_SRC = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR)
     96PATH_REL_PYTHONTEST_SRC = os.path.relpath(PATH_PYTHONTEST_SRC, PATH_FLEXEXTRACT_DIR)
    9697PATH_REL_CONTROLFILES = os.path.relpath(PATH_CONTROLFILES, PATH_FLEXEXTRACT_DIR)
    9798PATH_REL_TEMPLATES = os.path.relpath(PATH_TEMPLATES, PATH_FLEXEXTRACT_DIR)
  • source/python/install.py

    r274f9ef r3946de5  
    5454import subprocess
    5555import inspect
     56import tarfile
    5657from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
    5758
     
    239240
    240241    '''
    241     import tarfile
    242242    from glob import glob
    243243
     
    252252    if target == 'local':
    253253        ECMWF_ENV_FILE = []
     254        runfile = [os.path.relpath(x, ecd)
     255                   for x in UioFiles(_config.PATH_REL_RUN_DIR,
     256                                     'run_local.sh').files]
    254257    else:
    255258        ECMWF_ENV_FILE = [_config.PATH_REL_ECMWF_ENV]
     259        runfile = [os.path.relpath(x, ecd)
     260                       for x in UioFiles(_config.PATH_REL_RUN_DIR,
     261                                         'run.sh').files]
    256262
    257263    pyfiles = [os.path.relpath(x, ecd)
    258                for x in UioFiles(_config.PATH_LOCAL_PYTHON, '*py').files]
     264               for x in UioFiles(_config.PATH_REL_PYTHON_SRC, '*py').files]
     265    pytestfiles = [os.path.relpath(x, ecd)
     266               for x in UioFiles(_config.PATH_REL_PYTHONTEST_SRC, '*py').files]
    259267    controlfiles = [os.path.relpath(x, ecd)
    260                     for x in UioFiles(_config.PATH_CONTROLFILES,
     268                    for x in UioFiles(_config.PATH_REL_CONTROLFILES,
    261269                                      'CONTROL*').files]
    262270    tempfiles = [os.path.relpath(x, ecd)
    263                  for x in UioFiles(_config.PATH_TEMPLATES , '*').files]
     271                 for x in UioFiles(_config.PATH_REL_TEMPLATES , '*.temp').files]
     272    nlfiles = [os.path.relpath(x, ecd)
     273                 for x in UioFiles(_config.PATH_REL_TEMPLATES , '*.nl').files]
     274    gribtable = [os.path.relpath(x, ecd)
     275                 for x in UioFiles(_config.PATH_REL_TEMPLATES , '*grib*').files]
    264276    ffiles = [os.path.relpath(x, ecd)
    265               for x in UioFiles(_config.PATH_FORTRAN_SRC, '*.f*').files]
     277              for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.f*').files]
    266278    hfiles = [os.path.relpath(x, ecd)
    267               for x in UioFiles(_config.PATH_FORTRAN_SRC, '*.h').files]
     279              for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, '*.h').files]
    268280    makefiles = [os.path.relpath(x, ecd)
    269                  for x in UioFiles(_config.PATH_FORTRAN_SRC, 'Makefile*').files]
     281                 for x in UioFiles(_config.PATH_REL_FORTRAN_SRC, 'Makefile*').files]
     282    jobdir = [_config.PATH_REL_JOBSCRIPTS]
    270283
    271284    # concatenate single lists to one for a better looping
    272     filelist = pyfiles + controlfiles + tempfiles + ffiles + hfiles + \
    273                makefiles + ECMWF_ENV_FILE
     285    filelist = pyfiles + pytestfiles + controlfiles + tempfiles + nlfiles + \
     286               ffiles + gribtable + hfiles + makefiles + ECMWF_ENV_FILE + \
     287               runfile + jobdir + \
     288               ['CODE_OF_CONDUCT.md', 'LICENSE.md', 'README.md']
    274289
    275290    # create installation tar-file
     291    exclude_files = [".ksh"]
    276292    try:
    277293        with tarfile.open(tarball_path, "w:gz") as tar_handle:
    278294            for file in filelist:
    279                 tar_handle.add(file)
    280 
     295                tar_handle.add(file, recursive=False,
     296                               filter=lambda tarinfo: None
     297                                      if os.path.splitext(tarinfo.name)[1]
     298                                         in exclude_files
     299                                      else tarinfo)
    281300    except subprocess.CalledProcessError as e:
    282301        print('... ERROR CODE:\n ... ' + str(e.returncode))
    283302        print('... ERROR MESSAGE:\n ... ' + str(e))
    284303
    285         sys.exit('... could not make installation tar ball!')
     304        sys.exit('\n... could not make installation tar ball!')
     305    except OSError as e:
     306        print('... ERROR CODE: ' + str(e.errno))
     307        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     308
     309        sys.exit('\n... error occured while trying to read tar-file ' +
     310                 str(tarball_path))
    286311
    287312    return
     
    301326
    302327    '''
    303     import tarfile
    304328
    305329    print('Untar ...')
    306330
    307     with tarfile.open(tarball_path) as tar_handle:
    308         tar_handle.extractall()
     331    try:
     332        with tarfile.open(tarball_path) as tar_handle:
     333            tar_handle.extractall()
     334    except tarfile.TarError as e:
     335        sys.exit('\n... error occured while trying to read tar-file ' +
     336                     str(tarball_path))
     337    except OSError as e:
     338        print('... ERROR CODE: ' + str(e.errno))
     339        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     340
     341        sys.exit('\n... error occured while trying to read tar-file ' +
     342                 str(tarball_path))
    309343
    310344    return
     
    336370    from genshi.template.text import NewTextTemplate
    337371    from genshi.template import  TemplateLoader
    338 
    339     loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
    340     ecmwfvars_template = loader.load(_config.TEMPFILE_USER_ENVVARS,
    341                                      cls=NewTextTemplate)
    342 
    343     stream = ecmwfvars_template.generate(user_name = ecuid,
    344                                        user_group = ecgid,
    345                                        gateway_name = gateway,
    346                                        destination_name = destination
    347                                        )
    348 
    349     with open(_config.PATH_ECMWF_ENV, 'w') as f:
    350         f.write(stream.render('text'))
     372    from genshi.template.eval import UndefinedError
     373
     374    try:
     375        loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
     376        ecmwfvars_template = loader.load(_config.TEMPFILE_USER_ENVVARS,
     377                                         cls=NewTextTemplate)
     378
     379        stream = ecmwfvars_template.generate(user_name = ecuid,
     380                                             user_group = ecgid,
     381                                             gateway_name = gateway,
     382                                             destination_name = destination
     383                                             )
     384    except UndefinedError as e:
     385        print('... ERROR ' + str(e))
     386
     387        sys.exit('\n... error occured while trying to generate template ' +
     388                 _config.PATH_ECMWF_ENV)
     389    except OSError as e:
     390        print('... ERROR CODE: ' + str(e.errno))
     391        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     392
     393        sys.exit('\n... error occured while trying to generate template ' +
     394                 _config.PATH_ECMWF_ENV)
     395
     396    try:
     397        with open(_config.PATH_ECMWF_ENV, 'w') as f:
     398            f.write(stream.render('text'))
     399    except OSError as e:
     400        print('... ERROR CODE: ' + str(e.errno))
     401        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     402
     403        sys.exit('\n... error occured while trying to write ' +
     404                 _config.PATH_ECMWF_ENV)
    351405
    352406    return
     
    382436    from genshi.template.text import NewTextTemplate
    383437    from genshi.template import  TemplateLoader
    384 
    385     loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
    386     compile_template = loader.load(_config.TEMPFILE_INSTALL_COMPILEJOB,
    387                                    cls=NewTextTemplate)
     438    from genshi.template.eval import  UndefinedError
    388439
    389440    if fp_root == '../':
    390441        fp_root = '$HOME'
    391442
    392     stream = compile_template.generate(
    393         usergroup = ecgid,
    394         username = ecuid,
    395         version_number = _config._VERSION_STR,
    396         fp_root_scripts = fp_root,
    397         makefile = makefile,
    398         fortran_program = _config.FORTRAN_EXECUTABLE
    399     )
    400 
    401     compilejob = os.path.join(_config.PATH_JOBSCRIPTS,
    402                               _config.FILE_INSTALL_COMPILEJOB)
    403 
    404     with open(compilejob, 'w') as f:
    405         f.write(stream.render('text'))
     443    try:
     444        loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
     445        compile_template = loader.load(_config.TEMPFILE_INSTALL_COMPILEJOB,
     446                                       cls=NewTextTemplate)
     447
     448        stream = compile_template.generate(
     449            usergroup = ecgid,
     450            username = ecuid,
     451            version_number = _config._VERSION_STR,
     452            fp_root_scripts = fp_root,
     453            makefile = makefile,
     454            fortran_program = _config.FORTRAN_EXECUTABLE
     455        )
     456    except UndefinedError as e:
     457        print('... ERROR ' + str(e))
     458
     459        sys.exit('\n... error occured while trying to generate template ' +
     460                 _config.TEMPFILE_INSTALL_COMPILEJOB)
     461    except OSError as e:
     462        print('... ERROR CODE: ' + str(e.errno))
     463        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     464
     465        sys.exit('\n... error occured while trying to generate template ' +
     466                 _config.TEMPFILE_INSTALL_COMPILEJOB)
     467
     468    try:
     469        compilejob = os.path.join(_config.PATH_JOBSCRIPTS,
     470                                  _config.FILE_INSTALL_COMPILEJOB)
     471
     472        with open(compilejob, 'w') as f:
     473            f.write(stream.render('text'))
     474    except OSError as e:
     475        print('... ERROR CODE: ' + str(e.errno))
     476        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     477
     478        sys.exit('\n... error occured while trying to write ' +
     479                 compilejob)
    406480
    407481    return
     
    437511    from genshi.template.text import NewTextTemplate
    438512    from genshi.template import  TemplateLoader
    439 
    440     loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
    441     compile_template = loader.load(_config.TEMPFILE_INSTALL_JOB,
    442                                    cls=NewTextTemplate)
     513    from genshi.template.eval import  UndefinedError
    443514
    444515    fp_root_path_to_python = os.path.join(fp_root,
    445516                                          _config.FLEXEXTRACT_DIRNAME,
    446                                           _config.PATH_REL_PYTHON)
    447 
    448     stream = compile_template.generate(
    449         usergroup = ecgid,
    450         username = ecuid,
    451         version_number = _config._VERSION_STR,
    452         fp_root_path = fp_root_path_to_python,
    453     )
    454 
    455     tempjobfile = os.path.join(_config.PATH_TEMPLATES,
    456                                _config.TEMPFILE_JOB)
    457 
    458     with open(tempjobfile, 'w') as f:
    459         f.write(stream.render('text'))
     517                                          _config.PATH_REL_PYTHON_SRC)
     518
     519    try:
     520        loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
     521        compile_template = loader.load(_config.TEMPFILE_INSTALL_JOB,
     522                                       cls=NewTextTemplate)
     523
     524        stream = compile_template.generate(
     525            usergroup = ecgid,
     526            username = ecuid,
     527            version_number = _config._VERSION_STR,
     528            fp_root_path = fp_root_path_to_python,
     529        )
     530    except UndefinedError as e:
     531        print('... ERROR ' + str(e))
     532
     533        sys.exit('\n... error occured while trying to generate template ' +
     534                 _config.TEMPFILE_INSTALL_JOB)
     535    except OSError as e:
     536        print('... ERROR CODE: ' + str(e.errno))
     537        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     538
     539        sys.exit('\n... error occured while trying to generate template ' +
     540                 _config.TEMPFILE_INSTALL_JOB)
     541
     542
     543    try:
     544        tempjobfile = os.path.join(_config.PATH_TEMPLATES,
     545                                   _config.TEMPFILE_JOB)
     546
     547        with open(tempjobfile, 'w') as f:
     548            f.write(stream.render('text'))
     549    except OSError as e:
     550        print('... ERROR CODE: ' + str(e.errno))
     551        print('... ERROR MESSAGE:\n \t ' + str(e.strerror))
     552
     553        sys.exit('\n... error occured while trying to write ' +
     554                 tempjobfile)
    460555
    461556    return
  • source/python/mods/tools.py

    r96e1533 r3946de5  
    9999        return None
    100100    return int(value)
     101
     102def check_filepattern(filename):
     103    '''
     104    '''
     105    if '.ksh' in filename:
     106        return True
     107    return False
     108
     109
    101110
    102111def get_cmdline_arguments():
  • source/pythontest/TestInstall.py

    rc5074d2 r3946de5  
    66import os
    77import inspect
     8import subprocess
     9import tarfile
     10import errno
     11import shutil
     12from genshi.template import TemplateLoader
     13from genshi.template.eval import  UndefinedError
     14from exceptions import OSError
    815import pytest
     16from mock import patch
    917
    1018sys.path.append('../python')
    1119import _config
    12 import install
     20import _config_test
     21from install import (mk_tarball, un_tarball, mk_env_vars, mk_compilejob,
     22                     mk_job_template)
     23
    1324from mods.tools import make_dir, silent_remove
    1425
    15 
    16 class TestTools():
     26#    - main
     27#    - get_install_cmdline_arguments
     28#    - install_via_gateway
     29#    - delete_convert_build
     30#    - make_convert_build
     31
     32class TestInstall():
    1733    '''
    1834    '''
    19 
    20 
    21     #    - main
    22     #    - get_install_cmdline_arguments
    23     #    - install_via_gateway
    24     #!    - mk_tarball
    25     #!    - un_tarball
    26     #!    - mk_env_vars
    27     #!    - mk_compilejob
    28     #!    - mk_job_template
    29     #    - delete_convert_build
    30     #    - make_convert_build
    31 
    32     def test_mk_tarball_local(self):
    33         import tarfile
    34 
     35    @classmethod
     36    def setup_class(self):
     37        self.testdir = _config_test.PATH_TEST_DIR
     38        self.testfilesdir = _config_test.PATH_TESTFILES_DIR
     39        self.testinstalldir = _config_test.PATH_TESTINSTALL_DIR
     40
     41        # make test tarballs from shell script
     42        subprocess.check_output([os.path.join(self.testinstalldir,
     43                                              'mk_install_tar.sh')])
     44
     45        # un tar the test tarballs from shell script
     46        subprocess.check_output([os.path.join(self.testinstalldir,
     47                                              'un_install_tar.sh')])
     48
     49
     50
     51    @patch('tarfile.open', side_effect=[subprocess.CalledProcessError(1,'test'),
     52                                        OSError(errno.EEXIST)])
     53    def test_fail_mk_tarball_local(self, mock_open):
     54        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
     55        # create test tarball and list its content files
     56        tarballname = _config.FLEXEXTRACT_DIRNAME + '_localtest.tar'
     57
     58        with pytest.raises(SystemExit):
     59            mk_tarball(ecd + tarballname, 'local')
     60        with pytest.raises(SystemExit):
     61            mk_tarball(ecd + tarballname, 'local')
     62
     63    def test_success_mk_tarball_local(self):
    3564        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
    3665
    3766        # list comparison files for tarball content
    38         tar_test_dir = os.path.join(_config.PATH_TEST_DIR +
    39                                     os.path.sep + 'TestInstallTar')
     67        tar_test_dir = os.path.join(self.testdir, 'InstallTar')
    4068        tar_test_file = os.path.join(tar_test_dir,
    4169                                     'flex_extract_v7.1_local.tar')
     
    4573        # create test tarball and list its content files
    4674        tarballname = _config.FLEXEXTRACT_DIRNAME + '_localtest.tar'
    47         install.mk_tarball(ecd + tarballname, 'local')
     75        mk_tarball(ecd + tarballname, 'local')
    4876        with tarfile.open(ecd + tarballname, 'r') as tar_handle:
    4977            tar_content_list = tar_handle.getnames()
     
    5684        assert sorted(comparison_list) == sorted(tar_content_list)
    5785
    58     def test_mk_tarball_ecgate(self):
    59         import tarfile
    60 
     86    def test_success_mk_tarball_ecgate(self):
    6187        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
    6288
    6389        # list comparison files for tarball content
    64         tar_test_dir = os.path.join(_config.PATH_TEST_DIR +
    65                                     os.path.sep + 'TestInstallTar')
     90        tar_test_dir = os.path.join(self.testdir, 'InstallTar')
    6691        tar_test_file = os.path.join(tar_test_dir,
    6792                                     'flex_extract_v7.1_ecgate.tar')
     
    7196        # create test tarball and list its content files
    7297        tarballname = _config.FLEXEXTRACT_DIRNAME + '_ecgatetest.tar'
    73         install.mk_tarball(ecd + tarballname, 'ecgate')
     98        mk_tarball(ecd + tarballname, 'ecgate')
    7499        with tarfile.open(ecd + tarballname, 'r') as tar_handle:
    75100            tar_content_list = tar_handle.getnames()
     
    82107        assert sorted(comparison_list) == sorted(tar_content_list)
    83108
    84     def test_un_tarball(self):
    85         import tarfile
    86         import shutil
    87 
     109    @patch('tarfile.open', side_effect=[tarfile.TarError, OSError])
     110    def test_fail_un_tarball(self, mock_open):
     111        with pytest.raises(SystemExit):
     112            un_tarball('testpath')
     113
     114    def test_success_ecgate_un_tarball(self):
    88115        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
    89116
    90117        # list comparison files for tarball content
    91         tar_test_dir = os.path.join(_config.PATH_TEST_DIR +
    92                                         os.path.sep + 'TestInstallTar')
    93         tar_test_fedir = os.path.join(tar_test_dir, 'flex_extract_v7.1_ecgate')
     118        tar_test_dir = os.path.join(self.testdir, 'InstallTar')
     119        cmp_dir = _config.FLEXEXTRACT_DIRNAME + '_ecgate'
     120        tar_test_fedir = os.path.join(tar_test_dir, cmp_dir)
    94121        comparison_list = []
    95122        for path, subdirs, files in os.walk(tar_test_fedir):
     
    100127
    101128        # untar in test directory
    102         test_dir = os.path.join(tar_test_dir, 'test_untar')
     129        test_dir = os.path.join(tar_test_dir, 'test_ecgate')
    103130        make_dir(test_dir)
    104131        os.chdir(test_dir)
    105132        tarballname = _config.FLEXEXTRACT_DIRNAME + '_ecgate.tar'
    106         install.un_tarball(os.path.join(tar_test_dir, tarballname))
     133        un_tarball(os.path.join(tar_test_dir, tarballname))
    107134        tarfiles_list = []
    108135        for path, subdirs, files in os.walk(test_dir):
     
    114141        assert sorted(tarfiles_list) == sorted(comparison_list)
    115142
    116         # clean up temp test dir
    117         shutil.rmtree(test_dir)
    118 
    119     def test_mk_env_vars(self):
     143    def test_success_local_un_tarball(self):
     144        ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep
     145
     146        # list comparison files for tarball content
     147        tar_test_dir = os.path.join(self.testdir, 'InstallTar')
     148        cmp_dir = _config.FLEXEXTRACT_DIRNAME + '_local'
     149        tar_test_fedir = os.path.join(tar_test_dir, cmp_dir)
     150        comparison_list = []
     151        for path, subdirs, files in os.walk(tar_test_fedir):
     152            for name in files:
     153                if 'tar' not in name:
     154                    comparison_list.append(os.path.relpath(
     155                        os.path.join(path, name), tar_test_fedir))
     156
     157        # untar in test directory
     158        test_dir = os.path.join(tar_test_dir, 'test_local')
     159        make_dir(test_dir)
     160        os.chdir(test_dir)
     161        tarballname = _config.FLEXEXTRACT_DIRNAME + '_local.tar'
     162        un_tarball(os.path.join(tar_test_dir, tarballname))
     163        tarfiles_list = []
     164        for path, subdirs, files in os.walk(test_dir):
     165            for name in files:
     166                tarfiles_list.append(os.path.relpath(
     167                    os.path.join(path, name), test_dir))
     168
     169        # test for equality
     170        assert sorted(tarfiles_list) == sorted(comparison_list)
     171
     172    @patch('_config.PATH_ECMWF_ENV', _config_test.PATH_TESTFILES_DIR+'/ecmwf_test')
     173    def test_success_mk_env_vars(self):
    120174        import filecmp
    121175
    122         # comparison file
    123         testfile = os.path.join(_config.PATH_TEST_DIR,'TestData',
     176        cmp_file = os.path.join(self.testfilesdir,
    124177                                'ECMWF_ENV.test')
    125178
    126         # create test ECMWF_ENV file
    127         install.mk_env_vars('testuser',
     179        mk_env_vars('testuser',
     180                    'testgroup',
     181                    'gateway.test.ac.at',
     182                    'user@destination')
     183
     184        assert filecmp.cmp(cmp_file, _config.PATH_ECMWF_ENV, shallow=False)
     185
     186        silent_remove(_config.PATH_ECMWF_ENV)
     187
     188    @patch('genshi.template.TemplateLoader', side_effect=[OSError])
     189    def test_fail_load_mk_env_vars(self, mock_generate):
     190        with pytest.raises(SystemExit):
     191            mk_env_vars('testuser',
     192                        'testgroup',
     193                        'gateway.test.ac.at',
     194                        'user@destination')
     195
     196    def test_fail_generate_mk_env_vars(self):
     197        with patch('genshi.template.TemplateLoader.load') as MockHelper:
     198            MockHelper.return_value.generate.side_effect = UndefinedError('undefined')
     199            with pytest.raises(SystemExit):
     200                mk_env_vars('testuser',
    128201                            'testgroup',
    129202                            'gateway.test.ac.at',
    130203                            'user@destination')
    131204
    132         assert filecmp.cmp(testfile, _config.PATH_ECMWF_ENV, shallow=False)
    133 
    134         # delte test file
    135         silent_remove(_config.PATH_ECMWF_ENV)
    136 
    137     def test_mk_compilejob(self):
     205    @patch('__builtin__.open', side_effect=[OSError(errno.EPERM)])
     206    def test_fail_open_mk_env_vars(self, mock_open):
     207        with pytest.raises(SystemExit):
     208            mk_env_vars('testuser',
     209                        'testgroup',
     210                        'gateway.test.ac.at',
     211                        'user@destination')
     212
     213    @patch('_config.FILE_INSTALL_COMPILEJOB', _config_test.PATH_TESTFILES_DIR+'/compilejob_test.ksh')
     214    def test_success_mk_compilejob(self):
    138215        import filecmp
    139216
    140         # comparison file
    141         testfile = os.path.join(_config.PATH_TEST_DIR,'TestData',
    142                                     'compilejob.test')
    143 
    144         # create
    145         install.mk_compilejob('Makefile.TEST',
     217        testfile = os.path.join(self.testfilesdir,
     218                                'compilejob.test')
     219
     220        mk_compilejob('Makefile.TEST',
     221                      '',
     222                      'testuser',
     223                      'testgroup',
     224                      'fp_root_test_path')
     225
     226        finalfile = os.path.join(_config.PATH_JOBSCRIPTS,
     227                                 _config.FILE_INSTALL_COMPILEJOB)
     228        assert filecmp.cmp(testfile, finalfile, shallow=False)
     229
     230        silent_remove(finalfile)
     231
     232    @patch('genshi.template.TemplateLoader', side_effect=[OSError])
     233    def test_fail_load_mk_compilejob(self, mock_generate):
     234        with pytest.raises(SystemExit):
     235            mk_compilejob('Makefile.TEST',
     236                          '',
     237                          'testuser',
     238                          'testgroup',
     239                          'fp_root_test_path')
     240
     241    def test_fail_generate_mk_compilejob(self):
     242        with patch('genshi.template.TemplateLoader.load') as MockHelper:
     243            MockHelper.return_value.generate.side_effect = UndefinedError('undefined')
     244            with pytest.raises(SystemExit):
     245                mk_compilejob('Makefile.TEST',
    146246                              '',
    147247                              'testuser',
     
    149249                              'fp_root_test_path')
    150250
    151         finalfile = os.path.join(_config.PATH_JOBSCRIPTS,
    152                               _config.FILE_INSTALL_COMPILEJOB)
     251    @patch('__builtin__.open', side_effect=[OSError(errno.EPERM)])
     252    def test_fail_open_mk_compilejob(self, mock_open):
     253        with pytest.raises(SystemExit):
     254            mk_compilejob('Makefile.TEST',
     255                          '',
     256                          'testuser',
     257                          'testgroup',
     258                          'fp_root_test_path')
     259
     260    @patch('_config.TEMPFILE_JOB', _config_test.PATH_TESTFILES_DIR+'/job_temp.test_test')
     261    def test_success_mk_job_template(self):
     262        import filecmp
     263
     264        testfile = os.path.join(self.testfilesdir,
     265                                'job.temp.test')
     266
     267        mk_job_template('testuser',
     268                        'testgroup',
     269                        'gateway.test.ac.at',
     270                        'dest@generic',
     271                        'fp_root_test_path')
     272
     273        finalfile = os.path.join(_config.PATH_TEMPLATES,
     274                                 _config.TEMPFILE_JOB)
    153275        assert filecmp.cmp(testfile, finalfile, shallow=False)
    154276
    155         # delete test file
    156277        silent_remove(finalfile)
    157278
    158     def test_mk_job_template(self):
    159         import filecmp
    160 
    161         # comparison file
    162         testfile = os.path.join(_config.PATH_TEST_DIR,
    163                                 'TestData',
    164                                 'job.temp.test')
    165 
    166         # create
    167         install.mk_job_template('testuser',
     279    @patch('genshi.template.TemplateLoader', side_effect=[OSError])
     280    def test_fail_load_mk_job_template(self, mock_generate):
     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')
     287
     288    def test_fail_generate_mk_job_template(self):
     289        with patch('genshi.template.TemplateLoader.load') as MockHelper:
     290            MockHelper.return_value.generate.side_effect = UndefinedError('undefined')
     291            with pytest.raises(SystemExit):
     292                mk_job_template('testuser',
    168293                                'testgroup',
    169294                                'gateway.test.ac.at',
     
    171296                                'fp_root_test_path')
    172297
    173         finalfile = os.path.join(_config.PATH_TEMPLATES,
    174                                  _config.TEMPFILE_JOB)
    175         assert filecmp.cmp(testfile, finalfile, shallow=False)
    176 
    177         # delete test file
    178         silent_remove(finalfile)
     298    @patch('__builtin__.open', side_effect=[OSError(errno.EPERM)])
     299    def test_fail_open_mk_job_template(self, mock_open):
     300        with pytest.raises(SystemExit):
     301            mk_job_template('testuser',
     302                            'testgroup',
     303                            'gateway.test.ac.at',
     304                            'dest@generic',
     305                            'fp_root_test_path')
     306
     307    @classmethod
     308    def teardown_class(self):
     309
     310        test_dir = os.path.join(self.testinstalldir,
     311                                _config.FLEXEXTRACT_DIRNAME + '_local')
     312        shutil.rmtree(test_dir)
     313        test_dir = os.path.join(self.testinstalldir,
     314                                _config.FLEXEXTRACT_DIRNAME + '_ecgate')
     315        shutil.rmtree(test_dir)
     316
     317        test_dir = os.path.join(self.testinstalldir,
     318                                'test_local')
     319        shutil.rmtree(test_dir)
     320        test_dir = os.path.join(self.testinstalldir,
     321                                'test_ecgate')
     322        shutil.rmtree(test_dir)
     323
     324        tar_file = os.path.join(self.testinstalldir,
     325                     _config.FLEXEXTRACT_DIRNAME + '_local.tar')
     326        os.remove(tar_file)
     327        tar_file = os.path.join(self.testinstalldir,
     328                                _config.FLEXEXTRACT_DIRNAME + '_ecgate.tar')
     329        os.remove(tar_file)
     330        pass
  • source/pythontest/_config_test.py

    r96e1533 r3946de5  
    4040TEST_DIR = 'test'
    4141TESTFILES_DIR = 'Testfiles'
    42 
     42TESTINSTALL_DIR = 'InstallTar'
    4343# ------------------------------------------------------------------------------
    4444#  PATHES
     
    4646PATH_TEST_DIR = os.path.join(_config.PATH_FLEXEXTRACT_DIR, TEST_DIR)
    4747PATH_TESTFILES_DIR = os.path.join(PATH_TEST_DIR, TESTFILES_DIR)
    48 
     48PATH_TESTINSTALL_DIR = os.path.join(PATH_TEST_DIR, TESTINSTALL_DIR)
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG