[tor-commits] [nyx/master] Test for rendering subgraphs

atagar at torproject.org atagar at torproject.org
Sun Jun 26 00:48:01 UTC 2016


commit 084d328c4782695707ba15f2dc483c069339fcb6
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jun 25 17:01:00 2016 -0700

    Test for rendering subgraphs
---
 nyx/panel/graph.py  |  6 +++---
 test/panel/graph.py | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 49f79ff..a2a00bc 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -616,7 +616,7 @@ class GraphPanel(nyx.panel.Panel):
         self.redraw(True)
 
 
-def _draw_subgraph(subwindow, attr, data, x, color):
+def _draw_subgraph(subwindow, attr, data, x, color, fill_char = ' '):
   # Concering our subgraph colums, the y-axis label can be at most six
   # characters, with two spaces of padding on either side of the graph.
   # Starting with the smallest size, then possibly raise it after determing
@@ -647,9 +647,9 @@ def _draw_subgraph(subwindow, attr, data, x, color):
 
     for row in range(column_height):
       if attr.right_to_left:
-        subwindow.addstr(x + attr.subgraph_width - col - 1, attr.subgraph_height - 1 - row, ' ', color, HIGHLIGHT)
+        subwindow.addstr(x + attr.subgraph_width - col - 1, attr.subgraph_height - 1 - row, fill_char, color, HIGHLIGHT)
       else:
-        subwindow.addstr(x + col + axis_offset + 1, attr.subgraph_height - 1 - row, ' ', color, HIGHLIGHT)
+        subwindow.addstr(x + col + axis_offset + 1, attr.subgraph_height - 1 - row, fill_char, color, HIGHLIGHT)
 
 
 def _x_axis_labels(interval, subgraph_columns):
diff --git a/test/panel/graph.py b/test/panel/graph.py
index c8635e1..a013d59 100644
--- a/test/panel/graph.py
+++ b/test/panel/graph.py
@@ -29,6 +29,16 @@ Accounting (awake)                 Time to reset: 01:02
   37.7 Kb / 842.0 Kb                 16.0 Kb / 74.1 Kb
 """.strip()
 
+EXPECTED_GRAPH = """
+Download:
+5 Kb      *
+          *
+2 Kb      ** *
+     *    ****
+0 b  *********
+         5s   10   15
+""".rstrip()
+
 
 class TestGraph(unittest.TestCase):
   def test_x_axis_labels(self):
@@ -97,11 +107,30 @@ class TestGraph(unittest.TestCase):
 
     data = nyx.panel.graph.BandwidthStats()
 
-    rendered = test.render(nyx.panel.graph._draw_subgraph, attr, data.primary, 0, nyx.curses.Color.CYAN)
+    rendered = test.render(nyx.panel.graph._draw_subgraph, attr, data.primary, 0, nyx.curses.Color.CYAN, '*')
     self.assertEqual(EXPECTED_BLANK_GRAPH, rendered.content)
 
   @require_curses
   @patch('nyx.panel.graph.tor_controller')
+  def test_draw_subgraph(self, tor_controller_mock):
+    tor_controller_mock().get_info.return_value = '543,543 421,421 551,551 710,710 200,200 175,175 188,188 250,250 377,377'
+
+    attr = nyx.panel.graph.DrawAttributes(
+      stat = None,
+      subgraph_height = 7,
+      subgraph_width = 30,
+      interval = nyx.panel.graph.Interval.EACH_SECOND,
+      bounds_type = nyx.panel.graph.Bounds.LOCAL_MAX,
+      right_to_left = False,
+    )
+
+    data = nyx.panel.graph.BandwidthStats()
+
+    rendered = test.render(nyx.panel.graph._draw_subgraph, attr, data.primary, 0, nyx.curses.Color.CYAN, '*')
+    self.assertEqual(EXPECTED_GRAPH, rendered.content)
+
+  @require_curses
+  @patch('nyx.panel.graph.tor_controller')
   def test_draw_accounting_stats(self, tor_controller_mock):
     tor_controller_mock().is_alive.return_value = True
 





More information about the tor-commits mailing list