Skip to content

Commit

Permalink
enhance test for print_warning to test passing of logger via 'log' ar…
Browse files Browse the repository at this point in the history
…gument
  • Loading branch information
boegel committed Feb 29, 2020
1 parent 022e3a7 commit e8d7235
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/framework/build_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ def test_log_levels(self):

def test_print_warning(self):
"""Test print_warning"""
def run_check(args, silent=False, expected_stderr=''):
def run_check(args, silent=False, expected_stderr='', **kwargs):
"""Helper function to check stdout/stderr produced via print_warning."""
self.mock_stderr(True)
self.mock_stdout(True)
print_warning(*args, silent=silent)
print_warning(*args, silent=silent, **kwargs)
stderr = self.get_stderr()
stdout = self.get_stdout()
self.mock_stdout(False)
Expand All @@ -258,6 +258,14 @@ def run_check(args, silent=False, expected_stderr=''):

self.assertErrorRegex(EasyBuildError, "Unknown named arguments", print_warning, 'foo', unknown_arg='bar')

# test passing of logger to print_warning
tmp_logfile = os.path.join(self.test_prefix, 'test.log')
logger, _ = init_logging(tmp_logfile, silent=True)
expected = "\nWARNING: Test log message with a logger involved.\n\n"
run_check(["Test log message with a logger involved."], expected_stderr=expected, log=logger)
log_txt = read_file(tmp_logfile)
self.assertTrue("WARNING Test log message with a logger involved." in log_txt)

def test_print_error(self):
"""Test print_error"""
def run_check(args, silent=False, expected_stderr=''):
Expand Down

0 comments on commit e8d7235

Please sign in to comment.