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

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



commit 7c41f64f8e98f35614f5ab3cbeb0da837cd528af
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Apr 10 12:16:53 2016 -0700

    Test _draw_flags()
---
 nyx/panel/header.py  | 43 ++++++++++++++++++++++---------------------
 test/panel/header.py |  6 ++++++
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index da0ba7f..00d4794 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -194,7 +194,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
 
       if vals.is_relay:
         _draw_fingerprint_and_fd_usage(subwindow, left_width, 1, right_width, vals)
-        self._draw_flags(subwindow, 0, 2, left_width, vals)
+        _draw_flags(subwindow, 0, 2, vals.flags)
         self._draw_exit_policy(subwindow, left_width, 2, right_width, vals)
       elif vals.is_connected:
         self._draw_newnym_option(subwindow, left_width, 1, right_width, vals)
@@ -203,7 +203,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
 
       if vals.is_relay:
         _draw_fingerprint_and_fd_usage(subwindow, 0, 3, left_width, vals)
-        self._draw_flags(subwindow, 0, 4, left_width, vals)
+        _draw_flags(subwindow, 0, 4, vals.flags)
 
     if self._message:
       subwindow.addstr(0, subwindow.height - 1, self._message, *self._message_attr)
@@ -213,25 +213,6 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
     else:
       subwindow.addstr(0, subwindow.height - 1, 'Paused', HIGHLIGHT)
 
-  def _draw_flags(self, subwindow, x, y, width, vals):
-    """
-    Presents flags held by our relay...
-
-      flags: Running, Valid
-    """
-
-    x = subwindow.addstr(x, y, 'flags: ')
-
-    if vals.flags:
-      for i, flag in enumerate(vals.flags):
-        flag_color = CONFIG['attr.flag_colors'].get(flag, WHITE)
-        x = subwindow.addstr(x, y, flag, flag_color, BOLD)
-
-        if i < len(vals.flags) - 1:
-          x = subwindow.addstr(x, y, ', ')
-    else:
-      subwindow.addstr(x, y, 'none', CYAN, BOLD)
-
   def _draw_exit_policy(self, subwindow, x, y, width, vals):
     """
     Presents our exit policy...
@@ -562,3 +543,23 @@ def _draw_fingerprint_and_fd_usage(subwindow, x, y, width, vals):
       x = subwindow.addstr(x, y, vals.format(': {fd_used} / {fd_limit} ('))
       x = subwindow.addstr(x, y, '%i%%' % fd_percent, *percentage_format)
       subwindow.addstr(x, y, ')')
+
+
+def _draw_flags(subwindow, x, y, flags):
+  """
+  Presents flags held by our relay...
+
+    flags: Running, Valid
+  """
+
+  x = subwindow.addstr(x, y, 'flags: ')
+
+  if flags:
+    for i, flag in enumerate(flags):
+      flag_color = CONFIG['attr.flag_colors'].get(flag, WHITE)
+      x = subwindow.addstr(x, y, flag, flag_color, BOLD)
+
+      if i < len(flags) - 1:
+        x = subwindow.addstr(x, y, ', ')
+  else:
+    subwindow.addstr(x, y, 'none', CYAN, BOLD)
diff --git a/test/panel/header.py b/test/panel/header.py
index 0d80f0f..39982e0 100644
--- a/test/panel/header.py
+++ b/test/panel/header.py
@@ -156,3 +156,9 @@ class TestHeader(unittest.TestCase):
       )
 
       self.assertEqual(expected, test.render(nyx.panel.header._draw_fingerprint_and_fd_usage, 0, 0, 80, vals).content)
+
+  @require_curses
+  def test_draw_flags(self):
+    self.assertEqual('flags: none', test.render(nyx.panel.header._draw_flags, 0, 0, []).content)
+    self.assertEqual('flags: Guard', test.render(nyx.panel.header._draw_flags, 0, 0, ['Guard']).content)
+    self.assertEqual('flags: Running, Exit', test.render(nyx.panel.header._draw_flags, 0, 0, ['Running', 'Exit']).content)



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