Changeset 3946de5 in flex_extract.git for source/pythontest/TestInstall.py
- Timestamp:
- Nov 16, 2018, 8:07:45 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 5e7c588
- Parents:
- 1abf820
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/pythontest/TestInstall.py
rc5074d2 r3946de5 6 6 import os 7 7 import inspect 8 import subprocess 9 import tarfile 10 import errno 11 import shutil 12 from genshi.template import TemplateLoader 13 from genshi.template.eval import UndefinedError 14 from exceptions import OSError 8 15 import pytest 16 from mock import patch 9 17 10 18 sys.path.append('../python') 11 19 import _config 12 import install 20 import _config_test 21 from install import (mk_tarball, un_tarball, mk_env_vars, mk_compilejob, 22 mk_job_template) 23 13 24 from mods.tools import make_dir, silent_remove 14 25 15 16 class TestTools(): 26 # - main 27 # - get_install_cmdline_arguments 28 # - install_via_gateway 29 # - delete_convert_build 30 # - make_convert_build 31 32 class TestInstall(): 17 33 ''' 18 34 ''' 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): 35 64 ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep 36 65 37 66 # 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') 40 68 tar_test_file = os.path.join(tar_test_dir, 41 69 'flex_extract_v7.1_local.tar') … … 45 73 # create test tarball and list its content files 46 74 tarballname = _config.FLEXEXTRACT_DIRNAME + '_localtest.tar' 47 install.mk_tarball(ecd + tarballname, 'local')75 mk_tarball(ecd + tarballname, 'local') 48 76 with tarfile.open(ecd + tarballname, 'r') as tar_handle: 49 77 tar_content_list = tar_handle.getnames() … … 56 84 assert sorted(comparison_list) == sorted(tar_content_list) 57 85 58 def test_mk_tarball_ecgate(self): 59 import tarfile 60 86 def test_success_mk_tarball_ecgate(self): 61 87 ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep 62 88 63 89 # 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') 66 91 tar_test_file = os.path.join(tar_test_dir, 67 92 'flex_extract_v7.1_ecgate.tar') … … 71 96 # create test tarball and list its content files 72 97 tarballname = _config.FLEXEXTRACT_DIRNAME + '_ecgatetest.tar' 73 install.mk_tarball(ecd + tarballname, 'ecgate')98 mk_tarball(ecd + tarballname, 'ecgate') 74 99 with tarfile.open(ecd + tarballname, 'r') as tar_handle: 75 100 tar_content_list = tar_handle.getnames() … … 82 107 assert sorted(comparison_list) == sorted(tar_content_list) 83 108 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): 88 115 ecd = _config.PATH_FLEXEXTRACT_DIR + os.path.sep 89 116 90 117 # 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) 94 121 comparison_list = [] 95 122 for path, subdirs, files in os.walk(tar_test_fedir): … … 100 127 101 128 # 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') 103 130 make_dir(test_dir) 104 131 os.chdir(test_dir) 105 132 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)) 107 134 tarfiles_list = [] 108 135 for path, subdirs, files in os.walk(test_dir): … … 114 141 assert sorted(tarfiles_list) == sorted(comparison_list) 115 142 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): 120 174 import filecmp 121 175 122 # comparison file 123 testfile = os.path.join(_config.PATH_TEST_DIR,'TestData', 176 cmp_file = os.path.join(self.testfilesdir, 124 177 'ECMWF_ENV.test') 125 178 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', 128 201 'testgroup', 129 202 'gateway.test.ac.at', 130 203 'user@destination') 131 204 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): 138 215 import filecmp 139 216 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', 146 246 '', 147 247 'testuser', … … 149 249 'fp_root_test_path') 150 250 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) 153 275 assert filecmp.cmp(testfile, finalfile, shallow=False) 154 276 155 # delete test file156 277 silent_remove(finalfile) 157 278 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', 168 293 'testgroup', 169 294 'gateway.test.ac.at', … … 171 296 'fp_root_test_path') 172 297 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
Note: See TracChangeset
for help on using the changeset viewer.