Changeset 3946de5 in flex_extract.git
- Timestamp:
- Nov 16, 2018, 8:07:45 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 5e7c588
- Parents:
- 1abf820
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/_config.py
r96e1533 r3946de5 93 93 # ------------------------------------------------------------------------------ 94 94 95 PATH_REL_PYTHON = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR) 95 PATH_REL_PYTHON_SRC = os.path.relpath(PATH_LOCAL_PYTHON, PATH_FLEXEXTRACT_DIR) 96 PATH_REL_PYTHONTEST_SRC = os.path.relpath(PATH_PYTHONTEST_SRC, PATH_FLEXEXTRACT_DIR) 96 97 PATH_REL_CONTROLFILES = os.path.relpath(PATH_CONTROLFILES, PATH_FLEXEXTRACT_DIR) 97 98 PATH_REL_TEMPLATES = os.path.relpath(PATH_TEMPLATES, PATH_FLEXEXTRACT_DIR) -
source/python/install.py
r274f9ef r3946de5 54 54 import subprocess 55 55 import inspect 56 import tarfile 56 57 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter 57 58 … … 239 240 240 241 ''' 241 import tarfile242 242 from glob import glob 243 243 … … 252 252 if target == 'local': 253 253 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] 254 257 else: 255 258 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] 256 262 257 263 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] 259 267 controlfiles = [os.path.relpath(x, ecd) 260 for x in UioFiles(_config.PATH_ CONTROLFILES,268 for x in UioFiles(_config.PATH_REL_CONTROLFILES, 261 269 'CONTROL*').files] 262 270 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] 264 276 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] 266 278 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] 268 280 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] 270 283 271 284 # 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'] 274 289 275 290 # create installation tar-file 291 exclude_files = [".ksh"] 276 292 try: 277 293 with tarfile.open(tarball_path, "w:gz") as tar_handle: 278 294 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) 281 300 except subprocess.CalledProcessError as e: 282 301 print('... ERROR CODE:\n ... ' + str(e.returncode)) 283 302 print('... ERROR MESSAGE:\n ... ' + str(e)) 284 303 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)) 286 311 287 312 return … … 301 326 302 327 ''' 303 import tarfile304 328 305 329 print('Untar ...') 306 330 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)) 309 343 310 344 return … … 336 370 from genshi.template.text import NewTextTemplate 337 371 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) 351 405 352 406 return … … 382 436 from genshi.template.text import NewTextTemplate 383 437 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 388 439 389 440 if fp_root == '../': 390 441 fp_root = '$HOME' 391 442 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) 406 480 407 481 return … … 437 511 from genshi.template.text import NewTextTemplate 438 512 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 443 514 444 515 fp_root_path_to_python = os.path.join(fp_root, 445 516 _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) 460 555 461 556 return -
source/python/mods/tools.py
r96e1533 r3946de5 99 99 return None 100 100 return int(value) 101 102 def check_filepattern(filename): 103 ''' 104 ''' 105 if '.ksh' in filename: 106 return True 107 return False 108 109 101 110 102 111 def get_cmdline_arguments(): -
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 -
source/pythontest/_config_test.py
r96e1533 r3946de5 40 40 TEST_DIR = 'test' 41 41 TESTFILES_DIR = 'Testfiles' 42 42 TESTINSTALL_DIR = 'InstallTar' 43 43 # ------------------------------------------------------------------------------ 44 44 # PATHES … … 46 46 PATH_TEST_DIR = os.path.join(_config.PATH_FLEXEXTRACT_DIR, TEST_DIR) 47 47 PATH_TESTFILES_DIR = os.path.join(PATH_TEST_DIR, TESTFILES_DIR) 48 48 PATH_TESTINSTALL_DIR = os.path.join(PATH_TEST_DIR, TESTINSTALL_DIR)
Note: See TracChangeset
for help on using the changeset viewer.