3131import os
3232import re
3333import shutil
34+ import stat
3435import sys
3536import tempfile
3637from distutils .version import LooseVersion
5051from easybuild .tools .config import DEFAULT_MODULECLASSES
5152from easybuild .tools .config import find_last_log , get_build_log_path , get_module_syntax , module_classes
5253from easybuild .tools .environment import modify_env
53- from easybuild .tools .filetools import change_dir , copy_dir , copy_file , download_file , is_patch_file , mkdir
54- from easybuild .tools .filetools import parse_http_header_fields_urlpat , read_file , remove_dir , remove_file
55- from easybuild .tools .filetools import which , write_file
54+ from easybuild .tools .filetools import adjust_permissions , change_dir , copy_dir , copy_file , download_file
55+ from easybuild .tools .filetools import is_patch_file , mkdir , move_file , parse_http_header_fields_urlpat
56+ from easybuild .tools .filetools import read_file , remove_dir , remove_file , which , write_file
5657from easybuild .tools .github import GITHUB_RAW , GITHUB_EB_MAIN , GITHUB_EASYCONFIGS_REPO
5758from easybuild .tools .github import URL_SEPARATOR , fetch_github_token
5859from easybuild .tools .modules import Lmod
@@ -1105,11 +1106,14 @@ def test_show_ec(self):
11051106 regex = re .compile (pattern , re .M )
11061107 self .assertTrue (regex .search (stdout ), "Pattern '%s' found in: %s" % (regex .pattern , stdout ))
11071108
1108- def mocked_main (self , args ):
1109+ def mocked_main (self , args , ** kwargs ):
11091110 """Run eb_main with mocked stdout/stderr."""
1111+ if not kwargs :
1112+ kwargs = {'raise_error' : True }
1113+
11101114 self .mock_stderr (True )
11111115 self .mock_stdout (True )
1112- self .eb_main (args , raise_error = True )
1116+ self .eb_main (args , ** kwargs )
11131117 stderr , stdout = self .get_stderr (), self .get_stdout ()
11141118 self .mock_stderr (False )
11151119 self .mock_stdout (False )
@@ -5867,15 +5871,8 @@ def test_sanity_check_only(self):
58675871
58685872 args = [test_ec , '--sanity-check-only' ]
58695873
5870- self .mock_stdout (True )
5871- self .mock_stderr (True )
5872- self .eb_main (args + ['--trace' ], do_build = True , raise_error = True , testing = False )
5873- stdout = self .get_stdout ().strip ()
5874- stderr = self .get_stderr ().strip ()
5875- self .mock_stdout (False )
5876- self .mock_stderr (False )
5874+ stdout = self .mocked_main (args + ['--trace' ], do_build = True , raise_error = True , testing = False )
58775875
5878- self .assertFalse (stderr )
58795876 skipped = [
58805877 "fetching files" ,
58815878 "creating build dir, resetting environment" ,
@@ -5910,10 +5907,12 @@ def test_sanity_check_only(self):
59105907 for msg in msgs :
59115908 self .assertTrue (msg in stdout , "'%s' found in: %s" % (msg , stdout ))
59125909
5910+ ebroottoy = os .path .join (self .test_installpath , 'software' , 'toy' , '0.0' )
5911+
59135912 # check if sanity check for extension fails if a file provided by that extension,
5914- # which is checked by the sanity check for that extension, is removed
5915- libbarbar = os .path .join (self . test_installpath , 'software' , 'toy' , '0.0' , 'lib' , 'libbarbar.a' )
5916- remove_file (libbarbar )
5913+ # which is checked by the sanity check for that extension, is no longer there
5914+ libbarbar = os .path .join (ebroottoy , 'lib' , 'libbarbar.a' )
5915+ move_file (libbarbar , libbarbar + '.moved' )
59175916
59185917 outtxt , error_thrown = self .eb_main (args + ['--debug' ], do_build = True , return_error = True )
59195918 error_msg = str (error_thrown )
@@ -5929,6 +5928,15 @@ def test_sanity_check_only(self):
59295928 outtxt = self .eb_main (args + ['--skip-extensions' ], do_build = True , raise_error = True )
59305929 self .assertTrue ("Sanity check for toy successful" in outtxt )
59315930
5931+ # restore fail, we want a passing sanity check for the next check
5932+ move_file (libbarbar + '.moved' , libbarbar )
5933+
5934+ # check use of --sanity-check-only when installation directory is read-only;
5935+ # cfr. https://github.com/easybuilders/easybuild-framework/issues/3757
5936+ adjust_permissions (ebroottoy , stat .S_IWUSR | stat .S_IWGRP | stat .S_IWOTH , add = False , recursive = True )
5937+
5938+ stdout = self .mocked_main (args + ['--trace' ], do_build = True , raise_error = True , testing = False )
5939+
59325940 def test_skip_extensions (self ):
59335941 """Test use of --skip-extensions."""
59345942 topdir = os .path .abspath (os .path .dirname (__file__ ))
0 commit comments