From 49c3a6b8668584eb19f32e11544381a755ca257a Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Thu, 2 Feb 2023 10:54:06 +0100 Subject: [PATCH 1/3] Replace more usages of assertTrue/False --- easybuild/base/testing.py | 13 ++ test/framework/build_log.py | 18 +-- test/framework/config.py | 10 +- test/framework/containers.py | 6 +- test/framework/easyblock.py | 50 ++++---- test/framework/easyconfig.py | 38 +++--- test/framework/easyconfigparser.py | 6 +- test/framework/filetools.py | 191 +++++++++++++++-------------- test/framework/github.py | 14 +-- test/framework/hooks.py | 4 +- test/framework/include.py | 6 +- test/framework/lib.py | 4 +- test/framework/license.py | 2 +- test/framework/modules.py | 18 +-- test/framework/modulestool.py | 2 +- test/framework/options.py | 108 ++++++++-------- test/framework/output.py | 14 +-- test/framework/parallelbuild.py | 12 +- test/framework/repository.py | 8 +- test/framework/robot.py | 6 +- test/framework/run.py | 4 +- test/framework/systemtools.py | 29 +++-- test/framework/toolchain.py | 18 +-- test/framework/toy_build.py | 171 +++++++++++++------------- 24 files changed, 382 insertions(+), 370 deletions(-) diff --git a/easybuild/base/testing.py b/easybuild/base/testing.py index d81e83c8df..01b64d84ef 100644 --- a/easybuild/base/testing.py +++ b/easybuild/base/testing.py @@ -34,6 +34,7 @@ * Kenneth Hoste (Ghent University) """ import difflib +import os import pprint import re import sys @@ -117,6 +118,18 @@ def assertEqual(self, a, b, msg=None): raise AssertionError("%s:\nDIFF%s:\n%s" % (msg, limit, ''.join(diff[:self.ASSERT_MAX_DIFF]))) + def assertExists(self, path, msg=None): + """Assert the given path exists""" + if msg is None: + msg = "'%s' should exist" % path + self.assertTrue(os.path.exists(path), msg) + + def assertNotExists(self, path, msg=None): + """Assert the given path exists""" + if msg is None: + msg = "'%s' should not exist" % path + self.assertFalse(os.path.exists(path), msg) + def setUp(self): """Prepare test case.""" super(TestCase, self).setUp() diff --git a/test/framework/build_log.py b/test/framework/build_log.py index 588246f513..a1792b998f 100644 --- a/test/framework/build_log.py +++ b/test/framework/build_log.py @@ -388,26 +388,26 @@ def test_init_logging(self): tmp_logfile = os.path.join(self.test_prefix, 'test.log') log, logfile = init_logging(tmp_logfile, silent=True) self.assertEqual(logfile, tmp_logfile) - self.assertTrue(os.path.exists(logfile)) - self.assertTrue(isinstance(log, EasyBuildLog)) + self.assertExists(logfile) + self.assertIsInstance(log, EasyBuildLog) stop_logging(logfile) # no log provided, so create one (should be file in $TMPDIR) log, logfile = init_logging(None, silent=True) - self.assertTrue(os.path.exists(logfile)) + self.assertExists(logfile) self.assertEqual(os.path.dirname(logfile), tmpdir) - self.assertTrue(isinstance(log, EasyBuildLog)) + self.assertIsInstance(log, EasyBuildLog) stop_logging(logfile) # no problem with specifying a different directory to put log file in (even if it doesn't exist yet) tmp_logdir = os.path.join(self.test_prefix, 'tmp_logs') - self.assertFalse(os.path.exists(tmp_logdir)) + self.assertNotExists(tmp_logdir) log, logfile = init_logging(None, silent=True, tmp_logdir=tmp_logdir) self.assertEqual(os.path.dirname(logfile), tmp_logdir) - self.assertTrue(isinstance(log, EasyBuildLog)) + self.assertIsInstance(log, EasyBuildLog) stop_logging(logfile) @@ -416,9 +416,9 @@ def test_init_logging(self): log, logfile = init_logging(None) stdout = self.get_stdout() self.mock_stdout(False) - self.assertTrue(os.path.exists(logfile)) + self.assertExists(logfile) self.assertEqual(os.path.dirname(logfile), tmpdir) - self.assertTrue(isinstance(log, EasyBuildLog)) + self.assertIsInstance(log, EasyBuildLog) self.assertTrue(stdout.startswith("== Temporary log file in case of crash")) stop_logging(logfile) @@ -428,7 +428,7 @@ def test_init_logging(self): log, logfile = init_logging(None, logtostdout=True) self.mock_stdout(False) self.assertEqual(logfile, None) - self.assertTrue(isinstance(log, EasyBuildLog)) + self.assertIsInstance(log, EasyBuildLog) stop_logging(logfile, logtostdout=True) diff --git a/test/framework/config.py b/test/framework/config.py index e3bc7f8780..4b42672cfc 100644 --- a/test/framework/config.py +++ b/test/framework/config.py @@ -341,8 +341,8 @@ def test_configuration_variables(self): cv1 = ConfigurationVariables() cv2 = ConfigurationVariables() cv3 = ConfigurationVariables({'foo': 'bar'}) # note: argument is ignored, an instance is already available - self.assertTrue(cv1 is cv2) - self.assertTrue(cv1 is cv3) + self.assertIs(cv1, cv2) + self.assertIs(cv1, cv3) def test_build_options(self): """Test usage of BuildOptions.""" @@ -353,8 +353,8 @@ def test_build_options(self): bo1 = BuildOptions() bo2 = BuildOptions() bo3 = BuildOptions({'foo': 'bar'}) # note: argument is ignored, an instance is already available - self.assertTrue(bo1 is bo2) - self.assertTrue(bo1 is bo3) + self.assertIs(bo1, bo2) + self.assertIs(bo1, bo3) # test basic functionality BuildOptions.__class__._instances.clear() @@ -394,7 +394,7 @@ def test_build_options(self): # there should be only one BuildOptions instance bo2 = BuildOptions() - self.assertTrue(bo is bo2) + self.assertIs(bo, bo2) def test_XDG_CONFIG_env_vars(self): """Test effect of XDG_CONFIG* environment variables on default configuration.""" diff --git a/test/framework/containers.py b/test/framework/containers.py index dcff27d640..bd6dfde7f6 100644 --- a/test/framework/containers.py +++ b/test/framework/containers.py @@ -308,7 +308,7 @@ def test_end2end_singularity_image(self): ] self.check_regexs(regexs, stdout) - self.assertTrue(os.path.exists(os.path.join(containerpath, 'toy-0.0.%s' % ext))) + self.assertExists(os.path.join(containerpath, 'toy-0.0.%s' % ext)) remove_file(os.path.join(containerpath, 'Singularity.toy-0.0')) @@ -330,7 +330,7 @@ def test_end2end_singularity_image(self): self.check_regexs(regexs, stdout) cont_img = os.path.join(containerpath, 'foo-bar.img') - self.assertTrue(os.path.exists(cont_img)) + self.assertExists(cont_img) remove_file(os.path.join(containerpath, 'Singularity.foo-bar')) @@ -348,7 +348,7 @@ def test_end2end_singularity_image(self): "WARNING: overwriting existing container image at %s due to --force" % cont_img, ]) self.check_regexs(regexs, stdout) - self.assertTrue(os.path.exists(cont_img)) + self.assertExists(cont_img) # also check behaviour under --extended-dry-run args.append('--extended-dry-run') diff --git a/test/framework/easyblock.py b/test/framework/easyblock.py index 0eeef89272..073337514b 100644 --- a/test/framework/easyblock.py +++ b/test/framework/easyblock.py @@ -85,12 +85,12 @@ def check_extra_options_format(extra_options): """Make sure extra_options value is of correct format.""" # EasyBuild v2.0: dict with keys and values # (breaks backward compatibility compared to v1.x) - self.assertTrue(isinstance(extra_options, dict)) # conversion to a dict works + self.assertIsInstance(extra_options, dict) # conversion to a dict works extra_options.items() extra_options.keys() extra_options.values() for key in extra_options.keys(): - self.assertTrue(isinstance(extra_options[key], list)) + self.assertIsInstance(extra_options[key], list) self.assertEqual(len(extra_options[key]), 3) name = "pi" @@ -201,7 +201,7 @@ def test_load_module(self): # we expect $TMPDIR to be tweaked by the prepare step (OpenMPI 2.x doesn't like long $TMPDIR values) tweaked_tmpdir = os.environ.get('TMPDIR') - self.assertTrue(tweaked_tmpdir != orig_tmpdir) + self.assertNotEqual(tweaked_tmpdir, orig_tmpdir) eb.make_module_step() eb.load_module() @@ -233,7 +233,7 @@ def test_fake_module_load(self): if get_module_syntax() == 'Lua': pi_modfile += '.lua' - self.assertTrue(os.path.exists(pi_modfile)) + self.assertExists(pi_modfile) # check whether temporary module file is marked as default if get_module_syntax() == 'Lua': @@ -667,7 +667,7 @@ def test_make_module_extra(self): if get_module_syntax() == 'Lua': modpath += '.lua' - self.assertTrue(os.path.exists(modpath), "%s exists" % modpath) + self.assertExists(modpath) txt = read_file(modpath) patterns = [ r"^prepend[-_]path.*TEST_PATH_VAR.*root.*foo", @@ -1202,7 +1202,7 @@ def test_make_module_step(self): 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) + self.assertExists(modpath) # verify contents of module txt = read_file(modpath) @@ -1373,13 +1373,13 @@ def test_make_builddir(self): builddir = eb.builddir testfile = os.path.join(builddir, 'test123', 'foobar.txt') write_file(testfile, 'test123') - self.assertTrue(os.path.exists(testfile)) + self.assertExists(testfile) eb.make_builddir() self.assertEqual(builddir, eb.builddir) # file is gone because directory was removed and re-created - self.assertFalse(os.path.exists(testfile)) - self.assertFalse(os.path.exists(os.path.dirname(testfile))) + self.assertNotExists(testfile) + self.assertNotExists(os.path.dirname(testfile)) self.assertEqual(os.listdir(eb.builddir), []) # make sure that build directory does *not* get re-created when we're building in installation directory @@ -1391,7 +1391,7 @@ def test_make_builddir(self): builddir = eb.builddir testfile = os.path.join(builddir, 'test123', 'foobar.txt') write_file(testfile, 'test123') - self.assertTrue(os.path.exists(testfile)) + self.assertExists(testfile) self.assertEqual(os.listdir(eb.builddir), ['test123']) self.assertEqual(os.listdir(os.path.join(eb.builddir, 'test123')), ['foobar.txt']) @@ -1400,7 +1400,7 @@ def test_make_builddir(self): eb.make_builddir() eb.make_installdir() self.assertEqual(builddir, eb.builddir) - self.assertTrue(os.path.exists(testfile)) + self.assertExists(testfile) self.assertEqual(os.listdir(eb.builddir), ['test123']) self.assertEqual(os.listdir(os.path.join(eb.builddir, 'test123')), ['foobar.txt']) @@ -1409,8 +1409,8 @@ def test_make_builddir(self): eb.make_builddir() eb.make_installdir() self.assertEqual(builddir, eb.builddir) - self.assertFalse(os.path.exists(testfile)) - self.assertFalse(os.path.exists(os.path.dirname(testfile))) + self.assertNotExists(testfile) + self.assertNotExists(os.path.dirname(testfile)) self.assertEqual(os.listdir(eb.builddir), []) def test_get_easyblock_instance(self): @@ -1420,7 +1420,7 @@ def test_get_easyblock_instance(self): ec = process_easyconfig(os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb'))[0] eb = get_easyblock_instance(ec) - self.assertTrue(isinstance(eb, EB_toy)) + self.assertIsInstance(eb, EB_toy) # check whether 'This is easyblock' log message is there tup = ('EB_toy', 'easybuild.easyblocks.toy', '.*test/framework/sandbox/easybuild/easyblocks/t/toy.pyc*') @@ -1482,9 +1482,9 @@ def test_fetch_sources(self): self.assertEqual(len(eb.src), 3) for idx in range(3): self.assertEqual(eb.src[idx]['name'], expected_sources[idx]) - self.assertTrue(os.path.exists(eb.src[idx]['path'])) + self.assertExists(eb.src[idx]['path']) source_loc = os.path.join(toy_source_dir, expected_sources[idx]) - self.assertTrue(os.path.exists(source_loc)) + self.assertExists(source_loc) self.assertTrue(os.path.samefile(eb.src[idx]['path'], source_loc)) self.assertEqual(eb.src[0]['cmd'], None) self.assertEqual(eb.src[1]['cmd'], "gunzip %s") @@ -1750,7 +1750,7 @@ def test_obtain_file(self): # toy tarball was indeed re-downloaded to tmpdir self.assertEqual(res, os.path.join(tmpdir, 't', 'toy', toy_tarball)) - self.assertTrue(os.path.exists(os.path.join(tmpdir, 't', 'toy', toy_tarball))) + self.assertExists(os.path.join(tmpdir, 't', 'toy', toy_tarball)) # obtain_file yields error for non-existing files fn = 'thisisclearlyanonexistingfile' @@ -1783,7 +1783,7 @@ def test_obtain_file(self): if res is not None: loc = os.path.join(tmpdir, 't', 'toy', fn) self.assertEqual(res, loc) - self.assertTrue(os.path.exists(loc), "%s file is found at %s" % (fn, loc)) + self.assertExists(loc), "%s file is found at %s" % (fn, loc) txt = read_file(loc) eb_regex = re.compile("EasyBuild: building software with ease") self.assertTrue(eb_regex.search(txt), "Pattern '%s' found in: %s" % (eb_regex.pattern, txt)) @@ -1833,7 +1833,7 @@ def test_collect_exts_file_info(self): exts_file_info = toy_eb.collect_exts_file_info() - self.assertTrue(isinstance(exts_file_info, list)) + self.assertIsInstance(exts_file_info, list) self.assertEqual(len(exts_file_info), 4) self.assertEqual(exts_file_info[0], {'name': 'ls'}) @@ -1858,7 +1858,7 @@ def test_collect_exts_file_info(self): # location of files is missing when fetch_files is set to False exts_file_info = toy_eb.collect_exts_file_info(fetch_files=False, verify_checksums=False) - self.assertTrue(isinstance(exts_file_info, list)) + self.assertIsInstance(exts_file_info, list) self.assertEqual(len(exts_file_info), 4) self.assertEqual(exts_file_info[0], {'name': 'ls'}) @@ -1897,7 +1897,7 @@ def test_obtain_file_extension(self): ext = ExtensionEasyBlock(toy_eb, test_ext) ext_src_path = ext.obtain_file(test_ext_src_fn) self.assertEqual(os.path.basename(ext_src_path), 'toy-0.0.tar.gz') - self.assertTrue(os.path.exists(ext_src_path)) + self.assertExists(ext_src_path) def test_check_readiness(self): """Test check_readiness method.""" @@ -2135,7 +2135,7 @@ def test_guess_start_dir(self): ec = process_easyconfig(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'))[0] cwd = os.getcwd() - self.assertTrue(os.path.exists(cwd)) + self.assertExists(cwd) def check_start_dir(expected_start_dir): """Check start dir.""" @@ -2170,7 +2170,7 @@ def test_extension_set_start_dir(self): ec = process_easyconfig(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'))[0] cwd = os.getcwd() - self.assertTrue(os.path.exists(cwd)) + self.assertExists(cwd) def check_ext_start_dir(expected_start_dir): """Check start dir.""" @@ -2608,8 +2608,8 @@ def run_checks(): def test_this_is_easybuild(self): """Test 'this_is_easybuild' function (and get_git_revision function used by it).""" # make sure both return a non-Unicode string - self.assertTrue(isinstance(get_git_revision(), str)) - self.assertTrue(isinstance(this_is_easybuild(), str)) + self.assertIsInstance(get_git_revision(), str) + self.assertIsInstance(this_is_easybuild(), str) def test_stale_module_caches(self): """Test whether module caches are reset between builds.""" diff --git a/test/framework/easyconfig.py b/test/framework/easyconfig.py index 4a6de50085..3c9577c7f7 100644 --- a/test/framework/easyconfig.py +++ b/test/framework/easyconfig.py @@ -231,7 +231,7 @@ def test_system_toolchain_constant(self): self.prep() eb = EasyConfig(self.eb_file) self.assertEqual(eb['toolchain'], {'name': 'system', 'version': 'system'}) - self.assertTrue(isinstance(eb.toolchain, SystemToolchain)) + self.assertIsInstance(eb.toolchain, SystemToolchain) def test_shlib_ext(self): """ inside easyconfigs shared_lib_ext should be set """ @@ -593,8 +593,8 @@ def test_extensions_templates(self): self.assertEqual(toy_ext.cfg['prebuildopts'], expected_prebuildopts) # check whether files expected to be installed for 'toy' extension are in place - self.assertTrue(os.path.exists(os.path.join(pi_installdir, 'bin', 'toy'))) - self.assertTrue(os.path.exists(os.path.join(pi_installdir, 'lib', 'libtoy.a'))) + self.assertExists(os.path.join(pi_installdir, 'bin', 'toy')) + self.assertExists(os.path.join(pi_installdir, 'lib', 'libtoy.a')) def test_suggestions(self): """ If a typo is present, suggestions should be provided (if possible) """ @@ -688,9 +688,9 @@ def test_tweaking(self): self.assertEqual(eb['versionsuffix'], versuff) self.assertEqual(eb['toolchain']['version'], tcver) self.assertEqual(eb['patches'], new_patches) - self.assertTrue(eb['runtest'] is False) - self.assertTrue(eb['hidden'] is True) - self.assertTrue(eb['parallel'] is None) + self.assertIs(eb['runtest'], False) + self.assertIs(eb['hidden'], True) + self.assertIsNone(eb['parallel']) self.assertEqual(eb['test_none'], 'False') self.assertEqual(eb['test_bool'], 'True') self.assertEqual(eb['test_123'], 'None') @@ -2237,14 +2237,14 @@ def test_toolchain_hierarchy_aware_dump(self): ectxt = read_file(test_ec) dumped_ec = EasyConfig(test_ec) self.assertEqual(ecdict, dumped_ec.asdict()) - self.assertTrue(r"'toy', '0.0')," in ectxt) + self.assertIn("'toy', '0.0'),", ectxt) # test case where we ask for explicit toolchains ec.dump(test_ec, explicit_toolchains=True) self.assertEqual(ecdict, ec.asdict()) ectxt = read_file(test_ec) dumped_ec = EasyConfig(test_ec) self.assertEqual(ecdict, dumped_ec.asdict()) - self.assertTrue(r"'toy', '0.0', '', ('gompi', '2018a'))," in ectxt) + self.assertIn("'toy', '0.0', '', ('gompi', '2018a')),", ectxt) def test_dump_order(self): """Test order of easyconfig parameters in dumped easyconfig.""" @@ -2985,7 +2985,7 @@ def test_software_license(self): # constant GPLv3 is resolved as string self.assertEqual(ec['software_license'], 'LicenseGPLv3') # software_license is defined as License subclass - self.assertTrue(isinstance(ec.software_license, LicenseGPLv3)) + self.assertIsInstance(ec.software_license, LicenseGPLv3) self.assertTrue(issubclass(ec.software_license.__class__, License)) ec['software_license'] = 'LicenseThatDoesNotExist' @@ -3029,7 +3029,7 @@ def test_eq_hash(self): ec2 = EasyConfig(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb')) # different instances, same parsed easyconfig - self.assertFalse(ec1 is ec2) + self.assertIsNot(ec1, ec2) self.assertEqual(ec1, ec2) self.assertTrue(ec1 == ec2) self.assertFalse(ec1 != ec2) @@ -3083,7 +3083,7 @@ def test_copy_easyconfigs(self): for orig_ec, src_ec in test_ecs: orig_ec = os.path.basename(orig_ec) copied_ec = os.path.join(ecs_target_dir, orig_ec[0].lower(), orig_ec.split('-')[0], orig_ec) - self.assertTrue(os.path.exists(copied_ec), "File %s exists" % copied_ec) + self.assertExists(copied_ec) self.assertEqual(read_file(copied_ec), read_file(os.path.join(self.test_prefix, src_ec))) # create test easyconfig that includes comments & build stats, just like an archived easyconfig @@ -3663,7 +3663,7 @@ def test_get_paths_for(self): os.environ['EB_SCRIPT_PATH'] = eb_symlink res = get_paths_for(subdir='easyconfigs', robot_path=None) - self.assertTrue(os.path.exists(res[0])) + self.assertExists(res[0]) self.assertTrue(os.path.samefile(res[0], os.path.join(someprefix, 'easybuild', 'easyconfigs'))) # Finally restore EB_SCRIPT_PATH value if set @@ -3866,7 +3866,7 @@ def test_multi_deps(self): # builddependencies should now be a non-empty list of lists, each with one entry corresponding to a GCC version builddeps = ec['builddependencies'] self.assertTrue(builddeps) - self.assertTrue(isinstance(builddeps, list)) + self.assertIsInstance(builddeps, list) self.assertEqual(len(builddeps), 3) self.assertTrue(all(isinstance(bd, list) for bd in builddeps)) self.assertTrue(all(len(bd) == 1 for bd in builddeps)) @@ -3875,7 +3875,7 @@ def test_multi_deps(self): # get_parsed_multi_deps() method basically returns same list multi_deps = ec.get_parsed_multi_deps() - self.assertTrue(isinstance(multi_deps, list)) + self.assertIsInstance(multi_deps, list) self.assertEqual(len(multi_deps), 3) self.assertTrue(all(isinstance(bd, list) for bd in multi_deps)) self.assertTrue(all(len(bd) == 1 for bd in multi_deps)) @@ -3887,7 +3887,7 @@ def test_multi_deps(self): ec = EasyConfig(test_ec) builddeps = ec['builddependencies'] self.assertTrue(builddeps) - self.assertTrue(isinstance(builddeps, list)) + self.assertIsInstance(builddeps, list) self.assertEqual(len(builddeps), 3) self.assertTrue(all(isinstance(bd, list) for bd in builddeps)) self.assertTrue(all(len(bd) == 3 for bd in builddeps)) @@ -3902,7 +3902,7 @@ def test_multi_deps(self): # get_parsed_multi_deps() method returns same list, but CMake & foo are not included multi_deps = ec.get_parsed_multi_deps() - self.assertTrue(isinstance(multi_deps, list)) + self.assertIsInstance(multi_deps, list) self.assertEqual(len(multi_deps), 3) self.assertTrue(all(isinstance(bd, list) for bd in multi_deps)) self.assertTrue(all(len(bd) == 1 for bd in multi_deps)) @@ -3939,7 +3939,7 @@ def test_multi_deps_templated_builddeps(self): builddeps = ec['builddependencies'] - self.assertTrue(isinstance(builddeps, list)) + self.assertIsInstance(builddeps, list) self.assertEqual(len(builddeps), 2) self.assertTrue(all(isinstance(bd, dict) for bd in builddeps)) @@ -4747,7 +4747,7 @@ def test_easyconfigs_caches(self): ec1 = process_easyconfig(toy_ec)[0] self.assertEqual(ec1['ec'].name, 'toy') self.assertEqual(ec1['ec'].version, '0.0') - self.assertTrue(isinstance(ec1['ec'].toolchain, SystemToolchain)) + self.assertIsInstance(ec1['ec'].toolchain, SystemToolchain) self.assertTrue(os.path.samefile(ec1['ec'].path, toy_ec)) # wipe toy easyconfig (but path still needs to exist) @@ -4757,7 +4757,7 @@ def test_easyconfigs_caches(self): ec2 = process_easyconfig(toy_ec)[0] self.assertEqual(ec2['ec'].name, 'toy') self.assertEqual(ec2['ec'].version, '0.0') - self.assertTrue(isinstance(ec2['ec'].toolchain, SystemToolchain)) + self.assertIsInstance(ec2['ec'].toolchain, SystemToolchain) self.assertTrue(os.path.samefile(ec2['ec'].path, toy_ec)) # also check whether easyconfigs cache works with end-to-end test diff --git a/test/framework/easyconfigparser.py b/test/framework/easyconfigparser.py index 550330d021..fbe8c6958c 100644 --- a/test/framework/easyconfigparser.py +++ b/test/framework/easyconfigparser.py @@ -136,7 +136,7 @@ def test_v20_deps(self): # dependencies should be parsed correctly deps = ec['dependencies'] - self.assertTrue(isinstance(deps[0], Dependency)) + self.assertIsInstance(deps[0], Dependency) self.assertEqual(deps[0].name(), 'zlib') self.assertEqual(deps[0].version(), '1.2.5') @@ -198,11 +198,11 @@ def test_easyconfig_constants(self): # make sure both keys and values are of appropriate types for constant_name in constants: - self.assertTrue(isinstance(constant_name, string_type), "Constant name %s is a string" % constant_name) + self.assertIsInstance(constant_name, string_type) val = constants[constant_name] fail_msg = "The constant %s should have an acceptable type, found %s (%s)" % (constant_name, type(val), str(val)) - self.assertTrue(isinstance(val, (string_type, dict, tuple)), fail_msg) + self.assertIsInstance(val, (string_type, dict, tuple), fail_msg) # check a couple of randomly picked constant values self.assertEqual(constants['SOURCE_TAR_GZ'], '%(name)s-%(version)s.tar.gz') diff --git a/test/framework/filetools.py b/test/framework/filetools.py index 92aa7fab96..c8b230fe3d 100644 --- a/test/framework/filetools.py +++ b/test/framework/filetools.py @@ -229,9 +229,9 @@ def test_which(self): invalid_cmd = 'i_really_do_not_expect_a_command_with_a_name_like_this_to_be_available' path = ft.which(invalid_cmd) - self.assertTrue(path is None) + self.assertIsNone(path) path = ft.which(invalid_cmd, on_error=IGNORE) - self.assertTrue(path is None) + self.assertIsNone(path) error_msg = "Could not find command '%s'" % invalid_cmd self.assertErrorRegex(EasyBuildError, error_msg, ft.which, invalid_cmd, on_error=ERROR) @@ -487,11 +487,11 @@ def test_download_file(self): self.mock_stdout(False) self.assertEqual(path, target_location) - self.assertFalse(os.path.exists(target_location)) + self.assertNotExists(target_location) self.assertTrue(re.match("^file written: .*/foo$", txt)) ft.download_file(fn, source_url, target_location, forced=True) - self.assertTrue(os.path.exists(target_location)) + self.assertExists(target_location) self.assertTrue(os.path.samefile(path, target_location)) def test_download_file_requests_fallback(self): @@ -570,7 +570,7 @@ def fake_urllib_open(url, *args, **kwargs): self.mock_stderr(False) self.assertIn("WARNING: Not checking server certificates while downloading toy-0.0.eb", stderr) - self.assertTrue(os.path.exists(res)) + self.assertExists(res) self.assertTrue(ft.read_file(res).startswith("name = 'toy'")) # also test insecure download via requests fallback @@ -607,7 +607,7 @@ def fake_requests_get(url, *args, **kwargs): self.mock_stderr(False) self.assertIn("WARNING: Not checking server certificates while downloading README.rst", stderr) - self.assertTrue(os.path.exists(res)) + self.assertExists(res) self.assertIn("https://easybuilders.github.io/easybuild", ft.read_file(res)) def test_mkdir(self): @@ -695,7 +695,7 @@ def test_symlink_resolve_path(self): link_dir = os.path.join(self.test_prefix, 'linkdir') ft.symlink(test_dir, link_dir) self.assertTrue(os.path.islink(link_dir)) - self.assertTrue(os.path.exists(link_dir)) + self.assertExists(link_dir) test_file = os.path.join(link_dir, 'test.txt') ft.write_file(test_file, "test123") @@ -706,7 +706,7 @@ def test_symlink_resolve_path(self): # checking if file is symlink self.assertTrue(os.path.islink(link)) - self.assertTrue(os.path.exists(link_dir)) + self.assertExists(link_dir) self.assertTrue(os.path.samefile(os.path.join(self.test_prefix, 'test', 'test.txt'), link)) @@ -742,7 +742,7 @@ def test_remove_symlinks(self): # Attempting to remove a valid symlink ft.remove_file(link) self.assertFalse(os.path.islink(link)) - self.assertFalse(os.path.exists(link)) + self.assertNotExists(link) # Testing the removal of invalid symlinks # Restoring the symlink and removing the file, this way the symlink is invalid @@ -751,7 +751,7 @@ def test_remove_symlinks(self): # attempting to remove the invalid symlink ft.remove_file(link) self.assertFalse(os.path.islink(link)) - self.assertFalse(os.path.exists(link)) + self.assertNotExists(link) def test_read_write_file(self): """Test reading/writing files.""" @@ -815,7 +815,7 @@ def test_read_write_file(self): self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) # by default, write_file will just blindly overwrite an already existing file - self.assertTrue(os.path.exists(fp)) + self.assertExists(fp) ft.write_file(fp, 'blah') self.assertEqual(ft.read_file(fp), 'blah') @@ -848,11 +848,11 @@ def test_read_write_file(self): txt = self.get_stdout() self.mock_stdout(False) - self.assertFalse(os.path.exists(foo)) + self.assertNotExists(foo) self.assertTrue(re.match("^file written: .*/foo.txt$", txt)) ft.write_file(foo, 'bar', forced=True) - self.assertTrue(os.path.exists(foo)) + self.assertExists(foo) self.assertEqual(ft.read_file(foo), 'bar') # test use of 'mode' in read_file @@ -1009,7 +1009,7 @@ def test_back_up_file(self): new_file = [x for x in test_files if x not in known_files][0] self.assertTrue(new_file.startswith('test.txt.bak_')) known_files = os.listdir(os.path.dirname(fp)) - self.assertTrue(ft.read_file(first_normal_backup), txt) + self.assertEqual(ft.read_file(first_normal_backup), txt) self.assertEqual(ft.read_file(os.path.join(os.path.dirname(fp), new_file)), new_txt) self.assertEqual(ft.read_file(fp), new_txt) @@ -1020,7 +1020,7 @@ def test_back_up_file(self): new_file = [x for x in test_files if x not in known_files][0] self.assertTrue(new_file.startswith('.test.txt_')) known_files = os.listdir(os.path.dirname(fp)) - self.assertTrue(ft.read_file(first_hidden_backup), txt) + self.assertEqual(ft.read_file(first_hidden_backup), txt) self.assertEqual(ft.read_file(os.path.join(os.path.dirname(fp), new_file)), new_txt) self.assertEqual(ft.read_file(fp), new_txt) @@ -1031,7 +1031,7 @@ def test_back_up_file(self): new_file = [x for x in test_files if x not in known_files][0] self.assertTrue(new_file.startswith('test.txt.bck_')) known_files = os.listdir(os.path.dirname(fp)) - self.assertTrue(ft.read_file(first_bck_backup), txt) + self.assertEqual(ft.read_file(first_bck_backup), txt) self.assertEqual(ft.read_file(os.path.join(os.path.dirname(fp), new_file)), new_txt) self.assertEqual(ft.read_file(fp), new_txt) @@ -1042,7 +1042,7 @@ def test_back_up_file(self): new_file = [x for x in test_files if x not in known_files][0] self.assertTrue(new_file.startswith('.test.txt.foobar_')) known_files = os.listdir(os.path.dirname(fp)) - self.assertTrue(ft.read_file(first_hidden_bck_backup), txt) + self.assertEqual(ft.read_file(first_hidden_bck_backup), txt) self.assertEqual(ft.read_file(os.path.join(os.path.dirname(fp), new_file)), new_txt) self.assertEqual(ft.read_file(fp), new_txt) @@ -1375,7 +1375,7 @@ def test_apply_regex_substitutions(self): # backup file is created by default backup = testfile + '.orig.eb' - self.assertTrue(os.path.exists(backup)) + self.assertExists(backup) self.assertEqual(ft.read_file(backup), testtxt) # cleanup @@ -1389,7 +1389,7 @@ def test_apply_regex_substitutions(self): self.assertEqual(new_testtxt, expected_testtxt) backup = testfile + '.backup' - self.assertTrue(os.path.exists(backup)) + self.assertExists(backup) self.assertEqual(ft.read_file(backup), testtxt) # cleanup @@ -1400,7 +1400,7 @@ def test_apply_regex_substitutions(self): ft.apply_regex_substitutions(testfile, regex_subs, backup=False) new_testtxt = ft.read_file(testfile) self.assertEqual(new_testtxt, expected_testtxt) - self.assertFalse(os.path.exists(backup)) + self.assertNotExists(backup) # passing empty list of substitions is a no-op ft.write_file(testfile, testtxt) @@ -1585,7 +1585,7 @@ def test_pypi_source_urls(self): eb340_url = 'https://pypi.python.org/packages/' eb340_url += '93/41/574d01f352671fbc8589a436167e15a7f3e27ac0aa635d208eb29ee8fd4e/' eb340_url += 'easybuild-3.4.0.tar.gz#md5=267a056a77a8f77fccfbf56354364045' - self.assertTrue(eb340_url, res) + self.assertIn(eb340_url, res) pattern = '^https://pypi.python.org/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/' pattern_md5 = pattern + 'easybuild-[0-9a-z.]+.tar.gz#md5=[a-f0-9]{32}$' pattern_sha256 = pattern + 'easybuild-[0-9a-z.]+.tar.gz#sha256=[a-f0-9]{64}$' @@ -1689,12 +1689,12 @@ def test_apply_patch(self): pattern = "I'm a toy, and very proud of it" self.assertIn(pattern, patched) if with_backup: - self.assertTrue(os.path.exists(backup_file)) + self.assertExists(backup_file) self.assertNotIn(pattern, ft.read_file(backup_file)) # Restore file to original after first(!) iteration ft.move_file(backup_file, src_file) else: - self.assertFalse(os.path.exists(backup_file)) + self.assertNotExists(backup_file) # This patch is dependent on the previous one toy_patch_gz = os.path.join(testdir, 'sandbox', 'sources', 'toy', 'toy-0.0_gzip.patch.gz') @@ -1778,7 +1778,7 @@ def test_copy_file(self): toy_ec = os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb') target_path = os.path.join(self.test_prefix, 'toy.eb') ft.copy_file(toy_ec, target_path) - self.assertTrue(os.path.exists(target_path)) + self.assertExists(target_path) self.assertTrue(ft.read_file(toy_ec) == ft.read_file(target_path)) # Make sure it doesn't fail if path is a symlink and target_path is a dir @@ -1790,7 +1790,7 @@ def test_copy_file(self): ft.copy_file(toy_link, dir_target_path) copied_file = os.path.join(dir_target_path, toy_link_fn) # symlinks that point to an existing file are resolved on copy (symlink itself is not copied) - self.assertTrue(os.path.exists(copied_file), "%s should exist" % copied_file) + self.assertExists(copied_file) self.assertTrue(os.path.isfile(copied_file), "%s should be a file" % copied_file) ft.remove_file(copied_file) @@ -1798,7 +1798,7 @@ def test_copy_file(self): ft.remove_file(target_path) ft.copy_file(toy_link, dir_target_path) self.assertTrue(os.path.islink(copied_file), "%s should be a broken symbolic link" % copied_file) - self.assertFalse(os.path.exists(copied_file), "%s should be a broken symbolic link" % copied_file) + self.assertNotExists(copied_file, "%s should be a broken symbolic link" % copied_file) self.assertEqual(os.readlink(os.path.join(dir_target_path, toy_link_fn)), os.readlink(toy_link)) ft.remove_file(copied_file) @@ -1837,14 +1837,14 @@ def test_copy_file(self): init_config(build_options=build_options) # make sure target file is not there, it shouldn't get copied under dry run - self.assertFalse(os.path.exists(target_path)) + self.assertNotExists(target_path) self.mock_stdout(True) ft.copy_file(toy_ec, target_path) txt = self.get_stdout() self.mock_stdout(False) - self.assertFalse(os.path.exists(target_path)) + self.assertNotExists(target_path) self.assertTrue(re.search("^copied file .*/toy-0.0.eb to .*/toy.eb", txt)) # forced copy, even in dry run mode @@ -1853,7 +1853,7 @@ def test_copy_file(self): txt = self.get_stdout() self.mock_stdout(False) - self.assertTrue(os.path.exists(target_path)) + self.assertExists(target_path) self.assertTrue(ft.read_file(toy_ec) == ft.read_file(target_path)) self.assertEqual(txt, '') @@ -1883,23 +1883,23 @@ def test_copy_files(self): target_dir = os.path.join(self.test_prefix, 'target_dir1') ft.copy_files([toy_ec], target_dir) copied_toy_ec = os.path.join(target_dir, 'toy-0.0.eb') - self.assertTrue(os.path.exists(copied_toy_ec)) + self.assertExists(copied_toy_ec) self.assertEqual(ft.read_file(copied_toy_ec), toy_ec_txt) # copying a single file to an existing directory ft.copy_files([bzip2_ec], target_dir) copied_bzip2_ec = os.path.join(target_dir, 'bzip2-1.0.6-GCC-4.9.2.eb') - self.assertTrue(os.path.exists(copied_bzip2_ec)) + self.assertExists(copied_bzip2_ec) self.assertEqual(ft.read_file(copied_bzip2_ec), bzip2_ec_txt) # copying multiple files to a non-existing directory target_dir = os.path.join(self.test_prefix, 'target_dir_multiple') ft.copy_files([toy_ec, bzip2_ec], target_dir) copied_toy_ec = os.path.join(target_dir, 'toy-0.0.eb') - self.assertTrue(os.path.exists(copied_toy_ec)) + self.assertExists(copied_toy_ec) self.assertEqual(ft.read_file(copied_toy_ec), toy_ec_txt) copied_bzip2_ec = os.path.join(target_dir, 'bzip2-1.0.6-GCC-4.9.2.eb') - self.assertTrue(os.path.exists(copied_bzip2_ec)) + self.assertExists(copied_bzip2_ec) self.assertEqual(ft.read_file(copied_bzip2_ec), bzip2_ec_txt) # copying files to an existing target that is not a directory results in an error @@ -1914,9 +1914,9 @@ def test_copy_files(self): # test special case: copying a single file to a file target via target_single_file=True target = os.path.join(self.test_prefix, 'target') - self.assertFalse(os.path.exists(target)) + self.assertNotExists(target) ft.copy_files([toy_ec], target, target_single_file=True) - self.assertTrue(os.path.exists(target)) + self.assertExists(target) self.assertTrue(os.path.isfile(target)) self.assertEqual(toy_ec_txt, ft.read_file(target)) @@ -1924,22 +1924,22 @@ def test_copy_files(self): # also test target_single_file=True with path including a missing subdirectory target = os.path.join(self.test_prefix, 'target_parent', 'target_subdir', 'target.txt') - self.assertFalse(os.path.exists(target)) - self.assertFalse(os.path.exists(os.path.dirname(target))) + self.assertNotExists(target) + self.assertNotExists(os.path.dirname(target)) ft.copy_files([toy_ec], target, target_single_file=True) - self.assertTrue(os.path.exists(target)) + self.assertExists(target) self.assertTrue(os.path.isfile(target)) self.assertEqual(toy_ec_txt, ft.read_file(target)) ft.remove_file(target) # default behaviour is to copy single file list to target *directory* - self.assertFalse(os.path.exists(target)) + self.assertNotExists(target) ft.copy_files([toy_ec], target) - self.assertTrue(os.path.exists(target)) + self.assertExists(target) self.assertTrue(os.path.isdir(target)) copied_toy_ec = os.path.join(target, 'toy-0.0.eb') - self.assertTrue(os.path.exists(copied_toy_ec)) + self.assertExists(copied_toy_ec) self.assertEqual(toy_ec_txt, ft.read_file(copied_toy_ec)) ft.remove_dir(target) @@ -1971,7 +1971,7 @@ def test_copy_files(self): # check behaviour under -x: only printing, no actual copying init_config(build_options={'extended_dry_run': True}) - self.assertFalse(os.path.exists(os.path.join(target, 'test.eb'))) + self.assertNotExists(os.path.join(target, 'test.eb')) self.mock_stderr(True) self.mock_stdout(True) @@ -1980,7 +1980,7 @@ def test_copy_files(self): self.mock_stderr(False) self.mock_stdout(False) - self.assertFalse(os.path.exists(os.path.join(target, 'test.eb'))) + self.assertNotExists(os.path.join(target, 'test.eb')) self.assertEqual(stderr, '') regex = re.compile("^copied test.eb to .*/target") @@ -1993,8 +1993,8 @@ def test_copy_files(self): self.mock_stderr(False) self.mock_stdout(False) - self.assertFalse(os.path.exists(os.path.join(target, 'bar.eb'))) - self.assertFalse(os.path.exists(os.path.join(target, 'foo.eb'))) + self.assertNotExists(os.path.join(target, 'bar.eb')) + self.assertNotExists(os.path.join(target, 'foo.eb')) self.assertEqual(stderr, '') regex = re.compile("^copied 2 files to .*/target") @@ -2046,17 +2046,17 @@ def test_copy_dir(self): to_copy = os.path.join(testdir, 'easyconfigs', 'test_ecs', 'g', 'GCC') target_dir = os.path.join(self.test_prefix, 'GCC') - self.assertFalse(os.path.exists(target_dir)) + self.assertNotExists(target_dir) - self.assertTrue(os.path.exists(os.path.join(to_copy, 'GCC-6.4.0-2.28.eb'))) + self.assertExists(os.path.join(to_copy, 'GCC-6.4.0-2.28.eb')) ft.copy_dir(to_copy, target_dir, ignore=lambda src, names: [x for x in names if '6.4.0-2.28' in x]) - self.assertTrue(os.path.exists(target_dir)) + self.assertExists(target_dir) expected = ['GCC-4.6.3.eb', 'GCC-4.6.4.eb', 'GCC-4.8.2.eb', 'GCC-4.8.3.eb', 'GCC-4.9.2.eb', 'GCC-4.9.3-2.25.eb', 'GCC-4.9.3-2.26.eb', 'GCC-7.3.0-2.30.eb'] self.assertEqual(sorted(os.listdir(target_dir)), expected) # GCC-6.4.0-2.28.eb should not get copied, since it's specified as file too ignore - self.assertFalse(os.path.exists(os.path.join(target_dir, 'GCC-6.4.0-2.28.eb'))) + self.assertNotExists(os.path.join(target_dir, 'GCC-6.4.0-2.28.eb')) # clean error when trying to copy a file with copy_dir src, target = os.path.join(to_copy, 'GCC-4.6.3.eb'), os.path.join(self.test_prefix, 'GCC-4.6.3.eb') @@ -2079,7 +2079,7 @@ def ignore_func(_, names): ft.mkdir(testdir) ft.copy_dir(to_copy, testdir, dirs_exist_ok=True, ignore=ignore_func) self.assertEqual(sorted(os.listdir(testdir)), expected) - self.assertFalse(os.path.exists(os.path.join(testdir, 'GCC-6.4.0-2.28.eb'))) + self.assertNotExists(os.path.join(testdir, 'GCC-6.4.0-2.28.eb')) # test copy_dir when broken symlinks are involved srcdir = os.path.join(self.test_prefix, 'topdir_to_copy') @@ -2115,10 +2115,10 @@ def ignore_func(_, names): ft.remove_dir(target_dir) os.symlink('.', os.path.join(subdir, 'recursive_link')) self.assertErrorRegex(EasyBuildError, 'Recursive symlinks detected', ft.copy_dir, srcdir, target_dir) - self.assertFalse(os.path.exists(target_dir)) + self.assertNotExists(target_dir) # Ok for symlinks=True ft.copy_dir(srcdir, target_dir, symlinks=True) - self.assertTrue(os.path.exists(target_dir)) + self.assertExists(target_dir) # also test behaviour of copy_file under --dry-run build_options = { @@ -2128,7 +2128,7 @@ def ignore_func(_, names): init_config(build_options=build_options) shutil.rmtree(target_dir) - self.assertFalse(os.path.exists(target_dir)) + self.assertNotExists(target_dir) # no actual copying in dry run mode, unless forced self.mock_stdout(True) @@ -2136,7 +2136,7 @@ def ignore_func(_, names): txt = self.get_stdout() self.mock_stdout(False) - self.assertFalse(os.path.exists(target_dir)) + self.assertNotExists(target_dir) self.assertTrue(re.search("^copied directory .*/GCC to .*/%s" % os.path.basename(target_dir), txt)) # forced copy, even in dry run mode @@ -2145,7 +2145,7 @@ def ignore_func(_, names): txt = self.get_stdout() self.mock_stdout(False) - self.assertTrue(os.path.exists(target_dir)) + self.assertExists(target_dir) self.assertTrue(sorted(os.listdir(to_copy)) == sorted(os.listdir(target_dir))) self.assertEqual(txt, '') @@ -2182,8 +2182,8 @@ def test_copy(self): txt = self.get_stdout() self.mock_stdout(False) - self.assertFalse(os.path.exists(os.path.join(self.test_prefix, 'toy'))) - self.assertFalse(os.path.exists(os.path.join(self.test_prefix, 'GCC-4.6.3.eb'))) + self.assertNotExists(os.path.join(self.test_prefix, 'toy')) + self.assertNotExists(os.path.join(self.test_prefix, 'GCC-4.6.3.eb')) self.assertTrue(re.search("^copied directory .*/toy to .*/toy", txt, re.M)) self.assertTrue(re.search("^copied file .*/GCC-4.6.3.eb to .*/GCC-4.6.3.eb", txt, re.M)) @@ -2230,9 +2230,9 @@ def test_extract_file(self): testdir = os.path.dirname(os.path.abspath(__file__)) toy_tarball = os.path.join(testdir, 'sandbox', 'sources', 'toy', 'toy-0.0.tar.gz') - self.assertFalse(os.path.exists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source'))) + self.assertNotExists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source')) path = ft.extract_file(toy_tarball, self.test_prefix, change_into_dir=False) - self.assertTrue(os.path.exists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source'))) + self.assertExists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source')) self.assertTrue(os.path.samefile(path, self.test_prefix)) # still in same directory as before if change_into_dir is set to False self.assertTrue(os.path.samefile(os.getcwd(), cwd)) @@ -2243,7 +2243,7 @@ def test_extract_file(self): path = ft.extract_file(toy_tarball_renamed, self.test_prefix, cmd="tar xfvz %s", change_into_dir=False) self.assertTrue(os.path.samefile(os.getcwd(), cwd)) - self.assertTrue(os.path.exists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source'))) + self.assertExists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source')) self.assertTrue(os.path.samefile(path, self.test_prefix)) shutil.rmtree(os.path.join(path, 'toy-0.0')) @@ -2261,11 +2261,11 @@ def test_extract_file(self): self.assertTrue(os.path.samefile(os.getcwd(), cwd)) self.assertTrue(os.path.samefile(path, self.test_prefix)) - self.assertFalse(os.path.exists(os.path.join(self.test_prefix, 'toy-0.0'))) + self.assertNotExists(os.path.join(self.test_prefix, 'toy-0.0')) self.assertTrue(re.search('running command "tar xzf .*/toy-0.0.tar.gz"', txt)) path = ft.extract_file(toy_tarball, self.test_prefix, forced=True, change_into_dir=False) - self.assertTrue(os.path.exists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source'))) + self.assertExists(os.path.join(self.test_prefix, 'toy-0.0', 'toy.source')) self.assertTrue(os.path.samefile(path, self.test_prefix)) self.assertTrue(os.path.samefile(os.getcwd(), cwd)) @@ -2313,24 +2313,25 @@ def test_remove(self): for remove_file_function in (ft.remove_file, ft.remove): ft.write_file(testfile, 'bar') - self.assertTrue(os.path.exists(testfile)) + self.assertExists(testfile) remove_file_function(testfile) - self.assertFalse(os.path.exists(testfile)) + self.assertNotExists(testfile) for remove_dir_function in (ft.remove_dir, ft.remove): ft.mkdir(test_dir) - self.assertTrue(os.path.exists(test_dir) and os.path.isdir(test_dir)) + self.assertExists(test_dir) + self.assertTrue(os.path.isdir(test_dir)) remove_dir_function(test_dir) - self.assertFalse(os.path.exists(test_dir) or os.path.isdir(test_dir)) + self.assertNotExists(test_dir) # remove also takes a list of paths ft.write_file(testfile, 'bar') ft.mkdir(test_dir) - self.assertTrue(os.path.exists(testfile)) - self.assertTrue(os.path.exists(test_dir) and os.path.isdir(test_dir)) + self.assertExists(testfile) + self.assertExists(test_dir) and os.path.isdir(test_dir) ft.remove([testfile, test_dir]) - self.assertFalse(os.path.exists(testfile)) - self.assertFalse(os.path.exists(test_dir) or os.path.isdir(test_dir)) + self.assertNotExists(testfile) + self.assertNotExists(test_dir) # check error handling (after creating a permission problem with removing files/dirs) ft.write_file(testfile, 'bar') @@ -2405,7 +2406,7 @@ def test_index_functions(self): # test dump_index function index_fp = ft.dump_index(self.test_prefix) - self.assertTrue(os.path.exists(index_fp)) + self.assertExists(index_fp) self.assertTrue(os.path.samefile(self.test_prefix, os.path.dirname(index_fp))) datestamp_pattern = r"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+" @@ -2482,7 +2483,7 @@ def test_index_functions(self): stdout = self.get_stdout() self.mock_stderr(False) self.mock_stdout(False) - self.assertTrue(index is None) + self.assertIsNone(index) self.assertFalse(stdout) regex = re.compile(r"WARNING: Index for %s is no longer valid \(too old\), so ignoring it" % self.test_prefix) self.assertTrue(regex.search(stderr), "Pattern '%s' found in: %s" % (regex.pattern, stderr)) @@ -2619,8 +2620,8 @@ def test_find_eb_script(self): if 'EB_SCRIPT_PATH' in os.environ: del os.environ['EB_SCRIPT_PATH'] - self.assertTrue(os.path.exists(ft.find_eb_script('rpath_args.py'))) - self.assertTrue(os.path.exists(ft.find_eb_script('rpath_wrapper_template.sh.in'))) + self.assertExists(ft.find_eb_script('rpath_args.py')) + self.assertExists(ft.find_eb_script('rpath_wrapper_template.sh.in')) self.assertErrorRegex(EasyBuildError, "Script 'no_such_script' not found", ft.find_eb_script, 'no_such_script') # put test script in place relative to location of 'eb' @@ -2652,17 +2653,17 @@ def test_move_file(self): new_test_file = os.path.join(self.test_prefix, 'subdir', 'new_test.txt') ft.move_file(test_file, new_test_file) - self.assertFalse(os.path.exists(test_file)) - self.assertTrue(os.path.exists(new_test_file)) + self.assertNotExists(test_file) + self.assertExists(new_test_file) self.assertEqual(ft.read_file(new_test_file), 'test123') # test moving to an existing file ft.write_file(test_file, 'gibberish') ft.move_file(new_test_file, test_file) - self.assertTrue(os.path.exists(test_file)) + self.assertExists(test_file) self.assertEqual(ft.read_file(test_file), 'test123') - self.assertFalse(os.path.exists(new_test_file)) + self.assertNotExists(new_test_file) # also test behaviour of move_file under --dry-run build_options = { @@ -2684,9 +2685,9 @@ def test_move_file(self): self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) self.assertEqual(stderr, '') - self.assertTrue(os.path.exists(test_file)) + self.assertExists(test_file) self.assertEqual(ft.read_file(test_file), 'test123') - self.assertFalse(os.path.exists(new_test_file)) + self.assertNotExists(new_test_file) def test_find_backup_name_candidate(self): """Test find_backup_name_candidate""" @@ -3148,7 +3149,7 @@ def test_copy_framework_files(self): orig_path = os.path.join(topdir, test_file) copied_path = os.path.join(target_dir, test_file) - self.assertTrue(os.path.exists(copied_path)) + self.assertExists(copied_path) self.assertEqual(ft.read_file(orig_path, mode='rb'), ft.read_file(copied_path, mode='rb')) self.assertTrue(os.path.samefile(copied_path, res['paths_in_repo'][idx])) @@ -3170,17 +3171,17 @@ def test_locks(self): # det_lock_path returns full path to lock with specified name # (used internally by create_lock, check_lock, remove_lock) lock_path = ft.det_lock_path(lock_name) - self.assertFalse(os.path.exists(lock_path)) + self.assertNotExists(lock_path) locks_dir = os.path.dirname(lock_path) - self.assertFalse(os.path.exists(locks_dir)) + self.assertNotExists(locks_dir) # if lock doesn't exist yet, check_lock just returns ft.check_lock(lock_name) # create lock, and check whether it actually was created ft.create_lock(lock_name) - self.assertTrue(os.path.exists(lock_path)) + self.assertExists(lock_path) # can't use os.path.samefile until locks_dir actually exists self.assertTrue(os.path.samefile(locks_dir, os.path.join(self.test_installpath, 'software', '.locks'))) @@ -3192,7 +3193,7 @@ def test_locks(self): # remove_lock should... remove the lock ft.remove_lock(lock_name) - self.assertFalse(os.path.exists(lock_path)) + self.assertNotExists(lock_path) self.assertEqual(os.listdir(locks_dir), []) # no harm done if remove_lock is called if lock is already gone @@ -3213,7 +3214,7 @@ def test_locks(self): ft.clean_up_locks() self.assertFalse(ft.global_lock_names) - self.assertFalse(os.path.exists(lock_path)) + self.assertNotExists(lock_path) self.assertEqual(os.listdir(locks_dir), []) # no problem with multiple locks @@ -3222,7 +3223,7 @@ def test_locks(self): for ln in lock_names: ft.create_lock(ln) for lp in lock_paths: - self.assertTrue(os.path.exists(lp), "Path %s should exist" % lp) + self.assertExists(lp) self.assertEqual(ft.global_lock_names, set(lock_names)) expected_locks = sorted(ln + '.lock' for ln in lock_names) @@ -3230,20 +3231,20 @@ def test_locks(self): ft.clean_up_locks() for lp in lock_paths: - self.assertFalse(os.path.exists(lp), "Path %s should not exist" % lp) + self.assertNotExists(lp) self.assertFalse(ft.global_lock_names) self.assertEqual(os.listdir(locks_dir), []) # also test signal handler that is supposed to clean up locks ft.create_lock(lock_name) self.assertTrue(ft.global_lock_names) - self.assertTrue(os.path.exists(lock_path)) + self.assertExists(lock_path) self.assertEqual(os.listdir(locks_dir), [lock_name + '.lock']) # clean_up_locks_signal_handler causes sys.exit with specified exit code self.assertErrorRegex(SystemExit, '15', ft.clean_up_locks_signal_handler, 15, None) self.assertFalse(ft.global_lock_names) - self.assertFalse(os.path.exists(lock_path)) + self.assertNotExists(lock_path) self.assertEqual(os.listdir(locks_dir), []) def test_locate_files(self): @@ -3389,22 +3390,22 @@ def test_create_unused_dir(self): """Test create_unused_dir function.""" path = ft.create_unused_dir(self.test_prefix, 'folder') self.assertEqual(path, os.path.join(self.test_prefix, 'folder')) - self.assertTrue(os.path.exists(path)) + self.assertExists(path) # Repeat with existing folder(s) should create new ones for i in range(10): path = ft.create_unused_dir(self.test_prefix, 'folder') self.assertEqual(path, os.path.join(self.test_prefix, 'folder_%s' % i)) - self.assertTrue(os.path.exists(path)) + self.assertExists(path) # Not influenced by similar folder path = ft.create_unused_dir(self.test_prefix, 'folder2') self.assertEqual(path, os.path.join(self.test_prefix, 'folder2')) - self.assertTrue(os.path.exists(path)) + self.assertExists(path) for i in range(10): path = ft.create_unused_dir(self.test_prefix, 'folder2') self.assertEqual(path, os.path.join(self.test_prefix, 'folder2_%s' % i)) - self.assertTrue(os.path.exists(path)) + self.assertExists(path) # Fail cleanly if passed a readonly folder readonly_dir = os.path.join(self.test_prefix, 'ro_folder') @@ -3421,7 +3422,7 @@ def test_create_unused_dir(self): ft.write_file(os.path.join(self.test_prefix, 'file'), '') path = ft.create_unused_dir(self.test_prefix, 'file') self.assertEqual(path, os.path.join(self.test_prefix, 'file_0')) - self.assertTrue(os.path.exists(path)) + self.assertExists(path) def suite(): diff --git a/test/framework/github.py b/test/framework/github.py index fbcaa6f4ec..c1db1d336b 100644 --- a/test/framework/github.py +++ b/test/framework/github.py @@ -258,7 +258,7 @@ def test_github_reasons_for_closing(self): self.mock_stdout(False) self.mock_stderr(False) - self.assertTrue(isinstance(res, list)) + self.assertIsInstance(res, list) self.assertEqual(stderr.strip(), "WARNING: Using easyconfigs from closed PR #1844") patterns = [ "Status of last commit is SUCCESS", @@ -477,10 +477,10 @@ def test_github_download_repo(self): path = gh.download_repo(path=self.test_prefix, github_user=GITHUB_TEST_ACCOUNT) repodir = os.path.join(self.test_prefix, 'easybuilders', 'easybuild-easyconfigs-main') self.assertTrue(os.path.samefile(path, repodir)) - self.assertTrue(os.path.exists(repodir)) + self.assertExists(repodir) shafile = os.path.join(repodir, 'latest-sha') self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) - self.assertTrue(os.path.exists(os.path.join(repodir, 'easybuild', 'easyconfigs', 'f', 'foss', 'foss-2019b.eb'))) + self.assertExists(os.path.join(repodir, 'easybuild', 'easyconfigs', 'f', 'foss', 'foss-2019b.eb')) # current directory should not have changed after calling download_repo self.assertTrue(os.path.samefile(cwd, os.getcwd())) @@ -505,7 +505,7 @@ def test_github_download_repo(self): self.assertTrue(os.path.samefile(path, repodir)) self.assertIn('easybuild', os.listdir(repodir)) self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) - self.assertTrue(os.path.exists(os.path.join(repodir, 'easybuild', 'easyblocks', '__init__.py'))) + self.assertExists(os.path.join(repodir, 'easybuild', 'easyblocks', '__init__.py')) def test_install_github_token(self): """Test for install_github_token function.""" @@ -573,7 +573,7 @@ def test_github_find_easybuild_easyconfig(self): expected = os.path.join('e', 'EasyBuild', r'EasyBuild-[1-9]+\.[0-9]+\.[0-9]+\.eb') regex = re.compile(expected) self.assertTrue(regex.search(path), "Pattern '%s' found in '%s'" % (regex.pattern, path)) - self.assertTrue(os.path.exists(path), "Path %s exists" % path) + self.assertExists(path) def test_github_find_patches(self): """ Test for find_software_name_for_patch """ @@ -1011,9 +1011,9 @@ def test_github_det_pr_target_repo(self): github_py = os.path.join(test_dir, 'github.py') configuremake = os.path.join(test_dir, 'sandbox', 'easybuild', 'easyblocks', 'generic', 'configuremake.py') - self.assertTrue(os.path.exists(configuremake)) + self.assertExists(configuremake) toy_eb = os.path.join(test_dir, 'sandbox', 'easybuild', 'easyblocks', 't', 'toy.py') - self.assertTrue(os.path.exists(toy_eb)) + self.assertExists(toy_eb) self.assertEqual(build_option('pr_target_repo'), None) self.assertEqual(gh.det_pr_target_repo(categorize_files_by_type([github_py])), 'easybuild-framework') diff --git a/test/framework/hooks.py b/test/framework/hooks.py index 5ee52a5d5f..3d88bf39aa 100644 --- a/test/framework/hooks.py +++ b/test/framework/hooks.py @@ -78,7 +78,7 @@ def test_load_hooks(self): # test caching of hooks remove_file(self.test_hooks_pymod) cached_hooks = load_hooks(self.test_hooks_pymod) - self.assertTrue(cached_hooks is hooks) + self.assertIs(cached_hooks, hooks) # hooks file can be empty empty_hooks_path = os.path.join(self.test_prefix, 'empty_hooks.py') @@ -88,7 +88,7 @@ def test_load_hooks(self): # loading another hooks file doesn't affect cached hooks prev_hooks = load_hooks(self.test_hooks_pymod) - self.assertTrue(prev_hooks is hooks) + self.assertIs(prev_hooks, hooks) # clearing cached hooks results in error because hooks file is not found easybuild.tools.hooks._cached_hooks = {} diff --git a/test/framework/include.py b/test/framework/include.py index 6c9ab75864..b346f911ae 100644 --- a/test/framework/include.py +++ b/test/framework/include.py @@ -92,7 +92,7 @@ def test_include_easyblocks(self): 'easyblocks/generic/__init__.py', 'easyblocks/generic/mybar.py'] for filepath in expected_paths: fullpath = os.path.join(included_easyblocks_path, 'easybuild', filepath) - self.assertTrue(os.path.exists(fullpath), "%s exists" % fullpath) + self.assertExists(fullpath) # path to included easyblocks should be prepended to Python search path self.assertEqual(sys.path[0], included_easyblocks_path) @@ -185,7 +185,7 @@ def test_include_mns(self): 'tools/module_naming_scheme/my_mns.py'] for filepath in expected_paths: fullpath = os.path.join(included_mns_path, 'easybuild', filepath) - self.assertTrue(os.path.exists(fullpath), "%s exists" % fullpath) + self.assertExists(fullpath) # path to included MNSs should be prepended to Python search path self.assertEqual(sys.path[0], included_mns_path) @@ -232,7 +232,7 @@ def test_include_toolchains(self): 'toolchains/my_tc.py', 'toolchains/compiler/my_compiler.py'] for filepath in expected_paths: fullpath = os.path.join(included_tcs_path, 'easybuild', filepath) - self.assertTrue(os.path.exists(fullpath), "%s exists" % fullpath) + self.assertExists(fullpath) # path to included MNSs should be prepended to Python search path self.assertEqual(sys.path[0], included_tcs_path) diff --git a/test/framework/lib.py b/test/framework/lib.py index 70050461a1..2f4149314c 100644 --- a/test/framework/lib.py +++ b/test/framework/lib.py @@ -102,9 +102,9 @@ def test_mkdir(self): self.configure() # mkdir works fine if set_up_configuration was called first - self.assertFalse(os.path.exists(test_dir)) + self.assertNotExists(test_dir) mkdir(test_dir) - self.assertTrue(os.path.exists(test_dir)) + self.assertExists(test_dir) def test_modules_tool(self): """Test use of modules_tool function in the context of using EasyBuild framework as a library.""" diff --git a/test/framework/license.py b/test/framework/license.py index d7f4982f04..80c741908f 100644 --- a/test/framework/license.py +++ b/test/framework/license.py @@ -62,7 +62,7 @@ def test_licenses(self): """Test format of available licenses.""" lics = what_licenses() for lic in lics: - self.assertTrue(isinstance(lic, string_type)) + self.assertIsInstance(lic, string_type) self.assertTrue(lic.startswith('License')) self.assertTrue(issubclass(lics[lic], License)) diff --git a/test/framework/modules.py b/test/framework/modules.py index 35cb9c3916..dc654677a5 100644 --- a/test/framework/modules.py +++ b/test/framework/modules.py @@ -149,7 +149,7 @@ def test_run_module(self): self.assertEqual(res, [{'mod_name': 'GCC/6.4.0-2.28', 'default': None}]) res = self.modtool.run_module('avail', 'GCC/4.6.3') - self.assertTrue(isinstance(res, list)) + self.assertIsInstance(res, list) self.assertEqual(sorted([x['mod_name'] for x in res]), ['GCC/4.6.3']) # loading a module produces no output, so we get an empty list @@ -248,8 +248,8 @@ def test_exist(self): test_modules_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules')) if isinstance(self.modtool, Lmod): # make sure only the .lua module file is there, otherwise this test doesn't work as intended - self.assertTrue(os.path.exists(os.path.join(test_modules_path, 'bzip2', '.1.0.6.lua'))) - self.assertFalse(os.path.exists(os.path.join(test_modules_path, 'bzip2', '.1.0.6'))) + self.assertExists(os.path.join(test_modules_path, 'bzip2', '.1.0.6.lua')) + self.assertNotExists(os.path.join(test_modules_path, 'bzip2', '.1.0.6')) self.assertEqual(self.modtool.exist(['bzip2/.1.0.6']), [True]) # exist also works on lists of module names @@ -557,7 +557,7 @@ def test_check_module_path_hmns(self): mkdir(core_mod_dir, parents=True) doesnotexist = os.path.join(self.test_prefix, 'doesnotexist') - self.assertFalse(os.path.exists(doesnotexist)) + self.assertNotExists(doesnotexist) os.environ['MODULEPATH'] = '%s:%s' % (core_mod_dir, doesnotexist) modtool = modules_tool() @@ -1081,7 +1081,7 @@ def test_mk_module_cache_key(self): """Test mk_module_cache_key method.""" os.environ['MODULEPATH'] = '%s:/tmp/test' % self.test_prefix res = self.modtool.mk_module_cache_key('thisisapartialkey') - self.assertTrue(isinstance(res, tuple)) + self.assertIsInstance(res, tuple) self.assertEqual(res, ('MODULEPATH=%s:/tmp/test' % self.test_prefix, self.modtool.COMMAND, 'thisisapartialkey')) del os.environ['MODULEPATH'] @@ -1132,8 +1132,8 @@ def test_module_caches(self): self.assertEqual(len(mod.MODULE_SHOW_CACHE), 2) self.assertIn(show_res_gcc, mod.MODULE_SHOW_CACHE.values()) self.assertIn(show_res_fftw, mod.MODULE_SHOW_CACHE.values()) - self.assertTrue(self.modtool.show('GCC/6.4.0-2.28') is show_res_gcc) - self.assertTrue(self.modtool.show('FFTW') is show_res_fftw) + self.assertIs(self.modtool.show('GCC/6.4.0-2.28'), show_res_gcc) + self.assertIs(self.modtool.show('FFTW'), show_res_fftw) # invalidate caches with correct path modulepaths = [p for p in os.environ.get('MODULEPATH', '').split(os.pathsep) if p] @@ -1333,7 +1333,7 @@ def test_load_in_hierarchy(self): # make sure that compiler-dependent hwloc test module exists gcc_mod_dir = os.path.join(mod_dir, 'Compiler', 'GCC', '6.4.0-2.28') - self.assertTrue(os.path.exists(os.path.join(gcc_mod_dir, 'hwloc', '1.11.8'))) + self.assertExists(os.path.join(gcc_mod_dir, 'hwloc', '1.11.8')) # test loading of compiler-dependent hwloc test module self.modtool.purge() @@ -1475,7 +1475,7 @@ def check_loaded_modules(): warning_msg = "WARNING: Found defined $EBROOT* environment variables without matching loaded module: " warning_msg += "$EBROOTSOFTWAREWITHOUTAMATCHINGMODULE; unsetting them" self.assertEqual(stderr, warning_msg) - self.assertTrue(os.environ.get('EBROOTSOFTWAREWITHOUTAMATCHINGMODULE') is None) + self.assertIsNone(os.environ.get('EBROOTSOFTWAREWITHOUTAMATCHINGMODULE')) # specified action for detected loaded modules is verified early error_msg = "Unknown action specified to --detect-loaded-modules: sdvbfdgh" diff --git a/test/framework/modulestool.py b/test/framework/modulestool.py index 2a9133d0ed..e2e2503388 100644 --- a/test/framework/modulestool.py +++ b/test/framework/modulestool.py @@ -130,7 +130,7 @@ def test_module_mismatch(self): # redefine 'module' function with correct module command os.environ['module'] = "() { eval `/bin/echo $*`\n}" mt = MockModulesTool(testing=True) - self.assertTrue(isinstance(mt.loaded_modules(), list)) # dummy usage + self.assertIsInstance(mt.loaded_modules(), list) # dummy usage # a warning should be logged if the 'module' function is undefined del os.environ['module'] diff --git a/test/framework/options.py b/test/framework/options.py index 5f1c1d865b..9039d2a09b 100644 --- a/test/framework/options.py +++ b/test/framework/options.py @@ -1143,7 +1143,7 @@ def test_copy_ec(self): regex = re.compile(r'.*/toy-0.0.eb copied to %s' % test_ec) self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) - self.assertTrue(os.path.exists(test_ec)) + self.assertExists(test_ec) self.assertEqual(toy_ec_txt, read_file(test_ec)) remove_file(test_ec) @@ -1151,7 +1151,7 @@ def test_copy_ec(self): # basic test: copying one easyconfig file to a non-existing relative path cwd = change_dir(self.test_prefix) target_fn = 'test.eb' - self.assertFalse(os.path.exists(target_fn)) + self.assertNotExists(target_fn) args = ['--copy-ec', 'toy-0.0.eb', target_fn] stdout = self.mocked_main(args) @@ -1160,7 +1160,7 @@ def test_copy_ec(self): change_dir(cwd) - self.assertTrue(os.path.exists(test_ec)) + self.assertExists(test_ec) self.assertEqual(toy_ec_txt, read_file(test_ec)) # copying one easyconfig into an existing directory @@ -1172,20 +1172,20 @@ def test_copy_ec(self): self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) copied_toy_ec = os.path.join(test_target_dir, 'toy-0.0.eb') - self.assertTrue(os.path.exists(copied_toy_ec)) + self.assertExists(copied_toy_ec) self.assertEqual(toy_ec_txt, read_file(copied_toy_ec)) remove_dir(test_target_dir) def check_copied_files(): """Helper function to check result of copying multiple easyconfigs.""" - self.assertTrue(os.path.exists(test_target_dir)) + self.assertExists(test_target_dir) self.assertEqual(sorted(os.listdir(test_target_dir)), ['bzip2-1.0.6-GCC-4.9.2.eb', 'toy-0.0.eb']) copied_toy_ec = os.path.join(test_target_dir, 'toy-0.0.eb') - self.assertTrue(os.path.exists(copied_toy_ec)) + self.assertExists(copied_toy_ec) self.assertEqual(toy_ec_txt, read_file(copied_toy_ec)) copied_bzip2_ec = os.path.join(test_target_dir, 'bzip2-1.0.6-GCC-4.9.2.eb') - self.assertTrue(os.path.exists(copied_bzip2_ec)) + self.assertExists(copied_bzip2_ec) self.assertEqual(bzip2_ec_txt, read_file(copied_bzip2_ec)) # copying multiple easyconfig files to a non-existing target directory (which is created automatically) @@ -1200,7 +1200,7 @@ def check_copied_files(): # same but with relative path for target dir change_dir(self.test_prefix) args[-1] = os.path.basename(test_target_dir) - self.assertFalse(os.path.exists(args[-1])) + self.assertNotExists(args[-1]) stdout = self.mocked_main(args) self.assertEqual(stdout, '2 file(s) copied to test_target_dir') @@ -1224,7 +1224,7 @@ def check_copied_files(): regex = re.compile('.*/toy-0.0.eb copied to .*/%s' % os.path.basename(test_working_dir)) self.assertTrue(regex.match(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) copied_toy_cwd = os.path.join(test_working_dir, 'toy-0.0.eb') - self.assertTrue(os.path.exists(copied_toy_cwd)) + self.assertExists(copied_toy_cwd) self.assertEqual(read_file(copied_toy_cwd), toy_ec_txt) # --copy-ec without arguments results in a proper error @@ -1260,11 +1260,11 @@ def test_github_copy_ec_from_pr(self): # check that the files exist for pr_file in all_files_pr8007: - self.assertTrue(os.path.exists(os.path.join(test_working_dir, pr_file))) + self.assertExists(os.path.join(test_working_dir, pr_file)) remove_file(os.path.join(test_working_dir, pr_file)) # copying all files touched by PR to a non-existing target directory (which is created automatically) - self.assertFalse(os.path.exists(test_target_dir)) + self.assertNotExists(test_target_dir) args = ['--copy-ec', '--from-pr', '8007', test_target_dir] stdout = self.mocked_main(args) @@ -1272,7 +1272,7 @@ def test_github_copy_ec_from_pr(self): self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout)) for pr_file in all_files_pr8007: - self.assertTrue(os.path.exists(os.path.join(test_target_dir, pr_file))) + self.assertExists(os.path.join(test_target_dir, pr_file)) remove_dir(test_target_dir) # test where we select a single easyconfig file from a PR @@ -1296,7 +1296,7 @@ def test_github_copy_ec_from_pr(self): regex = re.compile(r"%s copied to .*/bat.eb" % ec_filename) self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout)) - self.assertTrue(os.path.exists(bat_ec)) + self.assertExists(bat_ec) self.assertIn("name = 'bat'", read_file(bat_ec)) change_dir(cwd) @@ -1311,7 +1311,7 @@ def test_github_copy_ec_from_pr(self): self.assertEqual(os.listdir(test_working_dir), [patch_fn]) patch_path = os.path.join(test_working_dir, patch_fn) - self.assertTrue(os.path.exists(patch_path)) + self.assertExists(patch_path) self.assertTrue(is_patch_file(patch_path)) remove_file(patch_path) @@ -1347,7 +1347,7 @@ def test_github_copy_ec_from_pr(self): stdout = self.mocked_main(args) regex = re.compile(r'.*/%s copied to %s' % (ec_pr11521, test_ec)) self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) - self.assertTrue(os.path.exists(test_ec)) + self.assertExists(test_ec) self.assertIn("name = 'ExifTool'", read_file(test_ec)) remove_file(test_ec) @@ -2375,7 +2375,7 @@ def test_try_with_copy(self): self.assertFalse(errtxt) self.mock_stdout(False) self.mock_stderr(False) - self.assertTrue(os.path.exists(copied_ec)) + self.assertExists(copied_ec) self.mock_stdout(True) self.mock_stderr(True) @@ -2388,9 +2388,7 @@ def test_try_with_copy(self): self.assertFalse(errtxt) self.mock_stdout(False) self.mock_stderr(False) - self.assertTrue( - os.path.exists(os.path.join(self.test_buildpath, tweaked_ecs_dir, 'foo-1.2.3-GCC-6.4.0-2.28.eb')) - ) + self.assertExists(os.path.join(self.test_buildpath, tweaked_ecs_dir, 'foo-1.2.3-GCC-6.4.0-2.28.eb')) def test_software_version_ordering(self): """Test whether software versions are correctly ordered when using --software.""" @@ -2503,7 +2501,7 @@ def test_cleanup_builddir(self): # make sure --disable-cleanup-builddir works args.append('--disable-cleanup-builddir') self.eb_main(args, do_build=True, verbose=True) - self.assertTrue(os.path.exists(toy_buildpath), "Build dir %s is retained when requested" % toy_buildpath) + self.assertExists(toy_buildpath, "Build dir %s is retained when requested" % toy_buildpath) shutil.rmtree(toy_buildpath) # make sure build dir stays in case of failed build @@ -2513,7 +2511,7 @@ def test_cleanup_builddir(self): '--try-amend=prebuildopts=nosuchcommand &&', ] self.eb_main(args, do_build=True) - self.assertTrue(os.path.exists(toy_buildpath), "Build dir %s is retained after failed build" % toy_buildpath) + self.assertExists(toy_buildpath, "Build dir %s is retained after failed build" % toy_buildpath) def test_filter_deps(self): """Test use of --filter-deps.""" @@ -3651,7 +3649,7 @@ def test_use_included_module_naming_scheme(self): toy_mod = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0') if get_module_syntax() == 'Lua': toy_mod += '.lua' - self.assertTrue(os.path.exists(toy_mod), "Found %s" % toy_mod) + self.assertExists(toy_mod) def test_include_toolchains(self): """Test --include-toolchains.""" @@ -3728,7 +3726,7 @@ def test_cleanup_tmpdir(self): # default: cleanup tmpdir & logfile self.eb_main(args, raise_error=True, testing=False) self.assertEqual(os.listdir(tmpdir), []) - self.assertFalse(os.path.exists(self.logfile)) + self.assertNotExists(self.logfile) # disable cleaning up tmpdir args.append('--disable-cleanup-tmpdir') @@ -3736,10 +3734,10 @@ def test_cleanup_tmpdir(self): tmpdir_files = os.listdir(tmpdir) # tmpdir and logfile are still there \o/ self.assertTrue(len(tmpdir_files) == 1) - self.assertTrue(os.path.exists(self.logfile)) + self.assertExists(self.logfile) # tweaked easyconfigs is still there \o/ tweaked_dir = os.path.join(tmpdir, tmpdir_files[0], 'tweaked_easyconfigs') - self.assertTrue(os.path.exists(os.path.join(tweaked_dir, 'toy-1.0.eb'))) + self.assertExists(os.path.join(tweaked_dir, 'toy-1.0.eb')) def test_github_preview_pr(self): """Test --preview-pr.""" @@ -3891,10 +3889,10 @@ def test_minimal_toolchains(self): # check requirements for test init_config([], build_options={'robot_path': os.environ['EASYBUILD_ROBOT_PATHS']}) - self.assertFalse(os.path.exists(robot_find_easyconfig('hwloc', '1.11.8-gompi-2018a') or 'nosuchfile')) - self.assertTrue(os.path.exists(robot_find_easyconfig('hwloc', '1.11.8-GCC-6.4.0-2.28'))) - self.assertTrue(os.path.exists(robot_find_easyconfig('SQLite', '3.8.10.2-gompi-2018a'))) - self.assertTrue(os.path.exists(robot_find_easyconfig('SQLite', '3.8.10.2-GCC-6.4.0-2.28'))) + self.assertNotExists(robot_find_easyconfig('hwloc', '1.11.8-gompi-2018a') or 'nosuchfile') + self.assertExists(robot_find_easyconfig('hwloc', '1.11.8-GCC-6.4.0-2.28')) + self.assertExists(robot_find_easyconfig('SQLite', '3.8.10.2-gompi-2018a')) + self.assertExists(robot_find_easyconfig('SQLite', '3.8.10.2-GCC-6.4.0-2.28')) args = [ ec_file, @@ -4263,7 +4261,7 @@ def test_github_new_update_pr(self): res = [d for d in res if os.path.basename(d) != os.path.basename(git_working_dir)] if len(res) == 1: unstaged_file_full = os.path.join(res[0], unstaged_file) - self.assertFalse(os.path.exists(unstaged_file_full), "%s not found in %s" % (unstaged_file, res[0])) + self.assertNotExists(unstaged_file_full), "%s not found in %s" % (unstaged_file, res[0]) else: self.fail("Found copy of easybuild-easyconfigs working copy") @@ -4322,7 +4320,7 @@ def test_github_new_update_pr(self): # modifying an existing easyconfig requires a custom PR title gcc_ec = os.path.join(test_ecs, 'g', 'GCC', 'GCC-4.9.2.eb') - self.assertTrue(os.path.exists(gcc_ec)) + self.assertExists(gcc_ec) args = [ '--new-pr', @@ -4630,7 +4628,7 @@ def test_new_pr_easyblock(self): topdir = os.path.dirname(os.path.abspath(__file__)) toy_eb = os.path.join(topdir, 'sandbox', 'easybuild', 'easyblocks', 't', 'toy.py') - self.assertTrue(os.path.exists(toy_eb)) + self.assertExists(toy_eb) args = [ '--github-user=%s' % GITHUB_TEST_ACCOUNT, @@ -4954,7 +4952,7 @@ def test_dump_env_script(self): # check whether scripts were dumped env_script = os.path.join(self.test_prefix, '%s.env' % name) - self.assertTrue(os.path.exists(env_script)) + self.assertExists(env_script) # existing .env files are not overwritten, unless forced os.chdir(self.test_prefix) @@ -5549,14 +5547,14 @@ def test_set_default_module(self): if get_module_syntax() == 'Lua': toy_mod += '.lua' - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) if get_module_syntax() == 'Lua': self.assertTrue(os.path.islink(os.path.join(toy_mod_dir, 'default'))) self.assertEqual(os.readlink(os.path.join(toy_mod_dir, 'default')), '0.0-deps.lua') elif get_module_syntax() == 'Tcl': toy_dot_version = os.path.join(toy_mod_dir, '.version') - self.assertTrue(os.path.exists(toy_dot_version)) + self.assertExists(toy_dot_version) toy_dot_version_txt = read_file(toy_dot_version) self.assertIn("set ModulesVersion 0.0-deps", toy_dot_version_txt) else: @@ -5660,7 +5658,7 @@ def test_inject_checksums(self): self.mock_stderr(False) # make sure software install directory is *not* created (see bug issue #3064) - self.assertFalse(os.path.exists(os.path.join(self.test_installpath, 'software', 'toy'))) + self.assertNotExists(os.path.join(self.test_installpath, 'software', 'toy')) # SHA256 is default type of checksums used self.assertIn("injecting sha256 checksums in", stdout) @@ -6039,7 +6037,7 @@ def test_tmp_logdir(self): # purposely use a non-existing directory as log directory tmp_logdir = os.path.join(self.test_prefix, 'tmp-logs') - self.assertFalse(os.path.exists(tmp_logdir)) + self.assertNotExists(tmp_logdir) # force passing logfile=None to main in eb_main self.logfile = None @@ -6229,12 +6227,12 @@ def test_skip_extensions(self): if get_module_syntax() == 'Lua': toy_mod += '.lua' - self.assertTrue(os.path.exists(toy_mod), "%s should exist" % toy_mod) + self.assertExists(toy_mod) toy_installdir = os.path.join(self.test_installpath, 'software', 'toy', '0.0') for path in (os.path.join('bin', 'barbar'), os.path.join('lib', 'libbarbar.a')): path = os.path.join(toy_installdir, path) - self.assertFalse(os.path.exists(path), "Path %s should not exist" % path) + self.assertNotExists(path) def test_fake_vsc_include(self): """Test whether fake 'vsc' namespace is triggered for modules included via --include-*.""" @@ -6381,7 +6379,7 @@ def test_create_index(self): def test_sysroot(self): """Test use of --sysroot option.""" - self.assertTrue(os.path.exists(self.test_prefix)) + self.assertExists(self.test_prefix) sysroot_arg = '--sysroot=' + self.test_prefix stdout, stderr = self._run_mock_eb([sysroot_arg, '--show-config'], raise_error=True) @@ -6434,18 +6432,18 @@ def test_accept_eula_for(self): for val in ('foo,toy,bar', '.*', 't.y'): self.eb_main(args + ['--accept-eula-for=' + val], do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_modfile)) + self.assertExists(toy_modfile) remove_dir(self.test_installpath) - self.assertFalse(os.path.exists(toy_modfile)) + self.assertNotExists(toy_modfile) # also check use of $EASYBUILD_ACCEPT_EULA to accept EULA for specified software os.environ['EASYBUILD_ACCEPT_EULA_FOR'] = val self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_modfile)) + self.assertExists(toy_modfile) remove_dir(self.test_installpath) - self.assertFalse(os.path.exists(toy_modfile)) + self.assertNotExists(toy_modfile) del os.environ['EASYBUILD_ACCEPT_EULA_FOR'] @@ -6459,7 +6457,7 @@ def test_accept_eula_for(self): self.assertIn("Use accept-eula-for configuration setting rather than accept-eula", stderr) remove_dir(self.test_installpath) - self.assertFalse(os.path.exists(toy_modfile)) + self.assertNotExists(toy_modfile) # also via $EASYBUILD_ACCEPT_EULA self.mock_stderr(True) @@ -6468,18 +6466,18 @@ def test_accept_eula_for(self): stderr = self.get_stderr() self.mock_stderr(False) - self.assertTrue(os.path.exists(toy_modfile)) + self.assertExists(toy_modfile) self.assertIn("Use accept-eula-for configuration setting rather than accept-eula", stderr) remove_dir(self.test_installpath) - self.assertFalse(os.path.exists(toy_modfile)) + self.assertNotExists(toy_modfile) # also check accepting EULA via 'accept_eula = True' in easyconfig file self.disallow_deprecated_behaviour() del os.environ['EASYBUILD_ACCEPT_EULA'] write_file(test_ec, test_ec_txt + '\naccept_eula = True') self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_modfile)) + self.assertExists(toy_modfile) def test_config_abs_path(self): """Test ensuring of absolute path values for path configuration options.""" @@ -6641,14 +6639,14 @@ def test_easystack_opts(self): # libtoy module should be installed, module file should at least set EBROOTLIBTOY mod_dir = os.path.join(self.test_installpath, 'modules', 'all') mod_path = os.path.join(mod_dir, 'libtoy', '0.0') + mod_ext - self.assertTrue(os.path.exists(mod_path)) + self.assertExists(mod_path) self.modtool.use(mod_dir) self.modtool.load(['libtoy']) - self.assertTrue(os.path.exists(os.environ['EBROOTLIBTOY'])) + self.assertExists(os.environ['EBROOTLIBTOY']) # module should be hidden and in different install path mod_path = os.path.join(hidden_installpath, 'modules', 'all', 'toy', '.0.0') + mod_ext - self.assertTrue(os.path.exists(mod_path)) + self.assertExists(mod_path) # check build options that were put in place for last easyconfig self.assertFalse(build_option('hidden')) @@ -6714,13 +6712,13 @@ def test_set_up_configuration(self): eb_go, settings = set_up_configuration(args=['--debug', '--module-syntax=Tcl'], silent=True) # 2nd part of return value is a tuple with various settings - self.assertTrue(isinstance(settings, tuple)) + self.assertIsInstance(settings, tuple) self.assertEqual(len(settings), 9) self.assertEqual(settings[0], {}) # build specs - self.assertTrue(isinstance(settings[1], EasyBuildLog)) # EasyBuildLog instance + self.assertIsInstance(settings[1], EasyBuildLog) # EasyBuildLog instance self.assertTrue(settings[2].endswith('.log')) # path to log file - self.assertTrue(os.path.exists(settings[2])) - self.assertTrue(isinstance(settings[3], list)) # list of robot paths + self.assertExists(settings[2]) + self.assertIsInstance(settings[3], list) # list of robot paths self.assertEqual(len(settings[3]), 1) self.assertTrue(os.path.samefile(settings[3][0], os.environ['EASYBUILD_ROBOT_PATHS'])) self.assertEqual(settings[4], None) # search query diff --git a/test/framework/output.py b/test/framework/output.py index 101fb62f57..d1673a55d1 100644 --- a/test/framework/output.py +++ b/test/framework/output.py @@ -60,22 +60,20 @@ def test_status_bar(self): expected_progress_bar_class = DummyRich progress_bar = status_bar(ignore_cache=True) - error_msg = "%s should be instance of class %s" % (progress_bar, expected_progress_bar_class) - self.assertTrue(isinstance(progress_bar, expected_progress_bar_class), error_msg) + self.assertIsInstance(progress_bar, expected_progress_bar_class) update_build_option('output_style', 'basic') progress_bar = status_bar(ignore_cache=True) - self.assertTrue(isinstance(progress_bar, DummyRich)) + self.assertIsInstance(progress_bar, DummyRich) if HAVE_RICH: update_build_option('output_style', 'rich') progress_bar = status_bar(ignore_cache=True) - error_msg = "%s should be instance of class %s" % (progress_bar, expected_progress_bar_class) - self.assertTrue(isinstance(progress_bar, expected_progress_bar_class), error_msg) + self.assertIsInstance(progress_bar, expected_progress_bar_class) update_build_option('show_progress_bar', False) progress_bar = status_bar(ignore_cache=True) - self.assertTrue(isinstance(progress_bar, DummyRich)) + self.assertIsInstance(progress_bar, DummyRich) def test_get_output_style(self): """Test get_output_style function.""" @@ -152,9 +150,9 @@ def test_get_progress_bar(self): for pbar_type in PROGRESS_BAR_TYPES: pbar = get_progress_bar(pbar_type, ignore_cache=True) if HAVE_RICH: - self.assertTrue(isinstance(pbar, rich.progress.Progress)) + self.assertIsInstance(pbar, rich.progress.Progress) else: - self.assertTrue(isinstance(pbar, DummyRich)) + self.assertIsInstance(pbar, DummyRich) def test_get_start_update_stop_progress_bar(self): """ diff --git a/test/framework/parallelbuild.py b/test/framework/parallelbuild.py index 71bad5bbc7..3ad85ac3b1 100644 --- a/test/framework/parallelbuild.py +++ b/test/framework/parallelbuild.py @@ -186,16 +186,16 @@ def test_build_easyconfigs_in_parallel_pbs_python(self): # installation directory doesn't exist yet before submission toy_installdir = os.path.join(self.test_installpath, 'software', 'toy', '0.0') - self.assertFalse(os.path.exists(toy_installdir)) + self.assertNotExists(toy_installdir) jobs = submit_jobs(ordered_ecs, '', testing=False) self.assertEqual(len(jobs), 1) # software install dir is created (by default) as part of job submission process (fetch_step is run) - self.assertTrue(os.path.exists(toy_installdir)) + self.assertExists(toy_installdir) remove_dir(toy_installdir) remove_dir(os.path.dirname(toy_installdir)) - self.assertFalse(os.path.exists(toy_installdir)) + self.assertNotExists(toy_installdir) # installation directory does *not* get created when --pre-create-installdir is used build_options['pre_create_installdir'] = False @@ -203,7 +203,7 @@ def test_build_easyconfigs_in_parallel_pbs_python(self): jobs = submit_jobs(ordered_ecs, '', testing=False) self.assertEqual(len(jobs), 1) - self.assertFalse(os.path.exists(toy_installdir)) + self.assertNotExists(toy_installdir) # restore mocked stuff PbsPython.__init__ = PbsPython__init__ @@ -265,8 +265,8 @@ def test_build_easyconfigs_in_parallel_gc3pie(self): toy_modfile = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0') if get_module_syntax() == 'Lua': toy_modfile += '.lua' - self.assertTrue(os.path.exists(toy_modfile)) - self.assertTrue(os.path.exists(os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'bin', 'toy'))) + self.assertExists(toy_modfile) + self.assertExists(os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'bin', 'toy')) # also check what happens when a job fails (an error should be raised) test_ecfile = os.path.join(self.test_prefix, 'test.eb') diff --git a/test/framework/repository.py b/test/framework/repository.py index c03da7c109..aa1cf402b7 100644 --- a/test/framework/repository.py +++ b/test/framework/repository.py @@ -86,7 +86,7 @@ def test_gitrepo(self): try: repo.init() self.assertEqual(os.path.basename(repo.wc), 'testrepository') - self.assertTrue(os.path.exists(os.path.join(repo.wc, 'README.md'))) + self.assertExists(os.path.join(repo.wc, 'README.md')) shutil.rmtree(repo.wc) except EasyBuildError as err: print("ignoring failed subtest in test_gitrepo, testing offline?") @@ -126,7 +126,7 @@ def test_svnrepo(self): repo = SvnRepository(test_repo_url) repo.init() - self.assertTrue(os.path.exists(os.path.join(repo.wc, 'trunk', 'README.md'))) + self.assertExists(os.path.join(repo.wc, 'trunk', 'README.md')) shutil.rmtree(repo.wc) # this test is disabled because it fails in Travis as a result of bitbucket disabling TLS 1.0/1.1 @@ -147,7 +147,7 @@ def DISABLED_test_hgrepo(self): repo = HgRepository(test_repo_url) repo.init() - self.assertTrue(os.path.exists(os.path.join(repo.wc, 'README'))) + self.assertExists(os.path.join(repo.wc, 'README')) shutil.rmtree(repo.wc) def test_init_repository(self): @@ -170,7 +170,7 @@ def test_add_easyconfig(self): def check_ec(path, expected_buildstats): """Check easyconfig at specified path""" - self.assertTrue(os.path.exists(path)) + self.assertExists(path) ectxt = read_file(path) self.assertTrue(ectxt.startswith("# Built with EasyBuild version")) self.assertIn("# Build statistics", ectxt) diff --git a/test/framework/robot.py b/test/framework/robot.py index c438a74441..4f226bae35 100644 --- a/test/framework/robot.py +++ b/test/framework/robot.py @@ -627,7 +627,7 @@ def test_det_easyconfig_paths(self): mkdir(subdir_hwloc, parents=True) shutil.copy2(os.path.join(test_ecs_path, 'h', 'hwloc', hwloc_ec), subdir_hwloc) shutil.copy2(os.path.join(test_ecs_path, 'i', 'intel', 'intel-2018a.eb'), self.test_prefix) - self.assertFalse(os.path.exists(test_ec)) + self.assertNotExists(test_ec) args = [ os.path.join(test_ecs_path, 't', 'toy', 'toy-0.0.eb'), @@ -696,7 +696,7 @@ def test_search_paths(self): test_ec = 'toy-0.0-deps.eb' shutil.copy2(os.path.join(test_ecs_path, 't', 'toy', test_ec), self.test_prefix) - self.assertFalse(os.path.exists(test_ec)) + self.assertNotExists(test_ec) args = [ '--search-paths=%s' % self.test_prefix, # add to search path @@ -727,7 +727,7 @@ def test_github_det_easyconfig_paths_from_pr(self): test_ec = 'toy-0.0-deps.eb' shutil.copy2(os.path.join(test_ecs_path, 't', 'toy', test_ec), self.test_prefix) shutil.copy2(os.path.join(test_ecs_path, 'i', 'intel', 'intel-2018a.eb'), self.test_prefix) - self.assertFalse(os.path.exists(test_ec)) + self.assertNotExists(test_ec) gompi_2018b_txt = '\n'.join([ "easyblock = 'Toolchain'", diff --git a/test/framework/run.py b/test/framework/run.py index 3aafeac413..48a0f75fd2 100644 --- a/test/framework/run.py +++ b/test/framework/run.py @@ -507,14 +507,14 @@ def test_dry_run(self): # check forced run outfile = os.path.join(self.test_prefix, 'cmd.out') - self.assertFalse(os.path.exists(outfile)) + self.assertNotExists(outfile) self.mock_stdout(True) run_cmd("echo 'This is always echoed' > %s" % outfile, force_in_dry_run=True) txt = self.get_stdout() self.mock_stdout(False) # nothing printed to stdout, but command was run self.assertEqual(txt, '') - self.assertTrue(os.path.exists(outfile)) + self.assertExists(outfile) self.assertEqual(read_file(outfile), "This is always echoed\n") # Q&A commands diff --git a/test/framework/systemtools.py b/test/framework/systemtools.py index 23eeb70700..893b37103d 100644 --- a/test/framework/systemtools.py +++ b/test/framework/systemtools.py @@ -401,7 +401,7 @@ def tearDown(self): def test_avail_core_count_native(self): """Test getting core count.""" core_count = get_avail_core_count() - self.assertTrue(isinstance(core_count, int), "core_count has type int: %s, %s" % (core_count, type(core_count))) + self.assertIsInstance(core_count, int), "core_count has type int: %s, %s" % (core_count, type(core_count)) self.assertTrue(core_count > 0, "core_count %d > 0" % core_count) def test_avail_core_count_linux(self): @@ -422,7 +422,7 @@ def test_avail_core_count_darwin(self): def test_cpu_model_native(self): """Test getting CPU model.""" cpu_model = get_cpu_model() - self.assertTrue(isinstance(cpu_model, string_type)) + self.assertIsInstance(cpu_model, string_type) def test_cpu_model_linux(self): """Test getting CPU model (mocked for Linux).""" @@ -460,8 +460,9 @@ def test_cpu_model_darwin(self): def test_cpu_speed_native(self): """Test getting CPU speed.""" cpu_speed = get_cpu_speed() - self.assertTrue(isinstance(cpu_speed, float) or cpu_speed is None) - self.assertTrue(cpu_speed is None or cpu_speed > 0.0) + if cpu_speed is not None: + self.assertIsInstance(cpu_speed, float) + self.assertTrue(cpu_speed > 0.0) def test_cpu_speed_linux(self): """Test getting CPU speed (mocked for Linux).""" @@ -494,7 +495,7 @@ def test_cpu_speed_darwin(self): def test_cpu_features_native(self): """Test getting CPU features.""" cpu_feat = get_cpu_features() - self.assertTrue(isinstance(cpu_feat, list)) + self.assertIsInstance(cpu_feat, list) self.assertTrue(len(cpu_feat) >= 0) self.assertTrue(all(isinstance(x, string_type) for x in cpu_feat)) @@ -580,7 +581,7 @@ def test_cpu_architecture(self): def test_cpu_arch_name_native(self): """Test getting CPU arch name.""" arch_name = get_cpu_arch_name() - self.assertTrue(isinstance(arch_name, string_type)) + self.assertIsInstance(arch_name, string_type) def test_cpu_arch_name(self): """Test getting CPU arch name.""" @@ -714,12 +715,12 @@ def test_shared_lib_ext_darwin(self): def test_platform_name_native(self): """Test getting platform name.""" platform_name_nover = get_platform_name() - self.assertTrue(isinstance(platform_name_nover, string_type)) + self.assertIsInstance(platform_name_nover, string_type) len_nover = len(platform_name_nover.split('-')) self.assertTrue(len_nover >= 3) platform_name_ver = get_platform_name(withversion=True) - self.assertTrue(isinstance(platform_name_ver, string_type)) + self.assertIsInstance(platform_name_ver, string_type) len_ver = len(platform_name_ver.split('-')) self.assertTrue(platform_name_ver.startswith(platform_name_ver)) self.assertTrue(len_ver >= len_nover) @@ -764,7 +765,8 @@ def test_os_version(self): def test_gcc_version_native(self): """Test getting gcc version.""" gcc_version = get_gcc_version() - self.assertTrue(isinstance(gcc_version, string_type) or gcc_version is None) + if gcc_version is not None: + self.assertIsInstance(gcc_version, string_type) def test_gcc_version_linux(self): """Test getting gcc version (mocked for Linux).""" @@ -816,12 +818,12 @@ def test_get_total_memory_darwin(self): def test_get_total_memory_native(self): """Test the function that gets the total memory.""" memtotal = get_total_memory() - self.assertTrue(isinstance(memtotal, int)) + self.assertIsInstance(memtotal, int) def test_system_info(self): """Test getting system info.""" system_info = get_system_info() - self.assertTrue(isinstance(system_info, dict)) + self.assertIsInstance(system_info, dict) def test_det_parallelism_native(self): """Test det_parallelism function (native calls).""" @@ -1076,7 +1078,7 @@ def test_locate_solib(self): if libc_obj: libc_path = locate_solib(libc_obj) self.assertEqual(os.path.basename(libc_path), libname) - self.assertTrue(os.path.exists(libc_path), "%s should exist" % libname) + self.assertExists(libc_path) def test_find_library_path(self): """Test find_library_path function (Linux and Darwin only).""" @@ -1091,7 +1093,8 @@ def test_find_library_path(self): if libname: lib_path = find_library_path(libname) self.assertEqual(os.path.basename(lib_path), libname) - self.assertTrue(os.path.exists(lib_path) or os_type == DARWIN, "%s should exist" % libname) + if os_type != DARWIN: + self.assertExists(lib_path) def suite(): diff --git a/test/framework/toolchain.py b/test/framework/toolchain.py index ab2a75c212..1c36431c45 100644 --- a/test/framework/toolchain.py +++ b/test/framework/toolchain.py @@ -107,7 +107,7 @@ def test_system_toolchain(self): """Test for system toolchain.""" for ver in ['system', '']: tc = self.get_toolchain('system', version=ver) - self.assertTrue(isinstance(tc, SystemToolchain)) + self.assertIsInstance(tc, SystemToolchain) def test_foss_toolchain(self): """Test for foss toolchain.""" @@ -519,9 +519,9 @@ def test_get_variable_libs_list(self): tc.prepare() ldflags = tc.get_variable('LDFLAGS', typ=list) - self.assertTrue(isinstance(ldflags, list)) + self.assertIsInstance(ldflags, list) if len(ldflags) > 0: - self.assertTrue(isinstance(ldflags[0], string_type)) + self.assertIsInstance(ldflags[0], string_type) def test_validate_pass_by_value(self): """ @@ -1678,12 +1678,12 @@ def test_get_mpi_cmd_template(self): mpdbf = params['mpdbf'] regex = re.compile('^--file=.*/mpdboot$') self.assertTrue(regex.match(mpdbf), "'%s' should match pattern '%s'" % (mpdbf, regex.pattern)) - self.assertTrue(os.path.exists(mpdbf.split('=')[1])) + self.assertExists(mpdbf.split('=')[1]) nodesfile = params['nodesfile'] regex = re.compile('^-machinefile /.*/nodes$') self.assertTrue(regex.match(nodesfile), "'%s' should match pattern '%s'" % (nodesfile, regex.pattern)) - self.assertTrue(os.path.exists(nodesfile.split(' ')[1])) + self.assertExists(nodesfile.split(' ')[1]) def test_prepare_deps(self): """Test preparing for a toolchain when dependencies are involved.""" @@ -1968,7 +1968,7 @@ def test_standalone_iccifort(self): self.modtool.purge() for key in ['EBROOTICC', 'EBROOTIFORT', 'EBVERSIONICC', 'EBVERSIONIFORT']: - self.assertTrue(os.getenv(key) is None) + self.assertIsNone(os.getenv(key)) # install fake iccifort module with no dependencies fake_iccifort = os.path.join(self.test_prefix, 'iccifort', '2018.1.163') @@ -2004,7 +2004,7 @@ def test_standalone_iccifortcuda(self): self.modtool.purge() for key in ['EBROOTICC', 'EBROOTIFORT', 'EBVERSIONICC', 'EBVERSIONIFORT', 'EBROOTCUDA', 'EBVERSIONCUDA']: - self.assertTrue(os.getenv(key) is None) + self.assertIsNone(os.getenv(key)) # install fake iccifortcuda module with no dependencies fake_iccifortcuda = os.path.join(self.test_prefix, 'iccifortcuda', '2018b') @@ -2895,9 +2895,9 @@ def prep(): self.assertIn(len(tmpdir), (11, 13)) # also test cleanup method to ensure short $TMPDIR is cleaned up properly - self.assertTrue(os.path.exists(tmpdir)) + self.assertExists(tmpdir) tc.cleanup() - self.assertFalse(os.path.exists(tmpdir)) + self.assertNotExists(tmpdir) os.environ['TMPDIR'] = orig_tmpdir diff --git a/test/framework/toy_build.py b/test/framework/toy_build.py index 0cc1eccbb2..768a037233 100644 --- a/test/framework/toy_build.py +++ b/test/framework/toy_build.py @@ -125,14 +125,14 @@ def check_toy(self, installpath, outtxt, name='toy', version='0.0', versionprefi msg = "module for toy build toy/%s found (path %s)" % (full_version, toy_module) if get_module_syntax() == 'Lua': toy_module += '.lua' - self.assertTrue(os.path.exists(toy_module), msg + error_msg) + self.assertExists(toy_module, msg + error_msg) # module file is symlinked according to moduleclass toy_module_symlink = os.path.join(installpath, 'modules', 'tools', name, full_version) if get_module_syntax() == 'Lua': toy_module_symlink += '.lua' self.assertTrue(os.path.islink(toy_module_symlink)) - self.assertTrue(os.path.exists(toy_module_symlink)) + self.assertExists(toy_module_symlink) # make sure installation log file and easyconfig file are copied to install dir software_path = os.path.join(installpath, 'software', name, full_version) @@ -147,10 +147,10 @@ def check_toy(self, installpath, outtxt, name='toy', version='0.0', versionprefi "Found at least 1 file at %s" % test_report_path_pattern) ec_file_path = os.path.join(software_path, 'easybuild', '%s-%s.eb' % (name, full_version)) - self.assertTrue(os.path.exists(ec_file_path)) + self.assertExists(ec_file_path) devel_module_path = os.path.join(software_path, 'easybuild', '%s-%s-easybuild-devel' % (name, full_version)) - self.assertTrue(os.path.exists(devel_module_path)) + self.assertExists(devel_module_path) def test_toy_build(self, extra_args=None, ec_file=None, tmpdir=None, verify=True, fails=False, verbose=True, raise_error=False, test_report=None, name='toy', versionsuffix='', testing=True, @@ -198,7 +198,7 @@ def test_toy_build(self, extra_args=None, ec_file=None, tmpdir=None, verify=True # make sure full test report was dumped, and contains sensible information if test_report is not None: - self.assertTrue(os.path.exists(test_report)) + self.assertExists(test_report) if test_report_regexs: regex_patterns = test_report_regexs else: @@ -481,7 +481,7 @@ def test_toy_download_sources(self): self.check_toy(tmpdir, outtxt) - self.assertTrue(os.path.exists(os.path.join(sourcepath, 't', 'toy', 'toy-0.0.tar.gz'))) + self.assertExists(os.path.join(sourcepath, 't', 'toy', 'toy-0.0.tar.gz')) shutil.rmtree(tmpdir) @@ -823,7 +823,7 @@ def test_toy_hierarchical(self): toy_module_path = os.path.join(mod_prefix, 'MPI', 'GCC', '6.4.0-2.28', 'OpenMPI', '2.1.2', 'toy', '0.0') if get_module_syntax() == 'Lua': toy_module_path += '.lua' - self.assertTrue(os.path.exists(toy_module_path)) + self.assertExists(toy_module_path) # check that toolchain load is expanded to loads for toolchain dependencies, # except for the ones that extend $MODULEPATH to make the toy module available @@ -854,7 +854,7 @@ def test_toy_hierarchical(self): toy_module_path = os.path.join(mod_prefix, 'Compiler', 'GCC', '6.4.0-2.28', 'toy', '0.0') if get_module_syntax() == 'Lua': toy_module_path += '.lua' - self.assertTrue(os.path.exists(toy_module_path)) + self.assertExists(toy_module_path) # no dependencies or toolchain => no module load statements in module file modtxt = read_file(toy_module_path) @@ -871,7 +871,7 @@ def test_toy_hierarchical(self): toy_module_path = os.path.join(mod_prefix, 'Compiler', 'GCC', '6.4.0-2.28', 'toy', '0.0') if get_module_syntax() == 'Lua': toy_module_path += '.lua' - self.assertTrue(os.path.exists(toy_module_path)) + self.assertExists(toy_module_path) # 'module use' statements to extend $MODULEPATH are present modtxt = read_file(toy_module_path) @@ -911,7 +911,7 @@ def test_toy_hierarchical(self): toy_module_path = os.path.join(mod_prefix, 'Core', 'toy', '0.0') if get_module_syntax() == 'Lua': toy_module_path += '.lua' - self.assertTrue(os.path.exists(toy_module_path)) + self.assertExists(toy_module_path) # no dependencies or toolchain => no module load statements in module file modtxt = read_file(toy_module_path) @@ -929,7 +929,7 @@ def test_toy_hierarchical(self): toy_module_path = os.path.join(mod_prefix, 'Core', 'toy', '0.0') if get_module_syntax() == 'Lua': toy_module_path += '.lua' - self.assertTrue(os.path.exists(toy_module_path)) + self.assertExists(toy_module_path) # no dependencies or toolchain => no module load statements in module file modtxt = read_file(toy_module_path) @@ -957,7 +957,7 @@ def test_toy_hierarchical(self): args[0] = os.path.join(test_easyconfigs, 'g', 'gompi', 'gompi-2018a.eb') self.modtool.purge() self.eb_main(args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True) - self.assertTrue(os.path.exists(gompi_module_path), "%s found" % gompi_module_path) + self.assertExists(gompi_module_path) def test_toy_hierarchical_subdir_user_modules(self): """ @@ -1116,7 +1116,7 @@ def test_toy_advanced_filter_deps(self): toy_module = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0-gompi-2018a-test') if get_module_syntax() == 'Lua': toy_module += '.lua' - self.assertTrue(os.path.exists(toy_module)) + self.assertExists(toy_module) def test_toy_hidden_cmdline(self): """Test installing a hidden module using the '--hidden' command line option.""" @@ -1127,10 +1127,10 @@ def test_toy_hidden_cmdline(self): toy_module = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '.0.0') if get_module_syntax() == 'Lua': toy_module += '.lua' - self.assertTrue(os.path.exists(toy_module), 'Found hidden module %s' % toy_module) + self.assertExists(toy_module, 'Found hidden module %s' % toy_module) # installed software is not hidden toybin = os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'bin', 'toy') - self.assertTrue(os.path.exists(toybin)) + self.assertExists(toybin) def test_toy_hidden_easyconfig(self): """Test installing a hidden module using the 'hidden = True' easyconfig parameter.""" @@ -1145,10 +1145,10 @@ def test_toy_hidden_easyconfig(self): toy_module = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '.0.0') if get_module_syntax() == 'Lua': toy_module += '.lua' - self.assertTrue(os.path.exists(toy_module), 'Found hidden module %s' % toy_module) + self.assertExists(toy_module, 'Found hidden module %s' % toy_module) # installed software is not hidden toybin = os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'bin', 'toy') - self.assertTrue(os.path.exists(toybin)) + self.assertExists(toybin) def test_module_filepath_tweaking(self): """Test using --suffix-modules-path.""" @@ -1173,10 +1173,10 @@ def test_module_filepath_tweaking(self): if get_module_syntax() == 'Lua': mod_file_suffix += '.lua' - self.assertTrue(os.path.exists(os.path.join(mod_file_prefix, 'foobarbaz', 'toy', '0.0' + mod_file_suffix))) - self.assertTrue(os.path.exists(os.path.join(mod_file_prefix, 'TOOLS', 'toy', '0.0' + mod_file_suffix))) + self.assertExists(os.path.join(mod_file_prefix, 'foobarbaz', 'toy', '0.0' + mod_file_suffix)) + self.assertExists(os.path.join(mod_file_prefix, 'TOOLS', 'toy', '0.0' + mod_file_suffix)) self.assertTrue(os.path.islink(os.path.join(mod_file_prefix, 'TOOLS', 'toy', '0.0' + mod_file_suffix))) - self.assertTrue(os.path.exists(os.path.join(mod_file_prefix, 't', 'toy', '0.0' + mod_file_suffix))) + self.assertExists(os.path.join(mod_file_prefix, 't', 'toy', '0.0' + mod_file_suffix)) self.assertTrue(os.path.islink(os.path.join(mod_file_prefix, 't', 'toy', '0.0' + mod_file_suffix))) def test_toy_archived_easyconfig(self): @@ -1189,7 +1189,7 @@ def test_toy_archived_easyconfig(self): self.test_toy_build(raise_error=True, extra_args=extra_args) archived_ec = os.path.join(repositorypath, 'toy', 'toy-0.0.eb') - self.assertTrue(os.path.exists(archived_ec)) + self.assertExists(archived_ec) ec = EasyConfig(archived_ec) self.assertEqual(ec.name, 'toy') self.assertEqual(ec.version, '0.0') @@ -1206,7 +1206,7 @@ def test_toy_patches(self): installdir = os.path.join(self.test_installpath, 'software', 'toy', '0.0') patch_file = os.path.join(installdir, 'easybuild', 'toy-0.0_fix-silly-typo-in-printf-statement.patch') - self.assertTrue(os.path.exists(patch_file)) + self.assertExists(patch_file) archived_patch_file = os.path.join(repositorypath, 'toy', 'toy-0.0_fix-silly-typo-in-printf-statement.patch') self.assertTrue(os.path.isfile(archived_patch_file)) @@ -1248,7 +1248,7 @@ def test_toy_extension_patches_postinstallcmds(self): # verify that post-install command for 'bar' extension was executed fn = 'created-via-postinstallcmds.txt' - self.assertTrue(os.path.exists(os.path.join(installdir, fn))) + self.assertExists(os.path.join(installdir, fn)) def test_toy_extension_sources(self): """Test install toy that includes extensions with 'sources' spec (as single-item list).""" @@ -1649,10 +1649,10 @@ def test_module_only(self): args = common_args + ['--module-only'] err_msg = "Sanity check failed" self.assertErrorRegex(EasyBuildError, err_msg, self.eb_main, args, do_build=True, raise_error=True) - self.assertFalse(os.path.exists(toy_mod)) + self.assertNotExists(toy_mod) self.eb_main(args + ['--force'], do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) # make sure load statements for dependencies are included in additional module file generated with --module-only modtxt = read_file(toy_mod) @@ -1665,15 +1665,15 @@ def test_module_only(self): rebuild_args = args + ['--rebuild'] err_msg = "Sanity check failed" self.assertErrorRegex(EasyBuildError, err_msg, self.eb_main, rebuild_args, do_build=True, raise_error=True) - self.assertFalse(os.path.exists(toy_mod)) + self.assertNotExists(toy_mod) # installing another module under a different naming scheme and using Lua module syntax works fine # first actually build and install toy software + module prefix = os.path.join(self.test_installpath, 'software', 'toy', '0.0-deps') self.eb_main(common_args + ['--force'], do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) - self.assertTrue(os.path.exists(os.path.join(self.test_installpath, 'software', 'toy', '0.0-deps', 'bin'))) + self.assertExists(toy_mod) + self.assertExists(os.path.join(self.test_installpath, 'software', 'toy', '0.0-deps', 'bin')) modtxt = read_file(toy_mod) self.assertTrue(re.search("set root %s" % prefix, modtxt)) self.assertEqual(len(os.listdir(os.path.join(self.test_installpath, 'software'))), 2) @@ -1685,9 +1685,9 @@ def test_module_only(self): '--module-naming-scheme=MigrateFromEBToHMNS', ] toy_core_mod = os.path.join(self.test_installpath, 'modules', 'all', 'Core', 'toy', '0.0-deps') - self.assertFalse(os.path.exists(toy_core_mod)) + self.assertNotExists(toy_core_mod) self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_core_mod)) + self.assertExists(toy_core_mod) # existing install is reused modtxt2 = read_file(toy_core_mod) self.assertTrue(re.search("set root %s" % prefix, modtxt2)) @@ -1702,9 +1702,9 @@ def test_module_only(self): os.remove(toy_core_mod) # remove the write permissions on the installation adjust_permissions(prefix, stat.S_IRUSR | stat.S_IXUSR, relative=False) - self.assertFalse(os.path.exists(toy_core_mod)) + self.assertNotExists(toy_core_mod) self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_core_mod)) + self.assertExists(toy_core_mod) # existing install is reused modtxt2 = read_file(toy_core_mod) self.assertTrue(re.search("set root %s" % prefix, modtxt2)) @@ -1727,9 +1727,9 @@ def test_module_only(self): '--module-syntax=Lua', '--modules-tool=Lmod', ] - self.assertFalse(os.path.exists(toy_mod + '.lua')) + self.assertNotExists(toy_mod + '.lua') self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod + '.lua')) + self.assertExists(toy_mod + '.lua') # existing install is reused modtxt3 = read_file(toy_mod + '.lua') self.assertTrue(re.search('local root = "%s"' % prefix, modtxt3)) @@ -1784,7 +1784,7 @@ def test_module_only_extensions(self): # first try normal --module-only, should work fine self.eb_main([test_ec, '--module-only'], do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) remove_file(toy_mod) # rename file required for barbar extension, so we can check whether sanity check catches it @@ -1796,17 +1796,17 @@ def test_module_only_extensions(self): for extra_args in (['--module-only'], ['--module-only', '--rebuild']): self.assertErrorRegex(EasyBuildError, error_pattern, self.eb_main, [test_ec] + extra_args, do_build=True, raise_error=True) - self.assertFalse(os.path.exists(toy_mod)) + self.assertNotExists(toy_mod) # failing sanity check for barbar extension is ignored when using --module-only --skip-extensions for extra_args in (['--module-only'], ['--module-only', '--rebuild']): self.eb_main([test_ec, '--skip-extensions'] + extra_args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) remove_file(toy_mod) # we can force module generation via --force (which skips sanity check entirely) self.eb_main([test_ec, '--module-only', '--force'], do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) def test_toy_exts_parallel(self): """ @@ -1921,11 +1921,11 @@ def test_backup_modules(self): # install module once (without --module-only), so it can be backed up self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) # forced reinstall, no backup of module file because --backup-modules (or --module-only) is not used self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, '.' + toy_mod_fn + '.bak_*')) self.assertEqual(len(toy_mod_backups), 0) @@ -1937,7 +1937,7 @@ def test_backup_modules(self): stdout = self.get_stdout() self.mock_stderr(False) self.mock_stdout(False) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) toy_mod_backups = glob.glob(os.path.join(toy_mod_dir, '.' + toy_mod_fn + '.bak_*')) self.assertEqual(len(toy_mod_backups), 1) first_toy_mod_backup = toy_mod_backups[0] @@ -1989,7 +1989,7 @@ def test_backup_modules(self): # initial installation of Lua module file self.eb_main(args, do_build=True, raise_error=True) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) lua_toy_mods = glob.glob(os.path.join(toy_mod_dir, '*.lua*')) self.assertEqual(len(lua_toy_mods), 1) self.assertEqual(os.path.basename(toy_mod), os.path.basename(lua_toy_mods[0])) @@ -2008,7 +2008,7 @@ def test_backup_modules(self): self.mock_stderr(False) self.mock_stdout(False) - self.assertTrue(os.path.exists(toy_mod)) + self.assertExists(toy_mod) lua_toy_mods = glob.glob(os.path.join(toy_mod_dir, '*.lua*')) self.assertEqual(len(lua_toy_mods), 1) self.assertEqual(os.path.basename(toy_mod), os.path.basename(lua_toy_mods[0])) @@ -2085,7 +2085,7 @@ def test_package(self): self.test_toy_build(extra_args=extra_args) toypkg = os.path.join(pkgpath, 'toy-0.0-eb-%s.321.foo' % EASYBUILD_VERSION) - self.assertTrue(os.path.exists(toypkg), "%s is there" % toypkg) + self.assertExists(toypkg) def test_package_skip(self): """Test use of --package with --skip.""" @@ -2093,14 +2093,14 @@ def test_package_skip(self): pkgpath = os.path.join(self.test_prefix, 'packages') # default path self.test_toy_build(['--packagepath=%s' % pkgpath]) - self.assertFalse(os.path.exists(pkgpath), "%s is not created without use of --package" % pkgpath) + self.assertNotExists(pkgpath, "%s is not created without use of --package" % pkgpath) self.mock_stdout(True) self.test_toy_build(extra_args=['--package', '--skip'], verify=False) self.mock_stdout(False) toypkg = os.path.join(pkgpath, 'toy-0.0-eb-%s.1.rpm' % EASYBUILD_VERSION) - self.assertTrue(os.path.exists(toypkg), "%s is there" % toypkg) + self.assertExists(toypkg) def test_regtest(self): """Test use of --regtest.""" @@ -2108,10 +2108,9 @@ def test_regtest(self): # just check whether module exists toy_module = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0') - msg = "module %s found" % toy_module if get_module_syntax() == 'Lua': toy_module += '.lua' - self.assertTrue(os.path.exists(toy_module), msg) + self.assertExists(toy_module) def test_minimal_toolchains(self): """Test toy build with --minimal-toolchains.""" @@ -2145,12 +2144,12 @@ def test_reproducibility(self): reprod_dir = os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'easybuild', 'reprod') reprod_ec = os.path.join(reprod_dir, 'toy-0.0.eb') - self.assertTrue(os.path.exists(reprod_ec)) + self.assertExists(reprod_ec) # Also check that the dumpenv script is placed alongside it dumpenv_script = '%s.env' % os.path.splitext(reprod_ec)[0] reprod_dumpenv = os.path.join(reprod_dir, dumpenv_script) - self.assertTrue(os.path.exists(reprod_dumpenv)) + self.assertExists(reprod_dumpenv) # Check contents of the dumpenv script patterns = [ @@ -2174,19 +2173,19 @@ def test_reproducibility(self): # Check for child easyblock existence child_easyblock = os.path.join(reprod_dir, 'easyblocks', 'toytoy.py') - self.assertTrue(os.path.exists(child_easyblock)) + self.assertExists(child_easyblock) # Check for parent easyblock existence parent_easyblock = os.path.join(reprod_dir, 'easyblocks', 'toy.py') - self.assertTrue(os.path.exists(parent_easyblock)) + self.assertExists(parent_easyblock) # Make sure framework easyblock modules are not included for framework_easyblock in ['easyblock.py', 'extensioneasyblock.py']: path = os.path.join(reprod_dir, 'easyblocks', framework_easyblock) - self.assertFalse(os.path.exists(path)) + self.assertNotExists(path) # Make sure hooks are also copied reprod_hooks = os.path.join(reprod_dir, 'hooks', hooks_filename) - self.assertTrue(os.path.exists(reprod_hooks)) + self.assertExists(reprod_hooks) def test_reproducibility_ext_easyblocks(self): """Test toy build produces expected reproducibility files also when extensions are used""" @@ -2209,22 +2208,22 @@ def test_reproducibility_ext_easyblocks(self): reprod_dir = os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'easybuild', 'reprod') reprod_ec = os.path.join(reprod_dir, 'toy-0.0.eb') - self.assertTrue(os.path.exists(reprod_ec)) + self.assertExists(reprod_ec) # Check for child easyblock existence child_easyblock = os.path.join(reprod_dir, 'easyblocks', 'toytoy.py') - self.assertTrue(os.path.exists(child_easyblock)) + self.assertExists(child_easyblock) # Check for parent easyblock existence parent_easyblock = os.path.join(reprod_dir, 'easyblocks', 'toy.py') - self.assertTrue(os.path.exists(parent_easyblock)) + self.assertExists(parent_easyblock) # Check for extension easyblock existence ext_easyblock = os.path.join(reprod_dir, 'easyblocks', 'toy_extension.py') - self.assertTrue(os.path.exists(ext_easyblock)) + self.assertExists(ext_easyblock) # Make sure framework easyblock modules are not included for framework_easyblock in ['easyblock.py', 'extensioneasyblock.py']: path = os.path.join(reprod_dir, 'easyblocks', framework_easyblock) - self.assertFalse(os.path.exists(path)) + self.assertNotExists(path) def test_toy_toy(self): """Test building two easyconfigs in a single go, with one depending on the other.""" @@ -2251,13 +2250,13 @@ def test_toy_toy(self): mod1 = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0-one') mod2 = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0-two') - self.assertTrue(os.path.exists(mod1) or os.path.exists('%s.lua' % mod1)) - self.assertTrue(os.path.exists(mod2) or os.path.exists('%s.lua' % mod2)) + if get_module_syntax() == 'Lua': + mod1 += '.lua' + mod2 += '.lua' + self.assertExists(mod1) + self.assertExists(mod2) - if os.path.exists(mod2): - mod2_txt = read_file(mod2) - else: - mod2_txt = read_file('%s.lua' % mod2) + mod2_txt = read_file(mod2) load1_regex = re.compile('load.*toy/0.0-one', re.M) self.assertTrue(load1_regex.search(mod2_txt), "Pattern '%s' found in: %s" % (load1_regex.pattern, mod2_txt)) @@ -2266,7 +2265,7 @@ def test_toy_toy(self): reprod_dir = os.path.join(self.test_installpath, 'software', 'toy', '0.0-two', 'easybuild', 'reprod') dumpenv_script = os.path.join(reprod_dir, 'toy-0.0-two.env') reprod_dumpenv = os.path.join(reprod_dir, dumpenv_script) - self.assertTrue(os.path.exists(reprod_dumpenv)) + self.assertExists(reprod_dumpenv) # Check contents of the dumpenv script patterns = [ @@ -2327,7 +2326,7 @@ def test_toy_sanity_check_commands(self): if get_module_syntax() == 'Lua': toy_modfile += '.lua' - self.assertTrue(os.path.exists(toy_modfile)) + self.assertExists(toy_modfile) def test_sanity_check_paths_lib64(self): """Test whether fallback in sanity check for lib64/ equivalents of library files works.""" @@ -2808,8 +2807,8 @@ def test_toy_modaltsoftname(self): modules_path = os.path.join(self.test_installpath, 'modules', 'all', 'Core') # install dirs for both installations should be there (using original software name) - self.assertTrue(os.path.exists(os.path.join(software_path, 'toy', '0.0-one', 'bin', 'toy'))) - self.assertTrue(os.path.exists(os.path.join(software_path, 'toy', '0.0-two', 'bin', 'toy'))) + self.assertExists(os.path.join(software_path, 'toy', '0.0-one', 'bin', 'toy')) + self.assertExists(os.path.join(software_path, 'toy', '0.0-two', 'bin', 'toy')) toytwo_name = '0.0-two' yot_name = '0.0-one' @@ -2818,8 +2817,8 @@ def test_toy_modaltsoftname(self): yot_name += '.lua' # modules for both installations with alternative name should be there - self.assertTrue(os.path.exists(os.path.join(modules_path, 'toytwo', toytwo_name))) - self.assertTrue(os.path.exists(os.path.join(modules_path, 'yot', yot_name))) + self.assertExists(os.path.join(modules_path, 'toytwo', toytwo_name)) + self.assertExists(os.path.join(modules_path, 'yot', yot_name)) # only subdirectories for software should be created self.assertEqual(sorted(os.listdir(software_path)), sorted(['toy', '.locks'])) @@ -3380,7 +3379,7 @@ def test_toy_ghost_installdir(self): self.assertFalse(stdout) regex = re.compile("WARNING: Likely ghost installation directory detected: %s" % toy_installdir) self.assertTrue(regex.search(stderr), "Pattern '%s' found in: %s" % (regex.pattern, stderr)) - self.assertTrue(os.path.exists(toy_installdir)) + self.assertExists(toy_installdir) # cleanup of ghost installation directories can be enable via --remove-ghost-install-dirs write_file(toy_modfile, dummy_toy_mod_txt) @@ -3391,7 +3390,7 @@ def test_toy_ghost_installdir(self): regex = re.compile("^== Ghost installation directory %s removed" % toy_installdir) self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout)) - self.assertFalse(os.path.exists(toy_installdir)) + self.assertNotExists(toy_installdir) def test_toy_build_lock(self): """Test toy installation when a lock is already in place.""" @@ -3407,11 +3406,11 @@ def test_toy_build_lock(self): self.assertErrorRegex(EasyBuildError, error_pattern, self.test_toy_build, raise_error=True, verbose=False) # lock should still be there after it was hit - self.assertTrue(os.path.exists(toy_lock_path)) + self.assertExists(toy_lock_path) # trying again should give same result self.assertErrorRegex(EasyBuildError, error_pattern, self.test_toy_build, raise_error=True, verbose=False) - self.assertTrue(os.path.exists(toy_lock_path)) + self.assertExists(toy_lock_path) locks_dir = os.path.join(self.test_prefix, 'locks') @@ -3474,7 +3473,7 @@ def __exit__(self, type, value, traceback): if not os.path.exists(toy_lock_path): mkdir(toy_lock_path) - self.assertTrue(os.path.exists(toy_lock_path)) + self.assertExists(toy_lock_path) all_args = extra_args + opts @@ -3517,7 +3516,7 @@ def __exit__(self, type, value, traceback): remove_dir(toy_lock_path) for opt in ['--wait-on-lock=1', '--wait-on-lock-limit=3', '--wait-on-lock-interval=1']: all_args = extra_args + [opt] - self.assertFalse(os.path.exists(toy_lock_path)) + self.assertNotExists(toy_lock_path) self.mock_stderr(True) self.mock_stdout(True) self.test_toy_build(extra_args=all_args, verify=False, raise_error=True, testing=False) @@ -3542,7 +3541,7 @@ def test_toy_lock_cleanup_signals(self): orig_wd = os.getcwd() locks_dir = os.path.join(self.test_installpath, 'software', '.locks') - self.assertFalse(os.path.exists(locks_dir)) + self.assertNotExists(locks_dir) orig_sigalrm_handler = signal.getsignal(signal.SIGALRM) @@ -3634,12 +3633,12 @@ def test_toy_build_lib64_lib_symlink(self): lib64_path = os.path.join(toy_installdir, 'lib64') # lib64 subdir exists, is not a symlink - self.assertTrue(os.path.exists(lib_path)) + self.assertExists(lib_path) self.assertTrue(os.path.isdir(lib_path)) self.assertFalse(os.path.islink(lib_path)) # lib64 subdir is a symlink to lib subdir - self.assertTrue(os.path.exists(lib64_path)) + self.assertExists(lib64_path) self.assertTrue(os.path.islink(lib64_path)) self.assertTrue(os.path.samefile(lib_path, lib64_path)) @@ -3650,8 +3649,8 @@ def test_toy_build_lib64_lib_symlink(self): remove_dir(self.test_installpath) self.test_toy_build(extra_args=['--disable-lib64-lib-symlink']) - self.assertTrue(os.path.exists(lib_path)) - self.assertFalse(os.path.exists(lib64_path)) + self.assertExists(lib_path) + self.assertNotExists(lib64_path) self.assertNotIn('lib64', os.listdir(toy_installdir)) self.assertTrue(os.path.isdir(lib_path)) self.assertFalse(os.path.islink(lib_path)) @@ -3676,12 +3675,12 @@ def test_toy_build_lib_lib64_symlink(self): lib64_path = os.path.join(toy_installdir, 'lib64') # lib64 subdir exists, is not a symlink - self.assertTrue(os.path.exists(lib64_path)) + self.assertExists(lib64_path) self.assertTrue(os.path.isdir(lib64_path)) self.assertFalse(os.path.islink(lib64_path)) # lib subdir is a symlink to lib64 subdir - self.assertTrue(os.path.exists(lib_path)) + self.assertExists(lib_path) self.assertTrue(os.path.isdir(lib_path)) self.assertTrue(os.path.islink(lib_path)) self.assertTrue(os.path.samefile(lib_path, lib64_path)) @@ -3693,8 +3692,8 @@ def test_toy_build_lib_lib64_symlink(self): remove_dir(self.test_installpath) self.test_toy_build(ec_file=test_ec, extra_args=['--disable-lib-lib64-symlink']) - self.assertTrue(os.path.exists(lib64_path)) - self.assertFalse(os.path.exists(lib_path)) + self.assertExists(lib64_path) + self.assertNotExists(lib_path) self.assertNotIn('lib', os.listdir(toy_installdir)) self.assertTrue(os.path.isdir(lib64_path)) self.assertFalse(os.path.islink(lib64_path)) From 2aae57c62ac59dc9038078618f6910802eee89ce Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Thu, 2 Feb 2023 12:36:57 +0100 Subject: [PATCH 2/3] Use SHA256 hash for PYPI URL test --- test/framework/filetools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/framework/filetools.py b/test/framework/filetools.py index c8b230fe3d..a627f7ee30 100644 --- a/test/framework/filetools.py +++ b/test/framework/filetools.py @@ -1584,7 +1584,7 @@ def test_pypi_source_urls(self): res = ft.pypi_source_urls('easybuild') eb340_url = 'https://pypi.python.org/packages/' eb340_url += '93/41/574d01f352671fbc8589a436167e15a7f3e27ac0aa635d208eb29ee8fd4e/' - eb340_url += 'easybuild-3.4.0.tar.gz#md5=267a056a77a8f77fccfbf56354364045' + eb340_url += 'easybuild-3.4.0.tar.gz#sha256=d870b27211f2224aab89bfd3279834ffb89ff00ad849a0dc2bf5cc1691efa9d2' self.assertIn(eb340_url, res) pattern = '^https://pypi.python.org/packages/[a-f0-9]{2}/[a-f0-9]{2}/[a-f0-9]{60}/' pattern_md5 = pattern + 'easybuild-[0-9a-z.]+.tar.gz#md5=[a-f0-9]{32}$' From 5285d9ccd096c2665a1d15e231800eb37f1e83d6 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 21 Feb 2023 17:54:52 +0100 Subject: [PATCH 3/3] Fix some wrong replacements of assert calls As suggested in review by @jfgrimm --- test/framework/easyblock.py | 2 +- test/framework/easyconfigparser.py | 2 +- test/framework/filetools.py | 3 ++- test/framework/systemtools.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/framework/easyblock.py b/test/framework/easyblock.py index 073337514b..51009196c5 100644 --- a/test/framework/easyblock.py +++ b/test/framework/easyblock.py @@ -1783,7 +1783,7 @@ def test_obtain_file(self): if res is not None: loc = os.path.join(tmpdir, 't', 'toy', fn) self.assertEqual(res, loc) - self.assertExists(loc), "%s file is found at %s" % (fn, loc) + self.assertExists(loc) txt = read_file(loc) eb_regex = re.compile("EasyBuild: building software with ease") self.assertTrue(eb_regex.search(txt), "Pattern '%s' found in: %s" % (eb_regex.pattern, txt)) diff --git a/test/framework/easyconfigparser.py b/test/framework/easyconfigparser.py index fbe8c6958c..9a17d8f0a5 100644 --- a/test/framework/easyconfigparser.py +++ b/test/framework/easyconfigparser.py @@ -198,7 +198,7 @@ def test_easyconfig_constants(self): # make sure both keys and values are of appropriate types for constant_name in constants: - self.assertIsInstance(constant_name, string_type) + self.assertIsInstance(constant_name, string_type, "Constant name %s is a string" % constant_name) val = constants[constant_name] fail_msg = "The constant %s should have an acceptable type, found %s (%s)" % (constant_name, type(val), str(val)) diff --git a/test/framework/filetools.py b/test/framework/filetools.py index a627f7ee30..886cd57c74 100644 --- a/test/framework/filetools.py +++ b/test/framework/filetools.py @@ -2328,7 +2328,8 @@ def test_remove(self): ft.write_file(testfile, 'bar') ft.mkdir(test_dir) self.assertExists(testfile) - self.assertExists(test_dir) and os.path.isdir(test_dir) + self.assertExists(test_dir) + self.assertTrue(os.path.isdir(test_dir)) ft.remove([testfile, test_dir]) self.assertNotExists(testfile) self.assertNotExists(test_dir) diff --git a/test/framework/systemtools.py b/test/framework/systemtools.py index 893b37103d..8258794698 100644 --- a/test/framework/systemtools.py +++ b/test/framework/systemtools.py @@ -401,7 +401,7 @@ def tearDown(self): def test_avail_core_count_native(self): """Test getting core count.""" core_count = get_avail_core_count() - self.assertIsInstance(core_count, int), "core_count has type int: %s, %s" % (core_count, type(core_count)) + self.assertIsInstance(core_count, int) self.assertTrue(core_count > 0, "core_count %d > 0" % core_count) def test_avail_core_count_linux(self):