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

[tor-commits] [nyx/master] Include @require_curses in interpreter tests



commit 07a0599f434c49f25e3efa984dc55a05a838a28b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jul 31 12:36:08 2016 -0700

    Include @require_curses in interpreter tests
    
    Our tests were actually pretty good. Just rearranging things a bit and adding
    @require_curses to the ones that need curses.
---
 nyx/panel/interpreter.py  |  2 +-
 test/panel/interpreter.py | 90 +++++++++++++++++++++++++++++++----------------
 2 files changed, 60 insertions(+), 32 deletions(-)

diff --git a/nyx/panel/interpreter.py b/nyx/panel/interpreter.py
index 5a08796..ae929ca 100644
--- a/nyx/panel/interpreter.py
+++ b/nyx/panel/interpreter.py
@@ -55,7 +55,7 @@ class InterpreterPanel(nyx.panel.Panel):
 
     controller = tor_controller()
     self._autocompleter = stem.interpreter.autocomplete.Autocompleter(controller)
-    self._interpreter = stem.interpreter.commands.ControlInterpretor(controller)
+    self._interpreter = stem.interpreter.commands.ControlInterpreter(controller)
     self._interpreter._run_python_commands = False
 
   def key_handlers(self):
diff --git a/test/panel/interpreter.py b/test/panel/interpreter.py
index fda70f3..b24a51f 100644
--- a/test/panel/interpreter.py
+++ b/test/panel/interpreter.py
@@ -8,6 +8,7 @@ import nyx.curses
 import nyx.panel.interpreter
 import test
 
+from test import require_curses
 from mock import patch
 
 EXPECTED_PANEL = """
@@ -27,61 +28,88 @@ Control Interpreter:
 >>> to use this panel press enter
 """.strip()
 
+EXPECTED_WITH_SCROLLBAR = """
+Control Interpreter:
+ |>>> GETINFO version
+ |250-version=0.2.4.27 (git-412e3f7dc9c6c01a)
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+-+
+""".strip()
+
 
 class TestInterpreter(unittest.TestCase):
-  def test_format_prompt_input(self):
-    user_input = 'getinfo'
-    output = nyx.panel.interpreter._format_prompt_input(user_input)
+  def test_format_prompt_input_with_interperter_command(self):
+    output = nyx.panel.interpreter._format_prompt_input('/help')
     self.assertEqual(2, len(output))
     self.assertEqual(('>>> ', ('Green', 'Bold')), output[0])
-    self.assertEqual(('getinfo ', ('Green', 'Bold')), output[1])
+    self.assertEqual(('/help', ('Magenta', 'Bold')), output[1])
 
-    user_input = 'getinfo version'
-    output = nyx.panel.interpreter._format_prompt_input(user_input)
-    self.assertEqual(3, len(output))
+  def test_format_prompt_input_with_command(self):
+    output = nyx.panel.interpreter._format_prompt_input('GETINFO')
+    self.assertEqual(2, len(output))
     self.assertEqual(('>>> ', ('Green', 'Bold')), output[0])
-    self.assertEqual(('getinfo ', ('Green', 'Bold')), output[1])
-    self.assertEqual(('version', ('Cyan', 'Bold')), output[2])
+    self.assertEqual(('GETINFO ', ('Green', 'Bold')), output[1])
 
-    user_input = '/help'
-    output = nyx.panel.interpreter._format_prompt_input(user_input)
-    self.assertEqual(2, len(output))
+  def test_format_prompt_input_with_command_and_arg(self):
+    output = nyx.panel.interpreter._format_prompt_input('GETINFO version')
+    self.assertEqual(3, len(output))
     self.assertEqual(('>>> ', ('Green', 'Bold')), output[0])
-    self.assertEqual(('/help', ('Magenta', 'Bold')), output[1])
+    self.assertEqual(('GETINFO ', ('Green', 'Bold')), output[1])
+    self.assertEqual(('version', ('Cyan', 'Bold')), output[2])
 
+  @require_curses
   @patch('nyx.panel.interpreter.tor_controller')
-  def test_rendering_panel(self, tor_controller_mock):
+  def test_blank_panel(self, tor_controller_mock):
     tor_controller_mock()._handle_event = lambda event: None
+
     panel = nyx.panel.interpreter.InterpreterPanel()
     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)
 
+  @require_curses
   @patch('nyx.panel.interpreter.tor_controller')
-  def test_rendering_multiline_panel(self, tor_controller_mock):
+  def test_multiline_panel(self, tor_controller_mock):
     tor_controller_mock()._handle_event = lambda event: None
+
     panel = nyx.panel.interpreter.InterpreterPanel()
-    panel._lines = [[('>>> ', ('Green', 'Bold')), ('GETINFO', ('Green', 'Bold')), (' version', ('Cyan',))]]
-    panel._lines.append([('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', ('Blue',))])
+    panel._lines = [
+      [('>>> ', ('Green', 'Bold')), ('GETINFO', ('Green', 'Bold')), (' version', ('Cyan',))],
+      [('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', ('Blue',))]
+    ]
+
     self.assertEqual(EXPECTED_MULTILINE_PANEL, test.render(panel._draw).content)
 
+  @require_curses
   @patch('nyx.panel.interpreter.tor_controller')
   def test_scrollbar(self, tor_controller_mock):
     tor_controller_mock()._handle_event = lambda event: None
-    panel = nyx.panel.interpreter.InterpreterPanel()
-    self.assertIsInstance(panel._scroller, nyx.curses.Scroller)
 
-    height = panel.get_height()
-    panel._lines = [()] * height
-    output_lines = test.render(panel._draw).content.split('\n')
-    self.assertEqual(height, len(output_lines))
-
-  @patch('nyx.panel.interpreter.tor_controller')
-  def test_key_handlers(self, tor_controller_mock):
-    tor_controller_mock()._handle_event = lambda event: None
     panel = nyx.panel.interpreter.InterpreterPanel()
-    output = panel.key_handlers()
-    self.assertEqual(2, len(output))
-    self.assertEqual('enter', output[0].key)
-    self.assertEqual('arrows', output[1].key)
+    panel._lines = [
+      [('>>> ', ('Green', 'Bold')), ('GETINFO', ('Green', 'Bold')), (' version', ('Cyan',))],
+      [('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', ('Blue',))]
+    ] + [()] * (panel.get_height() - 2)
+
+    self.assertEqual(EXPECTED_WITH_SCROLLBAR, test.render(panel._draw).content)



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