[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Added tests for str_input_handle_* functions
commit f50763bdb48b61e6a22e63ffa3d9b85523a94007
Author: Sambuddha Basu <sambuddhabasu1@xxxxxxxxx>
Date: Sun Jul 17 23:43:01 2016 -0700
Added tests for str_input_handle_* functions
---
test/panel/interpreter.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/test/panel/interpreter.py b/test/panel/interpreter.py
index a3ddd5e..5a793ca 100644
--- a/test/panel/interpreter.py
+++ b/test/panel/interpreter.py
@@ -4,10 +4,14 @@ Unit tests for nyx.panel.interpreter.
import unittest
+import curses
+import curses.ascii
import nyx.curses
import nyx.panel.interpreter
import test
+from mock import call, Mock, patch
+
EXPECTED_PANEL = """
Control Interpreter:
>>> to use this panel press enter
@@ -90,3 +94,80 @@ class TestInterpreter(unittest.TestCase):
self.assertEqual(2, len(output))
self.assertEqual('enter', output[0].key)
self.assertEqual('arrows', output[1].key)
+
+ def test_str_input_handle_key(self):
+ dimensions = (40, 80)
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ self.assertEqual(curses.ascii.BEL, nyx.curses.str_input_handle_key(textbox, 27))
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ textbox.win.move = Mock()
+ expected_call = call(dimensions[0], 0)
+ nyx.curses.str_input_handle_key(textbox, curses.KEY_HOME)
+ self.assertTrue(textbox.win.move.called)
+ self.assertEquals(expected_call, textbox.win.move.call_args)
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ textbox.gather.return_value = 'Sample Text'
+ textbox.win.move = Mock()
+ expected_call = call(*dimensions)
+ nyx.curses.str_input_handle_key(textbox, curses.KEY_RIGHT)
+ self.assertTrue(textbox.win.move.called)
+ self.assertEquals(expected_call, textbox.win.move.call_args)
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ self.assertEqual(curses.ascii.BEL, nyx.curses.str_input_handle_key(textbox, 410))
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ key_pressed = ord('a')
+ self.assertEqual(key_pressed, nyx.curses.str_input_handle_key(textbox, key_pressed))
+
+ @patch('nyx.curses.str_input_handle_key')
+ def test_str_input_handle_history_key(self, mock_str_input_handle_key):
+ backlog = ['GETINFO version']
+ dimensions = (40, 80)
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ self.assertIsNone(nyx.curses.str_input_handle_history_key(textbox, curses.KEY_UP, []))
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ textbox.win.getmaxyx.return_value = dimensions
+ textbox.win.addstr = Mock()
+ textbox.win.move = Mock()
+ nyx.curses.str_input_handle_history_key(textbox, curses.KEY_UP, backlog)
+ self.assertTrue(textbox.win.clear.called)
+ expected_addstr_call = call(dimensions[0], 0, backlog[0])
+ self.assertEqual(expected_addstr_call, textbox.win.addstr.call_args)
+ expected_move_call = call(dimensions[0], len(backlog[0]))
+ self.assertEqual(expected_move_call, textbox.win.move.call_args)
+
+ textbox = Mock()
+ nyx.curses.str_input_handle_history_key(textbox, curses.KEY_LEFT, [])
+ self.assertTrue(mock_str_input_handle_key.called)
+
+ @patch('nyx.curses.str_input_handle_history_key')
+ def test_str_input_handle_tab_completion(self, mock_str_input_handle_history_key):
+ dimensions = (40, 80)
+ tab_completion_content = 'GETINFO version'
+
+ textbox = Mock()
+ textbox.win.getyx.return_value = dimensions
+ textbox.win.getmaxyx.return_value = dimensions
+ textbox.win.addstr = Mock()
+ textbox.win.move = Mock()
+ tab_completion = Mock()
+ tab_completion.return_value = [tab_completion_content]
+ nyx.curses.str_input_handle_tab_completion(textbox, 9, [], tab_completion)
+ self.assertTrue(textbox.win.clear.called)
+ expected_addstr_call = call(dimensions[0], 0, tab_completion_content)
+ self.assertEqual(expected_addstr_call, textbox.win.addstr.call_args)
+ expected_move_call = call(dimensions[0], len(tab_completion_content))
+ self.assertTrue(expected_move_call, textbox.win.move.call_args)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits