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

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



commit 6cc017c0a67a6a8fe7038f229b3111743ec5b6ef
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Apr 9 23:06:23 2016 -0700

    Test _draw_disconnected()
---
 nyx/panel/header.py  | 26 ++++++++++++++------------
 test/panel/header.py |  8 ++++++++
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 54046b2..922b907 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -186,7 +186,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
     if vals.is_connected:
       _draw_ports_section(subwindow, 0, 1, left_width, vals)
     else:
-      self._draw_disconnected(subwindow, 0, 1, left_width, vals)
+      _draw_disconnected(subwindow, 0, 1, vals.last_heartbeat)
 
     if is_wide:
       self._draw_resource_usage(subwindow, left_width, 0, right_width, vals)
@@ -212,17 +212,6 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread):
     else:
       subwindow.addstr(0, subwindow.height - 1, 'Paused', HIGHLIGHT)
 
-  def _draw_disconnected(self, subwindow, x, y, width, vals):
-    """
-    Message indicating that tor is disconnected...
-
-      Tor Disconnected (15:21 07/13/2014, press r to reconnect)
-    """
-
-    x = subwindow.addstr(x, y, 'Tor Disconnected', RED, BOLD)
-    last_heartbeat = time.strftime('%H:%M %m/%d/%Y', time.localtime(vals.last_heartbeat))
-    subwindow.addstr(x, y, ' (%s, press r to reconnect)' % last_heartbeat)
-
   def _draw_resource_usage(self, subwindow, x, y, width, vals):
     """
     System resource usage of the tor process...
@@ -531,6 +520,7 @@ def _draw_platform_section(subwindow, x, y, width, vals):
       x = subwindow.addstr(x, y, vals.version_status, version_color)
       subwindow.addstr(x, y, ')')
 
+
 def _draw_ports_section(subwindow, x, y, width, vals):
   """
   Section providing our nickname, address, and port information...
@@ -557,3 +547,15 @@ def _draw_ports_section(subwindow, x, y, width, vals):
       subwindow.addstr(x, y, vals.format(', Control Port: {control_port}'))
   elif vals.socket_path:
     subwindow.addstr(x, y, vals.format(', Control Socket: {socket_path}'))
+
+
+def _draw_disconnected(subwindow, x, y, last_heartbeat):
+  """
+  Message indicating that tor is disconnected...
+
+    Tor Disconnected (15:21 07/13/2014, press r to reconnect)
+  """
+
+  x = subwindow.addstr(x, y, 'Tor Disconnected', RED, BOLD)
+  last_heartbeat_str = time.strftime('%H:%M %m/%d/%Y', time.localtime(last_heartbeat))
+  subwindow.addstr(x, y, ' (%s, press r to reconnect)' % last_heartbeat_str)
diff --git a/test/panel/header.py b/test/panel/header.py
index c06fd39..603d213 100644
--- a/test/panel/header.py
+++ b/test/panel/header.py
@@ -2,12 +2,14 @@
 Unit tests for nyx.panel.header.
 """
 
+import time
 import unittest
 
 import nyx.panel.header
 import test
 
 from test import require_curses
+from mock import patch
 
 
 class TestHeader(unittest.TestCase):
@@ -76,3 +78,9 @@ class TestHeader(unittest.TestCase):
     )
 
     self.assertEqual('Relaying Disabled, Control Socket: /path/to/control/socket', test.render(nyx.panel.header._draw_ports_section, 0, 0, 80, vals).content)
+
+  @require_curses
+  @patch('time.localtime')
+  def test_draw_disconnected(self, localtime_mock):
+    localtime_mock.return_value = time.strptime('22:43 04/09/2016', '%H:%M %m/%d/%Y')
+    self.assertEqual('Tor Disconnected (22:43 04/09/2016, press r to reconnect)', test.render(nyx.panel.header._draw_disconnected, 0, 0, 1460267022.231895).content)



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