Changeset 8028176 in flex_extract.git for Source/Pythontest/TestInstall.py


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG