@@ -1480,6 +1480,110 @@ def test_fetch_sources(self):
14801480 error_pattern = "Found one or more unexpected keys in 'sources' specification: {'nosuchkey': 'foobar'}"
14811481 self .assertErrorRegex (EasyBuildError , error_pattern , eb .fetch_sources , sources , checksums = [])
14821482
1483+ def test_download_instructions (self ):
1484+ """Test use of download_instructions easyconfig parameter."""
1485+ orig_test_ec = '\n ' .join ([
1486+ "easyblock = 'ConfigureMake'" ,
1487+ "name = 'software_with_missing_sources'" ,
1488+ "version = '0.0'" ,
1489+ "homepage = 'https://example.com'" ,
1490+ "description = 'test'" ,
1491+ "toolchain = SYSTEM" ,
1492+ "sources = [SOURCE_TAR_GZ]" ,
1493+ "exts_list = [" ,
1494+ " ('ext_with_missing_sources', '0.0', {" ,
1495+ " 'sources': [SOURCE_TAR_GZ]," ,
1496+ " })," ,
1497+ "]" ,
1498+ ])
1499+ self .contents = orig_test_ec
1500+ self .writeEC ()
1501+ eb = EasyBlock (EasyConfig (self .eb_file ))
1502+
1503+ common_error_pattern = "^Couldn't find file software_with_missing_sources-0.0.tar.gz anywhere"
1504+ error_pattern = common_error_pattern + ", and downloading it didn't work either"
1505+ self .assertErrorRegex (EasyBuildError , error_pattern , eb .fetch_step )
1506+
1507+ download_instructions = "download_instructions = 'Manual download from example.com required'"
1508+ sources = "sources = [SOURCE_TAR_GZ]"
1509+ self .contents = self .contents .replace (sources , download_instructions + '\n ' + sources )
1510+ self .writeEC ()
1511+ eb = EasyBlock (EasyConfig (self .eb_file ))
1512+
1513+ error_pattern = common_error_pattern + ", please follow the download instructions above"
1514+ self .mock_stderr (True )
1515+ self .mock_stdout (True )
1516+ self .assertErrorRegex (EasyBuildError , error_pattern , eb .fetch_step )
1517+ stderr = self .get_stderr ().strip ()
1518+ stdout = self .get_stdout ().strip ()
1519+ self .mock_stderr (False )
1520+ self .mock_stdout (False )
1521+ self .assertEqual (stderr , "Download instructions:\n \n Manual download from example.com required" )
1522+ self .assertEqual (stdout , '' )
1523+
1524+ # create dummy source file
1525+ write_file (os .path .join (os .path .dirname (self .eb_file ), 'software_with_missing_sources-0.0.tar.gz' ), '' )
1526+
1527+ # now downloading of sources for extension should fail
1528+ # top-level download instructions are printed (because there's nothing else)
1529+ error_pattern = "^Couldn't find file ext_with_missing_sources-0.0.tar.gz anywhere"
1530+ self .mock_stderr (True )
1531+ self .mock_stdout (True )
1532+ self .assertErrorRegex (EasyBuildError , error_pattern , eb .fetch_step )
1533+ stderr = self .get_stderr ().strip ()
1534+ stdout = self .get_stdout ().strip ()
1535+ self .mock_stderr (False )
1536+ self .mock_stdout (False )
1537+ self .assertEqual (stderr , "Download instructions:\n \n Manual download from example.com required" )
1538+ self .assertEqual (stdout , '' )
1539+
1540+ # wipe top-level download instructions, try again
1541+ self .contents = self .contents .replace (download_instructions , '' )
1542+ self .writeEC ()
1543+ eb = EasyBlock (EasyConfig (self .eb_file ))
1544+
1545+ # no download instructions printed anymore now
1546+ self .mock_stderr (True )
1547+ self .mock_stdout (True )
1548+ self .assertErrorRegex (EasyBuildError , error_pattern , eb .fetch_step )
1549+ stderr = self .get_stderr ().strip ()
1550+ stdout = self .get_stdout ().strip ()
1551+ self .mock_stderr (False )
1552+ self .mock_stdout (False )
1553+ self .assertEqual (stdout , '' )
1554+
1555+ # inject download instructions for extension
1556+ download_instructions = ' ' * 8 + "'download_instructions': "
1557+ download_instructions += "'Extension sources must be downloaded via example.com',"
1558+ sources = "'sources': [SOURCE_TAR_GZ],"
1559+ self .contents = self .contents .replace (sources , sources + '\n ' + download_instructions )
1560+ self .writeEC ()
1561+ eb = EasyBlock (EasyConfig (self .eb_file ))
1562+
1563+ self .mock_stderr (True )
1564+ self .mock_stdout (True )
1565+ self .assertErrorRegex (EasyBuildError , error_pattern , eb .fetch_step )
1566+ stderr = self .get_stderr ().strip ()
1567+ stdout = self .get_stdout ().strip ()
1568+ self .mock_stderr (False )
1569+ self .mock_stdout (False )
1570+ self .assertEqual (stderr , "Download instructions:\n \n Extension sources must be downloaded via example.com" )
1571+ self .assertEqual (stdout , '' )
1572+
1573+ # create dummy source file for extension
1574+ write_file (os .path .join (os .path .dirname (self .eb_file ), 'ext_with_missing_sources-0.0.tar.gz' ), '' )
1575+
1576+ # no more errors, all source files found (so no download instructions printed either)
1577+ self .mock_stderr (True )
1578+ self .mock_stdout (True )
1579+ eb .fetch_step ()
1580+ stderr = self .get_stderr ().strip ()
1581+ stdout = self .get_stdout ().strip ()
1582+ self .mock_stderr (False )
1583+ self .mock_stdout (False )
1584+ self .assertEqual (stderr , '' )
1585+ self .assertEqual (stdout , '' )
1586+
14831587 def test_fetch_patches (self ):
14841588 """Test fetch_patches method."""
14851589 testdir = os .path .abspath (os .path .dirname (__file__ ))
0 commit comments