commit b3b49f72e3073e4fb3176042c754b54ff73b6245 Author: Damian Johnson atagar@torproject.org Date: Tue Jul 12 10:04:15 2016 -0700
Test _draw_line()
Don't care for how many attributes this little helper needs but oh well. Shortens the draw() method and delegates it to mostly determine column dimensions. --- nyx/panel/config.py | 26 +++++++++++++++++--------- test/panel/config.py | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/nyx/panel/config.py b/nyx/panel/config.py index eea135d..f3e747a 100644 --- a/nyx/panel/config.py +++ b/nyx/panel/config.py @@ -272,15 +272,7 @@ class ConfigPanel(nyx.panel.Panel): value_width = VALUE_WIDTH
for i, entry in enumerate(contents[scroll:]): - attr = [CONFIG['attr.config.category_color'].get(entry.manual.category, WHITE)] - attr.append(BOLD if entry.is_set() else NORMAL) - attr.append(HIGHLIGHT if entry == selected else NORMAL) - - option_label = str_tools.crop(entry.name, NAME_WIDTH).ljust(NAME_WIDTH + 1) - value_label = str_tools.crop(entry.value(), value_width).ljust(value_width + 1) - summary_label = str_tools.crop(entry.manual.summary, description_width).ljust(description_width) - - subwindow.addstr(scroll_offset, DETAILS_HEIGHT + i, option_label + value_label + summary_label, *attr) + _draw_line(subwindow, scroll_offset, DETAILS_HEIGHT + i, entry, entry == selected, value_width, description_width)
if DETAILS_HEIGHT + i >= subwindow.height: break @@ -289,6 +281,22 @@ class ConfigPanel(nyx.panel.Panel): return self._contents if self._show_all else filter(lambda entry: stem.manual.is_important(entry.name) or entry.is_set(), self._contents)
+def _draw_line(subwindow, x, y, entry, is_selected, value_width, description_width): + """ + Show an individual configuration line. + """ + + attr = [CONFIG['attr.config.category_color'].get(entry.manual.category, WHITE)] + attr.append(BOLD if entry.is_set() else NORMAL) + attr.append(HIGHLIGHT if is_selected else NORMAL) + + option_label = str_tools.crop(entry.name, NAME_WIDTH).ljust(NAME_WIDTH + 1) + value_label = str_tools.crop(entry.value(), value_width).ljust(value_width + 1) + summary_label = str_tools.crop(entry.manual.summary, description_width).ljust(description_width) + + subwindow.addstr(x, y, option_label + value_label + summary_label, *attr) + + def _draw_selection_details(subwindow, selected): """ Shows details of the currently selected option. diff --git a/test/panel/config.py b/test/panel/config.py index 19db206..0289406 100644 --- a/test/panel/config.py +++ b/test/panel/config.py @@ -11,6 +11,8 @@ import test from test import require_curses from mock import patch
+EXPECTED_LINE = 'ControlPort 9051 Port providing access to tor...' + EXPECTED_DETAIL_DIALOG = """ +------------------------------------------------------------------------------+ | ControlPort (General Option) | @@ -26,6 +28,18 @@ EXPECTED_DETAIL_DIALOG = """ class TestConfigPanel(unittest.TestCase): @require_curses @patch('nyx.panel.config.tor_controller') + def test_draw_line(self, tor_controller_mock): + tor_controller_mock().get_info.return_value = True + tor_controller_mock().get_conf.return_value = ['9051'] + + manual = stem.manual.Manual.from_cache() + entry = nyx.panel.config.ConfigEntry('ControlPort', 'LineList', manual) + + rendered = test.render(nyx.panel.config._draw_line, 0, 0, entry, False, 10, 35) + self.assertEqual(EXPECTED_LINE, rendered.content) + + @require_curses + @patch('nyx.panel.config.tor_controller') def test_draw_selection_details(self, tor_controller_mock): tor_controller_mock().get_info.return_value = True tor_controller_mock().get_conf.return_value = ['9051']
tor-commits@lists.torproject.org