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

atagar at torproject.org atagar at torproject.org
Mon Apr 18 20:23:16 UTC 2016


commit 385b4f1a958665a3bd0da2176c0b64ff571fbc52
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Apr 10 13:04:41 2016 -0700

    Test _draw_newnym_option()
---
 nyx/panel/header.py  | 27 ++++++++++++++-------------
 test/panel/header.py |  6 ++++++
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 96b8383..9288db9 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -197,7 +197,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
         _draw_flags(subwindow, 0, 2, vals.flags)
         _draw_exit_policy(subwindow, left_width, 2, vals.exit_policy)
       elif vals.is_connected:
-        self._draw_newnym_option(subwindow, left_width, 1, right_width, vals)
+        _draw_newnym_option(subwindow, left_width, 1, vals.newnym_wait)
     else:
       _draw_resource_usage(subwindow, 0, 2, left_width, vals, pause_time)
 
@@ -213,18 +213,6 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
     else:
       subwindow.addstr(0, subwindow.height - 1, 'Paused', HIGHLIGHT)
 
-  def _draw_newnym_option(self, subwindow, x, y, width, vals):
-    """
-    Provide a notice for requiesting a new identity, and time until it's next
-    available if in the process of building circuits.
-    """
-
-    if vals.newnym_wait == 0:
-      subwindow.addstr(x, y, "press 'n' for a new identity")
-    else:
-      plural = 's' if vals.newnym_wait > 1 else ''
-      subwindow.addstr(x, y, 'building circuits, available again in %i second%s' % (vals.newnym_wait, plural))
-
   def run(self):
     """
     Keeps stats updated, checking for new information at a set rate.
@@ -564,3 +552,16 @@ def _draw_exit_policy(subwindow, x, y, exit_policy):
       x = subwindow.addstr(x, y, ', ')
 
     subwindow.addstr(x, y, '<default>', CYAN, BOLD)
+
+
+def _draw_newnym_option(subwindow, x, y, newnym_wait):
+  """
+  Provide a notice for requiesting a new identity, and time until it's next
+  available if in the process of building circuits.
+  """
+
+  if newnym_wait == 0:
+    subwindow.addstr(x, y, "press 'n' for a new identity")
+  else:
+    plural = 's' if newnym_wait > 1 else ''
+    subwindow.addstr(x, y, 'building circuits, available again in %i second%s' % (newnym_wait, plural))
diff --git a/test/panel/header.py b/test/panel/header.py
index 9794644..209ce8b 100644
--- a/test/panel/header.py
+++ b/test/panel/header.py
@@ -168,3 +168,9 @@ class TestHeader(unittest.TestCase):
   def test_draw_exit_policy(self):
     self.assertEqual('exit policy: reject *:*', test.render(nyx.panel.header._draw_exit_policy, 0, 0, stem.exit_policy.ExitPolicy('reject *:*')).content)
     self.assertEqual('exit policy: accept *:80, accept *:443, reject *:*', test.render(nyx.panel.header._draw_exit_policy, 0, 0, stem.exit_policy.ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')).content)
+
+  @require_curses
+  def test_draw_newnym_option(self):
+    self.assertEqual("press 'n' for a new identity", test.render(nyx.panel.header._draw_newnym_option, 0, 0, 0).content)
+    self.assertEqual('building circuits, available again in 1 second', test.render(nyx.panel.header._draw_newnym_option, 0, 0, 1).content)
+    self.assertEqual('building circuits, available again in 5 seconds', test.render(nyx.panel.header._draw_newnym_option, 0, 0, 5).content)





More information about the tor-commits mailing list