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

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



commit e59670d68f934ab1d762ee100888ff2fa6986f49
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jul 9 15:29:24 2016 -0700

    Test _draw_title()
---
 nyx/panel/connection.py  | 30 +++++++++++++++---------------
 test/panel/__init__.py   |  1 +
 test/panel/connection.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index cee63e2..87930a6 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -418,7 +418,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
     is_scrollbar_visible = len(lines) > subwindow.height - details_offset - 1
     scroll_offset = 2 if is_scrollbar_visible else 0
 
-    self._draw_title(subwindow, entries, self._show_details)
+    _draw_title(subwindow, entries, self._show_details)
 
     if is_showing_details:
       self._draw_details(subwindow, selected, subwindow.width, is_scrollbar_visible)
@@ -433,20 +433,6 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
       if y >= subwindow.height:
         break
 
-  def _draw_title(self, subwindow, entries, showing_details):
-    """
-    Panel title with the number of connections we presently have.
-    """
-
-    if showing_details:
-      subwindow.addstr(0, 0, 'Connection Details:', HIGHLIGHT)
-    elif not entries:
-      subwindow.addstr(0, 0, 'Connections:', HIGHLIGHT)
-    else:
-      counts = collections.Counter([entry.get_type() for entry in entries])
-      count_labels = ['%i %s' % (counts[category], category.lower()) for category in Category if counts[category]]
-      subwindow.addstr(0, 0, 'Connections (%s):' % ', '.join(count_labels), HIGHLIGHT)
-
   def _draw_details(self, subwindow, selected, width, is_scrollbar_visible):
     """
     Shows detailed information about the selected connection.
@@ -652,3 +638,17 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
           remote_ports.append(line.connection.local_port)
 
       nyx.tracker.get_port_usage_tracker().query(local_ports, remote_ports)
+
+def _draw_title(subwindow, entries, showing_details):
+  """
+  Panel title with the number of connections we presently have.
+  """
+
+  if showing_details:
+    subwindow.addstr(0, 0, 'Connection Details:', HIGHLIGHT)
+  elif not entries:
+    subwindow.addstr(0, 0, 'Connections:', HIGHLIGHT)
+  else:
+    counts = collections.Counter([entry.get_type() for entry in entries])
+    count_labels = ['%i %s' % (counts[category], category.lower()) for category in Category if counts[category]]
+    subwindow.addstr(0, 0, 'Connections (%s):' % ', '.join(count_labels), HIGHLIGHT)
diff --git a/test/panel/__init__.py b/test/panel/__init__.py
index 8980380..f1a9d7d 100644
--- a/test/panel/__init__.py
+++ b/test/panel/__init__.py
@@ -6,4 +6,5 @@ __all__ = [
   'header',
   'graph',
   'log',
+  'connection',
 ]
diff --git a/test/panel/connection.py b/test/panel/connection.py
new file mode 100644
index 0000000..8ff08a2
--- /dev/null
+++ b/test/panel/connection.py
@@ -0,0 +1,44 @@
+"""
+Unit tests for nyx.panel.connection.
+"""
+
+import unittest
+
+import nyx.panel.connection
+import test
+
+from nyx.panel.connection import Category, Entry
+from test import require_curses
+
+
+class MockEntry(Entry):
+  def __init__(self, lines = [], entry_type = Category.INBOUND, is_private = False):
+    self._lines = lines
+    self._type = entry_type
+    self._is_private = is_private
+
+  def lines(self):
+    return self._lines
+
+  def get_type(self):
+    return self._type
+
+  def is_private(self):
+    return self._is_private
+
+
+class TestConnectionPanel(unittest.TestCase):
+  @require_curses
+  def test_draw_title(self):
+    self.assertEqual('Connection Details:', test.render(nyx.panel.connection._draw_title, [], True).content)
+    self.assertEqual('Connections:', test.render(nyx.panel.connection._draw_title, [], False).content)
+
+    entries = [
+      MockEntry(entry_type = Category.INBOUND),
+      MockEntry(entry_type = Category.INBOUND),
+      MockEntry(entry_type = Category.OUTBOUND),
+      MockEntry(entry_type = Category.INBOUND),
+      MockEntry(entry_type = Category.CONTROL),
+    ]
+
+    self.assertEqual('Connections (3 inbound, 1 outbound, 1 control):', test.render(nyx.panel.connection._draw_title, entries, False).content)



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