[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Test _draw_selection_details()



commit 83163bab300d097375296f3719b834a34bc00713
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Jul 12 09:52:37 2016 -0700

    Test _draw_selection_details()
---
 nyx/panel/config.py    | 44 +++++++++++++++++++++++---------------------
 test/panel/__init__.py |  1 +
 test/panel/config.py   | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 21 deletions(-)

diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index 3b3d83b..eea135d 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -246,7 +246,7 @@ class ConfigPanel(nyx.panel.Panel):
     is_scrollbar_visible = len(contents) > subwindow.height - DETAILS_HEIGHT
 
     if selected is not None:
-      self._draw_selection_details(subwindow, selected)
+      _draw_selection_details(subwindow, selected)
 
     hidden_msg = "press 'a' to hide most options" if self._show_all else "press 'a' to show all options"
     subwindow.addstr(0, 0, 'Tor Configuration (%s):' % hidden_msg, HIGHLIGHT)
@@ -288,28 +288,30 @@ class ConfigPanel(nyx.panel.Panel):
   def _get_config_options(self):
     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_selection_details(self, subwindow, selected):
-    """
-    Shows details of the currently selected option.
-    """
 
-    description = 'Description: %s' % (selected.manual.description)
-    attr = ', '.join(('custom' if selected.is_set() else 'default', selected.value_type, 'usage: %s' % selected.manual.usage))
-    selected_color = CONFIG['attr.config.category_color'].get(selected.manual.category, WHITE)
-    subwindow.box(0, 0, subwindow.width, DETAILS_HEIGHT)
+def _draw_selection_details(subwindow, selected):
+  """
+  Shows details of the currently selected option.
+  """
 
-    subwindow.addstr(2, 1, '%s (%s Option)' % (selected.name, selected.manual.category), selected_color, BOLD)
-    subwindow.addstr(2, 2, 'Value: %s (%s)' % (selected.value(), str_tools.crop(attr, subwindow.width - len(selected.value()) - 13)), selected_color, BOLD)
+  attr = ', '.join(('custom' if selected.is_set() else 'default', selected.value_type, 'usage: %s' % selected.manual.usage))
+  selected_color = CONFIG['attr.config.category_color'].get(selected.manual.category, WHITE)
+  subwindow.box(0, 0, subwindow.width, DETAILS_HEIGHT)
 
-    for i in range(DETAILS_HEIGHT - 4):
-      if not description:
-        break  # done writing description
+  subwindow.addstr(2, 1, '%s (%s Option)' % (selected.name, selected.manual.category), selected_color, BOLD)
+  subwindow.addstr(2, 2, 'Value: %s (%s)' % (selected.value(), str_tools.crop(attr, subwindow.width - len(selected.value()) - 13)), selected_color, BOLD)
 
-      line, description = description.split('\n', 1) if '\n' in description else (description, '')
+  description = 'Description: %s' % selected.manual.description
 
-      if i < DETAILS_HEIGHT - 5:
-        line, remainder = str_tools.crop(line, subwindow.width - 3, 4, 4, str_tools.Ending.HYPHEN, True)
-        description = '  ' + remainder.strip() + description
-        subwindow.addstr(2, 3 + i, line, selected_color, BOLD)
-      else:
-        subwindow.addstr(2, 3 + i, str_tools.crop(line, subwindow.width - 3, 4, 4), selected_color, BOLD)
+  for i in range(DETAILS_HEIGHT - 4):
+    if not description:
+      break  # done writing description
+
+    line, description = description.split('\n', 1) if '\n' in description else (description, '')
+
+    if i < DETAILS_HEIGHT - 5:
+      line, remainder = str_tools.crop(line, subwindow.width - 3, 4, 4, str_tools.Ending.HYPHEN, True)
+      description = '  ' + remainder.strip() + description
+      subwindow.addstr(2, 3 + i, line, selected_color, BOLD)
+    else:
+      subwindow.addstr(2, 3 + i, str_tools.crop(line, subwindow.width - 3, 4, 4), selected_color, BOLD)
diff --git a/test/panel/__init__.py b/test/panel/__init__.py
index 9142e64..579da3f 100644
--- a/test/panel/__init__.py
+++ b/test/panel/__init__.py
@@ -7,5 +7,6 @@ __all__ = [
   'graph',
   'log',
   'connection',
+  'config',
   'torrc',
 ]
diff --git a/test/panel/config.py b/test/panel/config.py
new file mode 100644
index 0000000..19db206
--- /dev/null
+++ b/test/panel/config.py
@@ -0,0 +1,37 @@
+"""
+Unit tests for nyx.panel.config.
+"""
+
+import unittest
+
+import stem.manual
+import nyx.panel.config
+import test
+
+from test import require_curses
+from mock import patch
+
+EXPECTED_DETAIL_DIALOG = """
++------------------------------------------------------------------------------+
+| ControlPort (General Option)                                                 |
+| Value: 9051 (custom, LineList, usage: PORT|unix:path|auto [flags])           |
+| Description: If set, Tor will accept connections on this port and allow those|
+|   connections to control the Tor process using the Tor Control Protocol (des-|
+|   cribed in control-spec.txt in torspec). Note: unless you also specify one  |
+|   or more of HashedControlPassword or CookieAuthentication, setting this...  |
++------------------------------------------------------------------------------+
+""".strip()
+
+
+class TestConfigPanel(unittest.TestCase):
+  @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']
+
+    manual = stem.manual.Manual.from_cache()
+    selected = nyx.panel.config.ConfigEntry('ControlPort', 'LineList', manual)
+
+    rendered = test.render(nyx.panel.config._draw_selection_details, selected)
+    self.assertEqual(EXPECTED_DETAIL_DIALOG, rendered.content)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits