[tor-commits] [nyx/master] Unit test help popups
atagar at torproject.org
atagar at torproject.org
Sun Apr 3 00:38:54 UTC 2016
commit a5f5caa583c222223f77e665f6174a9ce46dc0e8
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Apr 2 17:09:54 2016 -0700
Unit test help popups
Tad more substantial popup. This is so neat!
---
test/popups.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/test/popups.py b/test/popups.py
index c4f56ea..fde87f2 100644
--- a/test/popups.py
+++ b/test/popups.py
@@ -4,10 +4,23 @@ Unit tests for nyx.popups.
import unittest
+import nyx.panel
import nyx.popups
import test
-from mock import patch
+from mock import patch, Mock
+
+EXPECTED_HELP_POPUP = """
+Page 1 Commands:---------------------------------------------------------------+
+| arrows: scroll up and down a: save snapshot of the log |
+| e: change logged events f: log regex filter (disabled) |
+| u: duplicate log entries (hidden) c: clear event log |
+| r: resize graph s: graphed stats (bandwidth) |
+| b: graph bounds (local max) i: graph update interval (each second)|
+| |
+| Press any key... |
++------------------------------------------------------------------------------+
+""".strip()
EXPECTED_ABOUT_POPUP = """
About:-------------------------------------------------------------------------+
@@ -24,6 +37,41 @@ About:-------------------------------------------------------------------------+
class TestPopups(unittest.TestCase):
@patch('nyx.controller.get_controller')
+ def test_help(self, get_controller_mock):
+ header_panel = Mock()
+
+ header_panel.key_handlers.return_value = (
+ nyx.panel.KeyHandler('n'),
+ nyx.panel.KeyHandler('r'),
+ )
+
+ graph_panel = Mock()
+
+ graph_panel.key_handlers.return_value = (
+ nyx.panel.KeyHandler('r', 'resize graph'),
+ nyx.panel.KeyHandler('s', 'graphed stats', current = 'bandwidth'),
+ nyx.panel.KeyHandler('b', 'graph bounds', current = 'local max'),
+ nyx.panel.KeyHandler('i', 'graph update interval', current = 'each second'),
+ )
+
+ log_panel = Mock()
+
+ log_panel.key_handlers.return_value = (
+ nyx.panel.KeyHandler('arrows', 'scroll up and down'),
+ nyx.panel.KeyHandler('a', 'save snapshot of the log'),
+ nyx.panel.KeyHandler('e', 'change logged events'),
+ nyx.panel.KeyHandler('f', 'log regex filter', current = 'disabled'),
+ nyx.panel.KeyHandler('u', 'duplicate log entries', current = 'hidden'),
+ nyx.panel.KeyHandler('c', 'clear event log'),
+ )
+
+ get_controller_mock().header_panel().get_height.return_value = 0
+ get_controller_mock().get_display_panels.return_value = [header_panel, graph_panel, log_panel]
+
+ rendered = test.render(nyx.popups.show_help)
+ self.assertEqual(EXPECTED_HELP_POPUP, rendered.content)
+
+ @patch('nyx.controller.get_controller')
def test_about(self, get_controller_mock):
get_controller_mock().header_panel().get_height.return_value = 0
More information about the tor-commits
mailing list