@@ -1327,7 +1327,8 @@ def test_apply_patch(self):
13271327 """ Test apply_patch """
13281328 testdir = os .path .dirname (os .path .abspath (__file__ ))
13291329 tmpdir = self .test_prefix
1330- path = ft .extract_file (os .path .join (testdir , 'sandbox' , 'sources' , 'toy' , 'toy-0.0.tar.gz' ), tmpdir )
1330+ toy_tar_gz = os .path .join (testdir , 'sandbox' , 'sources' , 'toy' , 'toy-0.0.tar.gz' )
1331+ path = ft .extract_file (toy_tar_gz , tmpdir , change_into_dir = False )
13311332 toy_patch_fn = 'toy-0.0_fix-silly-typo-in-printf-statement.patch'
13321333 toy_patch = os .path .join (testdir , 'sandbox' , 'sources' , 'toy' , toy_patch_fn )
13331334
@@ -1597,19 +1598,24 @@ def test_change_dir(self):
15971598
15981599 def test_extract_file (self ):
15991600 """Test extract_file"""
1601+ cwd = os .getcwd ()
1602+
16001603 testdir = os .path .dirname (os .path .abspath (__file__ ))
16011604 toy_tarball = os .path .join (testdir , 'sandbox' , 'sources' , 'toy' , 'toy-0.0.tar.gz' )
16021605
16031606 self .assertFalse (os .path .exists (os .path .join (self .test_prefix , 'toy-0.0' , 'toy.source' )))
1604- path = ft .extract_file (toy_tarball , self .test_prefix )
1607+ path = ft .extract_file (toy_tarball , self .test_prefix , change_into_dir = False )
16051608 self .assertTrue (os .path .exists (os .path .join (self .test_prefix , 'toy-0.0' , 'toy.source' )))
16061609 self .assertTrue (os .path .samefile (path , self .test_prefix ))
1610+ # still in same directory as before if change_into_dir is set to False
1611+ self .assertTrue (os .path .samefile (os .getcwd (), cwd ))
16071612 shutil .rmtree (os .path .join (path , 'toy-0.0' ))
16081613
16091614 toy_tarball_renamed = os .path .join (self .test_prefix , 'toy_tarball' )
16101615 shutil .copyfile (toy_tarball , toy_tarball_renamed )
16111616
1612- path = ft .extract_file (toy_tarball_renamed , self .test_prefix , cmd = "tar xfvz %s" )
1617+ path = ft .extract_file (toy_tarball_renamed , self .test_prefix , cmd = "tar xfvz %s" , change_into_dir = False )
1618+ self .assertTrue (os .path .samefile (os .getcwd (), cwd ))
16131619 self .assertTrue (os .path .exists (os .path .join (self .test_prefix , 'toy-0.0' , 'toy.source' )))
16141620 self .assertTrue (os .path .samefile (path , self .test_prefix ))
16151621 shutil .rmtree (os .path .join (path , 'toy-0.0' ))
@@ -1622,17 +1628,56 @@ def test_extract_file(self):
16221628 init_config (build_options = build_options )
16231629
16241630 self .mock_stdout (True )
1625- path = ft .extract_file (toy_tarball , self .test_prefix )
1631+ path = ft .extract_file (toy_tarball , self .test_prefix , change_into_dir = False )
16261632 txt = self .get_stdout ()
16271633 self .mock_stdout (False )
1634+ self .assertTrue (os .path .samefile (os .getcwd (), cwd ))
16281635
16291636 self .assertTrue (os .path .samefile (path , self .test_prefix ))
16301637 self .assertFalse (os .path .exists (os .path .join (self .test_prefix , 'toy-0.0' )))
16311638 self .assertTrue (re .search ('running command "tar xzf .*/toy-0.0.tar.gz"' , txt ))
16321639
1633- path = ft .extract_file (toy_tarball , self .test_prefix , forced = True )
1640+ path = ft .extract_file (toy_tarball , self .test_prefix , forced = True , change_into_dir = False )
16341641 self .assertTrue (os .path .exists (os .path .join (self .test_prefix , 'toy-0.0' , 'toy.source' )))
16351642 self .assertTrue (os .path .samefile (path , self .test_prefix ))
1643+ self .assertTrue (os .path .samefile (os .getcwd (), cwd ))
1644+
1645+ build_options ['extended_dry_run' ] = False
1646+ init_config (build_options = build_options )
1647+
1648+ ft .remove_dir (os .path .join (self .test_prefix , 'toy-0.0' ))
1649+
1650+ # a deprecation warning is printed (which is an error in this context)
1651+ # if the 'change_into_dir' named argument was left unspecified
1652+ error_pattern = "extract_file function was called without specifying value for change_into_dir"
1653+ self .assertErrorRegex (EasyBuildError , error_pattern , ft .extract_file , toy_tarball , self .test_prefix )
1654+ self .allow_deprecated_behaviour ()
1655+
1656+ # make sure we're not in self.test_prefix now (checks below assumes so)
1657+ self .assertFalse (os .path .samefile (os .getcwd (), self .test_prefix ))
1658+
1659+ # by default, extract_file changes to directory in which source file was unpacked
1660+ self .mock_stderr (True )
1661+ path = ft .extract_file (toy_tarball , self .test_prefix )
1662+ stderr = self .get_stderr ().strip ()
1663+ self .mock_stderr (False )
1664+ self .assertTrue (os .path .samefile (path , self .test_prefix ))
1665+ self .assertTrue (os .path .samefile (os .getcwd (), self .test_prefix ))
1666+ regex = re .compile ("^WARNING: .*extract_file function was called without specifying value for change_into_dir" )
1667+ self .assertTrue (regex .search (stderr ), "Pattern '%s' found in: %s" % (regex .pattern , stderr ))
1668+
1669+ ft .change_dir (cwd )
1670+ self .assertFalse (os .path .samefile (os .getcwd (), self .test_prefix ))
1671+
1672+ # no deprecation warning when change_into_dir is set to True
1673+ self .mock_stderr (True )
1674+ path = ft .extract_file (toy_tarball , self .test_prefix , change_into_dir = True )
1675+ stderr = self .get_stderr ().strip ()
1676+ self .mock_stderr (False )
1677+
1678+ self .assertTrue (os .path .samefile (path , self .test_prefix ))
1679+ self .assertTrue (os .path .samefile (os .getcwd (), self .test_prefix ))
1680+ self .assertFalse (stderr )
16361681
16371682 def test_remove (self ):
16381683 """Test remove_file, remove_dir and join remove functions."""
0 commit comments