Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Jul 26, 2022
1 parent 1807d48 commit eb94c51
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
8 changes: 8 additions & 0 deletions easybuild/base/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ def mocked_stdout_stderr(self, mock_stdout=True, mock_stderr=True):
if mock_stderr:
self.mock_stderr(False)

@contextmanager
def mocked_stderr(self):
self.mock_stderr(True)
try:
yield sys.stderr
finally:
self.mock_stderr(False)

def tearDown(self):
"""Cleanup after running a test."""
self.mock_stdout(False)
Expand Down
34 changes: 17 additions & 17 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2088,87 +2088,87 @@ def test_parallel(self):
self.assertEqual(test_eb.cfg.parallel, auto_parallel)

# only 'parallel' easyconfig parameter specified (no 'parallel' build option)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
test_eb = EasyBlock(EasyConfig(toy_ec1))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 123)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 123)

# both 'parallel' and 'maxparallel' easyconfig parameters specified (no 'parallel' build option)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
test_eb = EasyBlock(EasyConfig(toy_ec2))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 67)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 67)

# make sure 'parallel = False' is not overriden (no 'parallel' build option)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
test_eb = EasyBlock(EasyConfig(toy_ec3))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, False)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], False)

# only 'maxparallel' easyconfig parameter specified (no 'parallel' build option)
test_eb = EasyBlock(EasyConfig(toy_ec4))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 67)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 67)

# make sure 'maxparallel = False' is treated as 1 (no 'parallel' build option)
test_eb = EasyBlock(EasyConfig(toy_ec5))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 1)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 1)

# only 'parallel' build option specified
init_config(build_options={'parallel': '97', 'validate': False})
test_eb = EasyBlock(EasyConfig(toy_ec))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 97)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 97)

# both 'parallel' build option and easyconfig parameter specified (no 'maxparallel')
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
test_eb = EasyBlock(EasyConfig(toy_ec1))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 97)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 97)

# both 'parallel' and 'maxparallel' easyconfig parameters specified + 'parallel' build option
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
test_eb = EasyBlock(EasyConfig(toy_ec2))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 67)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 67)

# make sure 'parallel = False' is not overriden (with 'parallel' build option)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
test_eb = EasyBlock(EasyConfig(toy_ec3))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 0)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 0)

# only 'maxparallel' easyconfig parameter specified (with 'parallel' build option)
test_eb = EasyBlock(EasyConfig(toy_ec4))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 67)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 67)

# make sure 'maxparallel = False' is treated as 1 (with 'parallel' build option)
test_eb = EasyBlock(EasyConfig(toy_ec5))
test_eb.check_readiness_step()
self.assertEqual(test_eb.cfg.parallel, 1)
with self.temporarily_allow_deprecated_behaviour():
with self.temporarily_allow_deprecated_behaviour(), self.mocked_stderr():
self.assertEqual(test_eb.cfg['parallel'], 1)

# Template updated correctly
Expand Down
1 change: 0 additions & 1 deletion test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3078,7 +3078,6 @@ def test_template_constant_dict(self):

res = template_constant_dict(ec)
res.pop('arch')
expected['parallel'] = 42
self.assertEqual(res, expected)

toy_ec = os.path.join(test_ecs_dir, 't', 'toy', 'toy-0.0-deps.eb')
Expand Down
2 changes: 1 addition & 1 deletion test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def test_ignore_test_failure(self):

args = [toy_ec, '--ignore-test-failure', '--force']

with self.mocked_stdout_stderr() as (_, stderr):
with self.mocked_stderr() as stderr:
outtxt = self.eb_main(args, do_build=True)

msg = 'Test failure ignored'
Expand Down

0 comments on commit eb94c51

Please sign in to comment.