"""Tests for certbot.reporter.""" import mock import sys import unittest import six class ReporterTest(unittest.TestCase): """Tests for certbot.reporter.Reporter.""" def setUp(self): from certbot import reporter self.reporter = reporter.Reporter(mock.MagicMock(quiet=False)) self.old_stdout = sys.stdout # type: ignore sys.stdout = six.StringIO() def tearDown(self): sys.stdout = self.old_stdout def test_multiline_message(self): self.reporter.add_message("Line 1\nLine 2", self.reporter.LOW_PRIORITY) self.reporter.print_messages() output = sys.stdout.getvalue() # type: ignore self.assertTrue("Line 1\n" in output) self.assertTrue("Line 2" in output) def test_tty_print_empty(self): sys.stdout.isatty = lambda: True # type: ignore self.test_no_tty_print_empty() def test_no_tty_print_empty(self): self.reporter.print_messages() self.assertEqual(sys.stdout.getvalue(), "") # type: ignore try: raise ValueError except ValueError: self.reporter.print_messages() self.assertEqual(sys.stdout.getvalue(), "") # type: ignore def test_tty_successful_exit(self): sys.stdout.isatty = lambda: True # type: ignore self._successful_exit_common() def test_no_tty_successful_exit(self): self._successful_exit_common() def test_tty_unsuccessful_exit(self): sys.stdout.isatty = lambda: True # type: ignore self._unsuccessful_exit_common() def test_no_tty_unsuccessful_exit(self): self._unsuccessful_exit_common() def _successful_exit_common(self): self._add_messages() self.reporter.print_messages() output = sys.stdout.getvalue() # type: ignore self.assertTrue("IMPORTANT NOTES:" in output) self.assertTrue("High" in output) self.assertTrue("Med" in output) self.assertTrue("Low" in output) def _unsuccessful_exit_common(self): self._add_messages() try: raise ValueError except ValueError: self.reporter.print_messages() output = sys.stdout.getvalue() # type: ignore self.assertTrue("IMPORTANT NOTES:" in output) self.assertTrue("High" in output) self.assertTrue("Med" not in output) self.assertTrue("Low" not in output) def _add_messages(self): self.reporter.add_message("High", self.reporter.HIGH_PRIORITY) self.reporter.add_message( "Med", self.reporter.MEDIUM_PRIORITY, on_crash=False) self.reporter.add_message( "Low", self.reporter.LOW_PRIORITY, on_crash=False) if __name__ == "__main__": unittest.main() # pragma: no cover
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
display | Folder | 0755 |
|
|
testdata | Folder | 0755 |
|
|
__init__.py | File | 20 B | 0644 |
|
account_test.py | File | 14.45 KB | 0644 |
|
acme_util.py | File | 3.18 KB | 0644 |
|
auth_handler_test.py | File | 24 KB | 0644 |
|
cert_manager_test.py | File | 28.07 KB | 0644 |
|
cli_test.py | File | 19.94 KB | 0644 |
|
client_test.py | File | 28.76 KB | 0644 |
|
compat_test.py | File | 736 B | 0644 |
|
configuration_test.py | File | 6.82 KB | 0644 |
|
crypto_util_test.py | File | 13.56 KB | 0644 |
|
eff_test.py | File | 5.94 KB | 0644 |
|
error_handler_test.py | File | 5.31 KB | 0644 |
|
errors_test.py | File | 1.8 KB | 0644 |
|
hook_test.py | File | 16.67 KB | 0644 |
|
lock_test.py | File | 3.84 KB | 0644 |
|
log_test.py | File | 14.95 KB | 0644 |
|
main_test.py | File | 82.52 KB | 0644 |
|
notify_test.py | File | 2.07 KB | 0644 |
|
ocsp_test.py | File | 6.27 KB | 0644 |
|
renewal_test.py | File | 4.18 KB | 0644 |
|
renewupdater_test.py | File | 5.32 KB | 0644 |
|
reporter_test.py | File | 2.73 KB | 0644 |
|
reverter_test.py | File | 18.7 KB | 0644 |
|
storage_test.py | File | 42.89 KB | 0644 |
|
util.py | File | 14.12 KB | 0644 |
|
util_test.py | File | 21.58 KB | 0644 |
|