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

[tor-commits] [nyx/master] Moved curses tests to subwindow.py



commit 0a9fafa62c2857e781e7ba3598f422ceeb65e61a
Author: Sambuddha Basu <sambuddhabasu1@xxxxxxxxx>
Date:   Mon Jul 18 19:27:10 2016 -0700

    Moved curses tests to subwindow.py
---
 nyx/panel/interpreter.py  | 10 ++---
 test/panel/interpreter.py | 95 +++--------------------------------------------
 test/subwindow.py         | 83 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 95 deletions(-)

diff --git a/nyx/panel/interpreter.py b/nyx/panel/interpreter.py
index 9839e90..dfd7480 100644
--- a/nyx/panel/interpreter.py
+++ b/nyx/panel/interpreter.py
@@ -67,7 +67,7 @@ class InterpreterPanel(panel.Panel):
   """
 
   def __init__(self):
-    panel.Panel.__init__(self, 'interpreter')
+    panel.Panel.__init__(self)
 
     self._is_input_mode = False
     self._last_content_height = 0
@@ -85,7 +85,7 @@ class InterpreterPanel(panel.Panel):
 
   def key_handlers(self):
     def _scroll(key):
-      page_height = self.get_preferred_size()[0] - 1
+      page_height = self.get_height() - 1
       is_changed = self._scroller.handle_key(key, self._last_content_height, page_height)
 
       if is_changed:
@@ -97,8 +97,8 @@ class InterpreterPanel(panel.Panel):
       while self._is_input_mode:
         self.redraw(True)
         _scroll(nyx.curses.KeyInput(curses.KEY_END))
-        page_height = self.get_preferred_size()[0] - 1
-        user_input = nyx.curses.str_input(len(PROMPT) + self._x_offset, self.top + len(self.prompt_line[-page_height:]), '', list(reversed(self._backlog)), self.autocompleter.matches)
+        page_height = self.get_height() - 1
+        user_input = nyx.curses.str_input(len(PROMPT) + self._x_offset, self.get_top() + len(self.prompt_line[-page_height:]), '', list(reversed(self._backlog)), self.autocompleter.matches)
         user_input, is_done = user_input.strip(), False
 
         if not user_input:
@@ -143,7 +143,7 @@ class InterpreterPanel(panel.Panel):
       nyx.panel.KeyHandler('arrows', 'scroll up and down', _scroll, key_func = lambda key: key.is_scroll()),
     )
 
-  def draw(self, subwindow):
+  def _draw(self, subwindow):
     scroll = self._scroller.location(self._last_content_height, subwindow.height - 1)
 
     if self._last_content_height > subwindow.height - 1:
diff --git a/test/panel/interpreter.py b/test/panel/interpreter.py
index 5a793ca..5383777 100644
--- a/test/panel/interpreter.py
+++ b/test/panel/interpreter.py
@@ -4,14 +4,10 @@ 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
@@ -61,30 +57,26 @@ class TestInterpreter(unittest.TestCase):
     self.assertEqual(('>>> ', 'Green', 'Bold'), output[0])
     self.assertEqual(('/help', 'Magenta', 'Bold'), output[1])
 
-  def test_panel_name(self):
-    panel = nyx.panel.interpreter.InterpreterPanel()
-    self.assertEqual(panel.get_name(), 'interpreter')
-
   def test_rendering_panel(self):
     panel = nyx.panel.interpreter.InterpreterPanel()
-    self.assertEqual(EXPECTED_PANEL, test.render(panel.draw).content)
+    self.assertEqual(EXPECTED_PANEL, test.render(panel._draw).content)
 
     panel._is_input_mode = True
-    self.assertEqual(EXPECTED_PANEL_INPUT_MODE, test.render(panel.draw).content)
+    self.assertEqual(EXPECTED_PANEL_INPUT_MODE, test.render(panel._draw).content)
 
   def test_rendering_multiline_panel(self):
     panel = nyx.panel.interpreter.InterpreterPanel()
     panel.prompt_line = [[('>>> ', 'Green', 'Bold'), ('GETINFO', 'Green', 'Bold'), (' version', 'Cyan')]]
     panel.prompt_line.append([('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', 'Blue')])
-    self.assertEqual(EXPECTED_MULTILINE_PANEL, test.render(panel.draw).content)
+    self.assertEqual(EXPECTED_MULTILINE_PANEL, test.render(panel._draw).content)
 
   def test_scrollbar(self):
     panel = nyx.panel.interpreter.InterpreterPanel()
     self.assertIsInstance(panel._scroller, nyx.curses.Scroller)
 
-    height = panel.get_preferred_size()[0]
+    height = panel.get_height()
     panel._last_content_height = height
-    output_lines = test.render(panel.draw).content.split('\n')
+    output_lines = test.render(panel._draw).content.split('\n')
     self.assertEqual(height, len(output_lines))
     self.assertEqual(EXPECTED_SCROLLBAR_PANEL, output_lines[1])
 
@@ -94,80 +86,3 @@ 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)
diff --git a/test/subwindow.py b/test/subwindow.py
index 7f428e2..0f6f6a6 100644
--- a/test/subwindow.py
+++ b/test/subwindow.py
@@ -5,8 +5,14 @@ Unit tests for nyx.curses. Not entirely sure why this file can't be called
 
 import unittest
 
+import curses
+import curses.ascii
+import nyx.curses
+import nyx.panel.interpreter
 import test
 
+from mock import call, Mock, patch
+
 from test import require_curses
 
 EXPECTED_ADDSTR_WRAP = """
@@ -116,3 +122,80 @@ class TestCurses(unittest.TestCase):
       subwindow.scrollbar(15, 21, 30, fill_char = '*')
 
     self.assertEqual(EXPECTED_SCROLLBAR_BOTTOM, test.render(_draw).content.strip())
+
+  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