Address review issues

This commit is contained in:
Peter Eckersley
2016-06-25 12:28:47 -07:00
parent 8a28cb7352
commit 23f0ccbc8e
2 changed files with 18 additions and 5 deletions
+16 -5
View File
@@ -1,4 +1,5 @@
"""Certbot display."""
import logging
import os
import textwrap
@@ -9,6 +10,9 @@ from certbot import interfaces
from certbot import errors
from certbot.display import completer
logger = logging.getLogger(__name__)
WIDTH = 72
HEIGHT = 20
@@ -29,6 +33,10 @@ CANCEL = "cancel"
HELP = "help"
"""Display exit code when for when the user requests more help."""
ESC = "esc"
"""Display exit code when the user hits Escape"""
def _wrap_lines(msg):
"""Format lines nicely to 80 chars.
@@ -52,7 +60,7 @@ def _wrap_lines(msg):
def _clean(dialog_result):
"""Work around inconsistent return codes from python-dialog.
"""Treat sundy python-dialog return codes as CANCEL
:param tuple dialog_result: (code, result)
:returns: the argument but with unknown codes set to -1 (Error)
@@ -61,7 +69,10 @@ def _clean(dialog_result):
code, result = dialog_result
if code in (OK, HELP):
return dialog_result
elif code in (CANCEL, ESC):
return (CANCEL, result)
else:
logger.info("Surprising dialog return code %s", code)
return (CANCEL, result)
@@ -199,8 +210,8 @@ class NcursesDisplay(object):
"""
choices = [(tag, "", default_status) for tag in tags]
return self.dialog.checklist(
message, width=self.width, height=self.height, choices=choices)
return _clean(self.dialog.checklist(
message, width=self.width, height=self.height, choices=choices))
def directory_select(self, message, **unused_kwargs):
"""Display a directory selection screen.
@@ -213,9 +224,9 @@ class NcursesDisplay(object):
"""
root_directory = os.path.abspath(os.sep)
return self.dialog.dselect(
return _clean(self.dialog.dselect(
filepath=root_directory, width=self.width,
height=self.height, help_button=True, title=message)
height=self.height, help_button=True, title=message))
@zope.interface.implementer(interfaces.IDisplay)
+2
View File
@@ -113,6 +113,7 @@ class NcursesDisplayTest(unittest.TestCase):
@mock.patch("certbot.display.util."
"dialog.Dialog.checklist")
def test_checklist(self, mock_checklist):
mock_checklist.return_value = (mock.MagicMock(), mock.MagicMock())
self.displayer.checklist("message", TAGS)
choices = [
@@ -126,6 +127,7 @@ class NcursesDisplayTest(unittest.TestCase):
@mock.patch("certbot.display.util.dialog.Dialog.dselect")
def test_directory_select(self, mock_dselect):
mock_dselect.return_value = (mock.MagicMock(), mock.MagicMock())
self.displayer.directory_select("message")
self.assertEqual(mock_dselect.call_count, 1)