commit 7c203455fa08833b76de42a27cdbb16e4b1f69da Author: Damian Johnson atagar@torproject.org Date: Thu Jan 10 11:18:59 2019 -0800
Fix interpreter panel unit tests
Oops, line wrapping broke our tests...
====================================================================== FAIL: test_multiline_panel (panel.interpreter.TestInterpreter) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/atagar/Desktop/nyx/test/__init__.py", line 59, in wrapped return func(self, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/mock/mock.py", line 1305, in patched return func(*args, **keywargs) File "/home/atagar/Desktop/nyx/test/panel/interpreter.py", line 107, in test_multiline_panel self.assertEqual(EXPECTED_MULTILINE_PANEL, test.render(panel._draw).content) AssertionError: 'Control Interpreter:\n>>> GETINFO version\n250-version=0.2.4.27 (git-412e3f7dc9c6c01a)\n>>> to use this panel press enter' != u'Control Interpreter:\n>>> to use this panel press enter'
====================================================================== FAIL: test_scrollbar (panel.interpreter.TestInterpreter) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/atagar/Desktop/nyx/test/__init__.py", line 59, in wrapped return func(self, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/mock/mock.py", line 1305, in patched return func(*args, **keywargs) File "/home/atagar/Desktop/nyx/test/panel/interpreter.py", line 120, in test_scrollbar self.assertEqual(EXPECTED_WITH_SCROLLBAR, test.render(panel._draw).content) AssertionError: 'Control Interpreter:\n |>>> GETINFO version\n |250-version=0.2.4.27 (git-412e3f7dc9c6c01a)\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n |\n-+' != u'Control Interpreter:\n>>> to use this panel press enter'
----------------------------------------------------------------------
With commit 75052e8 tests should no longer directly modify their private '_lines' attribute. We need to call the _add_line() helper instead to ensure the wrapped and unwrapped attributes stay in sync. --- test/panel/interpreter.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/test/panel/interpreter.py b/test/panel/interpreter.py index 3e68596..ad04882 100644 --- a/test/panel/interpreter.py +++ b/test/panel/interpreter.py @@ -99,10 +99,8 @@ class TestInterpreter(unittest.TestCase): tor_controller_mock()._handle_event = lambda event: None
panel = nyx.panel.interpreter.InterpreterPanel() - panel._lines = [ - [('>>> ', ('Green', 'Bold')), ('GETINFO', ('Green', 'Bold')), (' version', ('Cyan',))], - [('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', ('Blue',))] - ] + panel._add_line([('>>> ', ('Green', 'Bold')), ('GETINFO', ('Green', 'Bold')), (' version', ('Cyan',))]) + panel._add_line([('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', ('Blue',))])
self.assertEqual(EXPECTED_MULTILINE_PANEL, test.render(panel._draw).content)
@@ -112,9 +110,10 @@ class TestInterpreter(unittest.TestCase): tor_controller_mock()._handle_event = lambda event: None
panel = nyx.panel.interpreter.InterpreterPanel() - panel._lines = [ - [('>>> ', ('Green', 'Bold')), ('GETINFO', ('Green', 'Bold')), (' version', ('Cyan',))], - [('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', ('Blue',))] - ] + [()] * (panel.get_height() - 2) + panel._add_line([('>>> ', ('Green', 'Bold')), ('GETINFO', ('Green', 'Bold')), (' version', ('Cyan',))]) + panel._add_line([('250-version=0.2.4.27 (git-412e3f7dc9c6c01a)', ('Blue',))]) + + for i in range(panel.get_height() - 2): + panel._add_line([])
self.assertEqual(EXPECTED_WITH_SCROLLBAR, test.render(panel._draw).content)