Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'description = "%s"' % descr,
"toolchain = {'name': 'dummy', 'version': 'dummy'}",
"dependencies = [('GCC', '6.4.0-2.28'), ('toy', '0.0-deps')]",
"builddependencies = [('OpenMPI', '2.1.2-GCC-6.4.0-2.28')]",
# hidden deps must be included in list of (build)deps
"hiddendependencies = [('toy', '0.0-deps'), ('OpenMPI', '2.1.2-GCC-6.4.0-2.28')]",
"modextravars = %s" % str(modextravars),
"modextrapaths = %s" % str(modextrapaths),
])
test_dir = os.path.dirname(os.path.abspath(__file__))
os.environ['MODULEPATH'] = os.path.join(test_dir, 'modules')
# test if module is generated correctly
self.writeEC()
ec = EasyConfig(self.eb_file)
eb = EasyBlock(ec)
eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
eb.check_readiness_step()
eb.make_builddir()
eb.prepare_step()
modpath = os.path.join(eb.make_module_step(), name, version)
if get_module_syntax() == 'Lua':
modpath += '.lua'
self.assertTrue(os.path.exists(modpath), "%s exists" % modpath)
# verify contents of module
txt = read_file(modpath)
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r"^#%Module", txt.split('\n')[0]))
self.assertTrue(re.search(r"^conflict\s+%s$" % name, txt, re.M))
eb['custom_key'] = "not so default"
self.assertEqual(eb['custom_key'], 'not so default')
# test if extra toolchain options are being passed
self.assertEqual(eb.toolchain.options['static'], True)
# test extra mandatory parameters
extra_vars.update({'mandatory_key': ['default', 'another mandatory key', easyconfig.MANDATORY]})
self.assertErrorRegex(EasyBuildError, r"mandatory parameters not provided",
EasyConfig, self.eb_file, extra_options=extra_vars)
self.contents += '\nmandatory_key = "value"'
self.prep()
eb = EasyConfig(self.eb_file, extra_options=extra_vars)
self.assertEqual(eb['mandatory_key'], 'value')
'[test/9.7.5]',
'name = test',
'version = 9.7.5',
'prefix = TEST_INC/..',
'[foobar/1.2.3]',
'name = foo,bar',
'version = 1.2.3, 3.2.1',
'prefix = /foo/bar',
])
write_file(metadata, metadatatxt)
build_options = {
'external_modules_metadata': parse_external_modules_metadata([metadata]),
'valid_module_classes': module_classes(),
}
init_config(build_options=build_options)
ec = EasyConfig(toy_ec)
self.assertEqual(ec.dependencies()[3]['short_mod_name'], 'foobar/1.2.3')
self.assertEqual(ec.dependencies()[3]['external_module'], True)
metadata = {
'name': ['foo', 'bar'],
'version': ['1.2.3', '3.2.1'],
'prefix': '/foo/bar',
}
self.assertEqual(ec.dependencies()[3]['external_module_metadata'], metadata)
self.assertEqual(ec.dependencies()[4]['short_mod_name'], 'test/9.7.5')
self.assertEqual(ec.dependencies()[4]['external_module'], True)
metadata = {
'name': ['test'],
'version': ['9.7.5'],
'prefix': 'TEST_INC/..',
}
def test_replaced_easyconfig_parameters(self):
"""Test handling of replaced easyconfig parameters."""
test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs', 'test_ecs')
ec = EasyConfig(os.path.join(test_ecs_dir, 't', 'toy', 'toy-0.0.eb'))
replaced_parameters = {
'license': ('license_file', '2.0'),
'makeopts': ('buildopts', '2.0'),
'premakeopts': ('prebuildopts', '2.0'),
}
for key, (newkey, ver) in replaced_parameters.items():
error_regex = "NO LONGER SUPPORTED since v%s.*'%s' is replaced by '%s'" % (ver, key, newkey)
self.assertErrorRegex(EasyBuildError, error_regex, ec.get, key)
self.assertErrorRegex(EasyBuildError, error_regex, lambda k: ec[k], key)
def foo(key):
ec[key] = 'foo'
self.assertErrorRegex(EasyBuildError, error_regex, foo, key)
def test_replaced_easyconfig_parameters(self):
"""Test handling of replaced easyconfig parameters."""
test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs')
ec = EasyConfig(os.path.join(test_ecs_dir, 'toy-0.0.eb'))
replaced_parameters = {
'license': ('license_file', '2.0'),
'makeopts': ('buildopts', '2.0'),
'premakeopts': ('prebuildopts', '2.0'),
}
for key, (newkey, ver) in replaced_parameters.items():
error_regex = "NO LONGER SUPPORTED since v%s.*'%s' is replaced by '%s'" % (ver, key, newkey)
self.assertErrorRegex(EasyBuildError, error_regex, ec.get, key)
self.assertErrorRegex(EasyBuildError, error_regex, lambda k: ec[k], key)
def foo(key):
ec[key] = 'foo'
self.assertErrorRegex(EasyBuildError, error_regex, foo, key)
def test_empty(self):
""" empty files should not parse! """
self.contents = "# empty string"
self.prep()
self.assertRaises(EasyBuildError, EasyConfig, self.eb_file)
self.assertErrorRegex(EasyBuildError, "expected a valid path", EasyConfig, "")
def test_update(self):
"""Test use of update() method for EasyConfig instances."""
toy_ebfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs', 'toy-0.0.eb')
ec = EasyConfig(toy_ebfile)
# for string values: append
ec.update('unpack_options', '--strip-components=1')
self.assertEqual(ec['unpack_options'].strip(), '--strip-components=1')
ec.update('description', "- just a test")
self.assertEqual(ec['description'].strip(), "Toy C program. - just a test")
# spaces in between multiple updates for stirng values
ec.update('configopts', 'CC="$CC"')
ec.update('configopts', 'CXX="$CXX"')
self.assertTrue(ec['configopts'].strip().endswith('CC="$CC" CXX="$CXX"'))
# for list values: extend
ec.update('patches', ['foo.patch', 'bar.patch'])
self.assertEqual(ec['patches'], ['toy-0.0_typo.patch', ('toy-extra.txt', 'toy-0.0'), 'foo.patch', 'bar.patch'])
def test_toolchain_inspection(self):
"""Test whether available toolchain inspection functionality is working."""
build_options = {
'robot_path': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs'),
'valid_module_classes': module_classes(),
}
init_config(build_options=build_options)
ec = EasyConfig(os.path.join(os.path.dirname(__file__), 'easyconfigs', 'gzip-1.5-goolf-1.4.10.eb'))
self.assertEqual(['/'.join([x['name'], x['version']]) for x in det_toolchain_compilers(ec)], ['GCC/4.7.2'])
self.assertEqual(det_toolchain_mpi(ec)['name'], 'OpenMPI')
ec = EasyConfig(os.path.join(os.path.dirname(__file__), 'easyconfigs', 'hwloc-1.6.2-GCC-4.6.4.eb'))
tc_comps = det_toolchain_compilers(ec)
self.assertEqual(['/'.join([x['name'], x['version']]) for x in tc_comps], ['GCC/4.6.4'])
self.assertEqual(det_toolchain_mpi(ec), None)
ec = EasyConfig(os.path.join(os.path.dirname(__file__), 'easyconfigs', 'toy-0.0.eb'))
self.assertEqual(det_toolchain_compilers(ec), None)
self.assertEqual(det_toolchain_mpi(ec), None)
# GCC and OpenMPI extend $MODULEPATH; hwloc is a dependency of OpenMPI.
self.contents = '\n'.join([
'easyblock = "ConfigureMake"',
'name = "pi"',
'version = "3.14"',
'homepage = "http://example.com"',
'description = "test easyconfig"',
"toolchain = {'name': 'foss', 'version': '2018a'}",
'dependencies = [',
" ('GCC', '6.4.0-2.28', '', True),"
" ('hwloc', '1.11.8', '', ('GCC', '6.4.0-2.28')),",
" ('OpenMPI', '2.1.2', '', ('GCC', '6.4.0-2.28')),"
']',
])
self.writeEC()
eb = EasyBlock(EasyConfig(self.eb_file))
eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
eb.check_readiness_step()
# toolchain must be loaded such that dependencies are accessible
self.modtool.load(['foss/2018a'])
# GCC, OpenMPI and hwloc modules should *not* be included in loads for dependencies
mod_dep_txt = eb.make_module_dep()
for mod in ['GCC/6.4.0-2.28', 'OpenMPI/2.1.2', 'hwloc/1.11.8']:
regex = re.compile('load.*%s' % mod)
self.assertFalse(regex.search(mod_dep_txt), "Pattern '%s' found in: %s" % (regex.pattern, mod_dep_txt))
"""Test det_full_module_name method of ActiveMNS."""
build_options = {
'valid_module_classes': module_classes(),
'external_modules_metadata': ConfigObj(),
}
init_config(build_options=build_options)
ec_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'toy-0.0-deps.eb')
ec = EasyConfig(ec_file)
self.assertEqual(ActiveMNS().det_full_module_name(ec), 'toy/0.0-deps')
self.assertEqual(ActiveMNS().det_full_module_name(ec['dependencies'][0]), 'ictce/4.1.13')
self.assertEqual(ActiveMNS().det_full_module_name(ec['dependencies'][1]), 'GCC/4.7.2')
ec_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'gzip-1.4-GCC-4.6.3.eb')
ec = EasyConfig(ec_file)
hiddendep = ec['hiddendependencies'][0]
self.assertEqual(ActiveMNS().det_full_module_name(hiddendep), 'toy/.0.0-deps')
self.assertEqual(ActiveMNS().det_full_module_name(hiddendep, force_visible=True), 'toy/0.0-deps')