Skip to content

Commit df6f14f

Browse files
committed
Replace more usages of assertTrue/False
1 parent 7ba437b commit df6f14f

24 files changed

Lines changed: 373 additions & 363 deletions

test/framework/build_log.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,26 +388,26 @@ def test_init_logging(self):
388388
tmp_logfile = os.path.join(self.test_prefix, 'test.log')
389389
log, logfile = init_logging(tmp_logfile, silent=True)
390390
self.assertEqual(logfile, tmp_logfile)
391-
self.assertTrue(os.path.exists(logfile))
392-
self.assertTrue(isinstance(log, EasyBuildLog))
391+
self.assertExists(logfile)
392+
self.assertIsInstance(log, EasyBuildLog)
393393

394394
stop_logging(logfile)
395395

396396
# no log provided, so create one (should be file in $TMPDIR)
397397
log, logfile = init_logging(None, silent=True)
398-
self.assertTrue(os.path.exists(logfile))
398+
self.assertExists(logfile)
399399
self.assertEqual(os.path.dirname(logfile), tmpdir)
400-
self.assertTrue(isinstance(log, EasyBuildLog))
400+
self.assertIsInstance(log, EasyBuildLog)
401401

402402
stop_logging(logfile)
403403

404404
# no problem with specifying a different directory to put log file in (even if it doesn't exist yet)
405405
tmp_logdir = os.path.join(self.test_prefix, 'tmp_logs')
406-
self.assertFalse(os.path.exists(tmp_logdir))
406+
self.assertNotExists(tmp_logdir)
407407

408408
log, logfile = init_logging(None, silent=True, tmp_logdir=tmp_logdir)
409409
self.assertEqual(os.path.dirname(logfile), tmp_logdir)
410-
self.assertTrue(isinstance(log, EasyBuildLog))
410+
self.assertIsInstance(log, EasyBuildLog)
411411

412412
stop_logging(logfile)
413413

@@ -416,9 +416,9 @@ def test_init_logging(self):
416416
log, logfile = init_logging(None)
417417
stdout = self.get_stdout()
418418
self.mock_stdout(False)
419-
self.assertTrue(os.path.exists(logfile))
419+
self.assertExists(logfile)
420420
self.assertEqual(os.path.dirname(logfile), tmpdir)
421-
self.assertTrue(isinstance(log, EasyBuildLog))
421+
self.assertIsInstance(log, EasyBuildLog)
422422
self.assertTrue(stdout.startswith("== Temporary log file in case of crash"))
423423

424424
stop_logging(logfile)
@@ -428,7 +428,7 @@ def test_init_logging(self):
428428
log, logfile = init_logging(None, logtostdout=True)
429429
self.mock_stdout(False)
430430
self.assertEqual(logfile, None)
431-
self.assertTrue(isinstance(log, EasyBuildLog))
431+
self.assertIsInstance(log, EasyBuildLog)
432432

433433
stop_logging(logfile, logtostdout=True)
434434

test/framework/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ def test_configuration_variables(self):
341341
cv1 = ConfigurationVariables()
342342
cv2 = ConfigurationVariables()
343343
cv3 = ConfigurationVariables({'foo': 'bar'}) # note: argument is ignored, an instance is already available
344-
self.assertTrue(cv1 is cv2)
345-
self.assertTrue(cv1 is cv3)
344+
self.assertIs(cv1, cv2)
345+
self.assertIs(cv1, cv3)
346346

347347
def test_build_options(self):
348348
"""Test usage of BuildOptions."""
@@ -353,8 +353,8 @@ def test_build_options(self):
353353
bo1 = BuildOptions()
354354
bo2 = BuildOptions()
355355
bo3 = BuildOptions({'foo': 'bar'}) # note: argument is ignored, an instance is already available
356-
self.assertTrue(bo1 is bo2)
357-
self.assertTrue(bo1 is bo3)
356+
self.assertIs(bo1, bo2)
357+
self.assertIs(bo1, bo3)
358358

359359
# test basic functionality
360360
BuildOptions.__class__._instances.clear()
@@ -394,7 +394,7 @@ def test_build_options(self):
394394

395395
# there should be only one BuildOptions instance
396396
bo2 = BuildOptions()
397-
self.assertTrue(bo is bo2)
397+
self.assertIs(bo, bo2)
398398

399399
def test_XDG_CONFIG_env_vars(self):
400400
"""Test effect of XDG_CONFIG* environment variables on default configuration."""

test/framework/containers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def test_end2end_singularity_image(self):
308308
]
309309
self.check_regexs(regexs, stdout)
310310

311-
self.assertTrue(os.path.exists(os.path.join(containerpath, 'toy-0.0.%s' % ext)))
311+
self.assertExists(os.path.join(containerpath, 'toy-0.0.%s' % ext))
312312

313313
remove_file(os.path.join(containerpath, 'Singularity.toy-0.0'))
314314

@@ -330,7 +330,7 @@ def test_end2end_singularity_image(self):
330330
self.check_regexs(regexs, stdout)
331331

332332
cont_img = os.path.join(containerpath, 'foo-bar.img')
333-
self.assertTrue(os.path.exists(cont_img))
333+
self.assertExists(cont_img)
334334

335335
remove_file(os.path.join(containerpath, 'Singularity.foo-bar'))
336336

@@ -348,7 +348,7 @@ def test_end2end_singularity_image(self):
348348
"WARNING: overwriting existing container image at %s due to --force" % cont_img,
349349
])
350350
self.check_regexs(regexs, stdout)
351-
self.assertTrue(os.path.exists(cont_img))
351+
self.assertExists(cont_img)
352352

353353
# also check behaviour under --extended-dry-run
354354
args.append('--extended-dry-run')

test/framework/easyblock.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ def check_extra_options_format(extra_options):
8585
"""Make sure extra_options value is of correct format."""
8686
# EasyBuild v2.0: dict with <string> keys and <list> values
8787
# (breaks backward compatibility compared to v1.x)
88-
self.assertTrue(isinstance(extra_options, dict)) # conversion to a dict works
88+
self.assertIsInstance(extra_options, dict) # conversion to a dict works
8989
extra_options.items()
9090
extra_options.keys()
9191
extra_options.values()
9292
for key in extra_options.keys():
93-
self.assertTrue(isinstance(extra_options[key], list))
93+
self.assertIsInstance(extra_options[key], list)
9494
self.assertEqual(len(extra_options[key]), 3)
9595

9696
name = "pi"
@@ -201,7 +201,7 @@ def test_load_module(self):
201201

202202
# we expect $TMPDIR to be tweaked by the prepare step (OpenMPI 2.x doesn't like long $TMPDIR values)
203203
tweaked_tmpdir = os.environ.get('TMPDIR')
204-
self.assertTrue(tweaked_tmpdir != orig_tmpdir)
204+
self.assertNotEqual(tweaked_tmpdir, orig_tmpdir)
205205

206206
eb.make_module_step()
207207
eb.load_module()
@@ -233,7 +233,7 @@ def test_fake_module_load(self):
233233
if get_module_syntax() == 'Lua':
234234
pi_modfile += '.lua'
235235

236-
self.assertTrue(os.path.exists(pi_modfile))
236+
self.assertExists(pi_modfile)
237237

238238
# check whether temporary module file is marked as default
239239
if get_module_syntax() == 'Lua':
@@ -667,7 +667,7 @@ def test_make_module_extra(self):
667667
if get_module_syntax() == 'Lua':
668668
modpath += '.lua'
669669

670-
self.assertTrue(os.path.exists(modpath), "%s exists" % modpath)
670+
self.assertExists(modpath)
671671
txt = read_file(modpath)
672672
patterns = [
673673
r"^prepend[-_]path.*TEST_PATH_VAR.*root.*foo",
@@ -1202,7 +1202,7 @@ def test_make_module_step(self):
12021202
modpath = os.path.join(eb.make_module_step(), name, version)
12031203
if get_module_syntax() == 'Lua':
12041204
modpath += '.lua'
1205-
self.assertTrue(os.path.exists(modpath), "%s exists" % modpath)
1205+
self.assertExists(modpath)
12061206

12071207
# verify contents of module
12081208
txt = read_file(modpath)
@@ -1373,13 +1373,13 @@ def test_make_builddir(self):
13731373
builddir = eb.builddir
13741374
testfile = os.path.join(builddir, 'test123', 'foobar.txt')
13751375
write_file(testfile, 'test123')
1376-
self.assertTrue(os.path.exists(testfile))
1376+
self.assertExists(testfile)
13771377

13781378
eb.make_builddir()
13791379
self.assertEqual(builddir, eb.builddir)
13801380
# file is gone because directory was removed and re-created
1381-
self.assertFalse(os.path.exists(testfile))
1382-
self.assertFalse(os.path.exists(os.path.dirname(testfile)))
1381+
self.assertNotExists(testfile)
1382+
self.assertNotExists(os.path.dirname(testfile))
13831383
self.assertEqual(os.listdir(eb.builddir), [])
13841384

13851385
# 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):
13911391
builddir = eb.builddir
13921392
testfile = os.path.join(builddir, 'test123', 'foobar.txt')
13931393
write_file(testfile, 'test123')
1394-
self.assertTrue(os.path.exists(testfile))
1394+
self.assertExists(testfile)
13951395
self.assertEqual(os.listdir(eb.builddir), ['test123'])
13961396
self.assertEqual(os.listdir(os.path.join(eb.builddir, 'test123')), ['foobar.txt'])
13971397

@@ -1400,7 +1400,7 @@ def test_make_builddir(self):
14001400
eb.make_builddir()
14011401
eb.make_installdir()
14021402
self.assertEqual(builddir, eb.builddir)
1403-
self.assertTrue(os.path.exists(testfile))
1403+
self.assertExists(testfile)
14041404
self.assertEqual(os.listdir(eb.builddir), ['test123'])
14051405
self.assertEqual(os.listdir(os.path.join(eb.builddir, 'test123')), ['foobar.txt'])
14061406

@@ -1409,8 +1409,8 @@ def test_make_builddir(self):
14091409
eb.make_builddir()
14101410
eb.make_installdir()
14111411
self.assertEqual(builddir, eb.builddir)
1412-
self.assertFalse(os.path.exists(testfile))
1413-
self.assertFalse(os.path.exists(os.path.dirname(testfile)))
1412+
self.assertNotExists(testfile)
1413+
self.assertNotExists(os.path.dirname(testfile))
14141414
self.assertEqual(os.listdir(eb.builddir), [])
14151415

14161416
def test_get_easyblock_instance(self):
@@ -1420,7 +1420,7 @@ def test_get_easyblock_instance(self):
14201420

14211421
ec = process_easyconfig(os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb'))[0]
14221422
eb = get_easyblock_instance(ec)
1423-
self.assertTrue(isinstance(eb, EB_toy))
1423+
self.assertIsInstance(eb, EB_toy)
14241424

14251425
# check whether 'This is easyblock' log message is there
14261426
tup = ('EB_toy', 'easybuild.easyblocks.toy', '.*test/framework/sandbox/easybuild/easyblocks/t/toy.pyc*')
@@ -1482,9 +1482,9 @@ def test_fetch_sources(self):
14821482
self.assertEqual(len(eb.src), 3)
14831483
for idx in range(3):
14841484
self.assertEqual(eb.src[idx]['name'], expected_sources[idx])
1485-
self.assertTrue(os.path.exists(eb.src[idx]['path']))
1485+
self.assertExists(eb.src[idx]['path'])
14861486
source_loc = os.path.join(toy_source_dir, expected_sources[idx])
1487-
self.assertTrue(os.path.exists(source_loc))
1487+
self.assertExists(source_loc)
14881488
self.assertTrue(os.path.samefile(eb.src[idx]['path'], source_loc))
14891489
self.assertEqual(eb.src[0]['cmd'], None)
14901490
self.assertEqual(eb.src[1]['cmd'], "gunzip %s")
@@ -1750,7 +1750,7 @@ def test_obtain_file(self):
17501750

17511751
# toy tarball was indeed re-downloaded to tmpdir
17521752
self.assertEqual(res, os.path.join(tmpdir, 't', 'toy', toy_tarball))
1753-
self.assertTrue(os.path.exists(os.path.join(tmpdir, 't', 'toy', toy_tarball)))
1753+
self.assertExists(os.path.join(tmpdir, 't', 'toy', toy_tarball))
17541754

17551755
# obtain_file yields error for non-existing files
17561756
fn = 'thisisclearlyanonexistingfile'
@@ -1783,7 +1783,7 @@ def test_obtain_file(self):
17831783
if res is not None:
17841784
loc = os.path.join(tmpdir, 't', 'toy', fn)
17851785
self.assertEqual(res, loc)
1786-
self.assertTrue(os.path.exists(loc), "%s file is found at %s" % (fn, loc))
1786+
self.assertExists(loc), "%s file is found at %s" % (fn, loc)
17871787
txt = read_file(loc)
17881788
eb_regex = re.compile("EasyBuild: building software with ease")
17891789
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):
18331833

18341834
exts_file_info = toy_eb.collect_exts_file_info()
18351835

1836-
self.assertTrue(isinstance(exts_file_info, list))
1836+
self.assertIsInstance(exts_file_info, list)
18371837
self.assertEqual(len(exts_file_info), 4)
18381838

18391839
self.assertEqual(exts_file_info[0], {'name': 'ls'})
@@ -1858,7 +1858,7 @@ def test_collect_exts_file_info(self):
18581858
# location of files is missing when fetch_files is set to False
18591859
exts_file_info = toy_eb.collect_exts_file_info(fetch_files=False, verify_checksums=False)
18601860

1861-
self.assertTrue(isinstance(exts_file_info, list))
1861+
self.assertIsInstance(exts_file_info, list)
18621862
self.assertEqual(len(exts_file_info), 4)
18631863

18641864
self.assertEqual(exts_file_info[0], {'name': 'ls'})
@@ -1897,7 +1897,7 @@ def test_obtain_file_extension(self):
18971897
ext = ExtensionEasyBlock(toy_eb, test_ext)
18981898
ext_src_path = ext.obtain_file(test_ext_src_fn)
18991899
self.assertEqual(os.path.basename(ext_src_path), 'toy-0.0.tar.gz')
1900-
self.assertTrue(os.path.exists(ext_src_path))
1900+
self.assertExists(ext_src_path)
19011901

19021902
def test_check_readiness(self):
19031903
"""Test check_readiness method."""
@@ -2135,7 +2135,7 @@ def test_guess_start_dir(self):
21352135
ec = process_easyconfig(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'))[0]
21362136

21372137
cwd = os.getcwd()
2138-
self.assertTrue(os.path.exists(cwd))
2138+
self.assertExists(cwd)
21392139

21402140
def check_start_dir(expected_start_dir):
21412141
"""Check start dir."""
@@ -2170,7 +2170,7 @@ def test_extension_set_start_dir(self):
21702170
ec = process_easyconfig(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'))[0]
21712171

21722172
cwd = os.getcwd()
2173-
self.assertTrue(os.path.exists(cwd))
2173+
self.assertExists(cwd)
21742174

21752175
def check_ext_start_dir(expected_start_dir):
21762176
"""Check start dir."""
@@ -2608,8 +2608,8 @@ def run_checks():
26082608
def test_this_is_easybuild(self):
26092609
"""Test 'this_is_easybuild' function (and get_git_revision function used by it)."""
26102610
# make sure both return a non-Unicode string
2611-
self.assertTrue(isinstance(get_git_revision(), str))
2612-
self.assertTrue(isinstance(this_is_easybuild(), str))
2611+
self.assertIsInstance(get_git_revision(), str)
2612+
self.assertIsInstance(this_is_easybuild(), str)
26132613

26142614
def test_stale_module_caches(self):
26152615
"""Test whether module caches are reset between builds."""

0 commit comments

Comments
 (0)