From d139e26a1cd16f74502ead02159dd24d94e3eb1d Mon Sep 17 00:00:00 2001 From: alexzorin Date: Fri, 10 Sep 2021 05:10:27 +1000 Subject: [PATCH] fix 'NEXT STEPS' being printed to stdout during -q (#9023) @osirisinferi noticed [in chat](https://opensource.eff.org/eff-open-source/pl/sa85u4n71tywfpc15c1wu59wae) that "NEXT STEPS:" was ignoring `--quiet` and was being printed unconditionally. I think it ended up being written this way in #8860 because I was trying not to avoid dumping ANSI escapes and newlines into the log file and confused myself in the process. This change makes things a bit more explicit in separating presentation/message. * fix 'NEXT STEPS' being printed to stdout during -q * fix tests --- certbot/certbot/_internal/main.py | 8 +++++--- certbot/tests/main_test.py | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/certbot/certbot/_internal/main.py b/certbot/certbot/_internal/main.py index 659d00888..c26cc7b9f 100644 --- a/certbot/certbot/_internal/main.py +++ b/certbot/certbot/_internal/main.py @@ -526,10 +526,12 @@ def _report_next_steps(config: configuration.NamespaceConfig, installer_err: Opt return # TODO: refactor ANSI escapes during https://github.com/certbot/certbot/issues/8848 - (bold_on, bold_off) = [c if sys.stdout.isatty() and not config.quiet else '' \ - for c in (util.ANSI_SGR_BOLD, util.ANSI_SGR_RESET)] + (bold_on, nl, bold_off) = [c if sys.stdout.isatty() and not config.quiet else '' \ + for c in (util.ANSI_SGR_BOLD, '\n', util.ANSI_SGR_RESET)] + print(bold_on, end=nl) + display_util.notify("NEXT STEPS:") + print(bold_off, end='') - print(bold_on, '\n', 'NEXT STEPS:', bold_off, sep='') for step in steps: display_util.notify(f"- {step}") diff --git a/certbot/tests/main_test.py b/certbot/tests/main_test.py index 3fd71b153..8c4ab883e 100644 --- a/certbot/tests/main_test.py +++ b/certbot/tests/main_test.py @@ -1934,8 +1934,9 @@ class ReportNextStepsTest(unittest.TestCase): _report_next_steps(*args, **kwargs) def _output(self) -> str: - self.mock_notify.assert_called_once() - return self.mock_notify.call_args_list[0][0][0] + self.assertEqual(self.mock_notify.call_count, 2) + self.assertEqual(self.mock_notify.call_args_list[0][0][0], 'NEXT STEPS:') + return self.mock_notify.call_args_list[1][0][0] def test_report(self): """No steps for a normal renewal"""