Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions easybuild/base/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Kenneth Hoste (Ghent University)
"""
import difflib
import os
import pprint
import re
import sys
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions test/framework/build_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions test/framework/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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()
Expand Down Expand Up @@ -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."""
Expand Down
6 changes: 3 additions & 3 deletions test/framework/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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'))

Expand All @@ -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')
Expand Down
50 changes: 25 additions & 25 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string> keys and <list> 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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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'])

Expand All @@ -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'])

Expand All @@ -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):
Expand All @@ -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*')
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
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))
Expand Down Expand Up @@ -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'})
Expand All @@ -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'})
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down
Loading