[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Test for curses module
commit 6266276285ff44157960f4cff26234edca81ce60
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Jun 26 17:04:22 2016 -0700
Test for curses module
Adding tests for our Subwindow class. While our panel tests are great, having
tests for our lower level curses object will be helpful.
---
nyx/curses.py | 5 ++-
test/__init__.py | 4 +-
test/arguments.py | 4 ++
test/panel/__init__.py | 1 +
test/subwindow.py | 120 +++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 131 insertions(+), 3 deletions(-)
diff --git a/nyx/curses.py b/nyx/curses.py
index 1c36526..ed8b87b 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -612,7 +612,7 @@ class _Subwindow(object):
self._addch(left + width - 1, top, curses.ACS_URCORNER, *attr) # upper right corner
self._addch(left + width - 1, top + height - 1, curses.ACS_LRCORNER, *attr) # lower right corner
- def scrollbar(self, top, top_index, size):
+ def scrollbar(self, top, top_index, size, fill_char = ' '):
"""
Draws a left justified scrollbar reflecting position within a vertical
listing. The bottom is squared off, having a layout like:
@@ -630,6 +630,7 @@ class _Subwindow(object):
:param int top: top row in the subwindow where the scrollbar should be drawn
:param int top_index: list index for the top-most visible element
:param int size: size of the list in which the listed elements are contained
+ :param str fill_char: character to use for scrollbar handle
"""
if (self.height - top) < 2:
@@ -652,7 +653,7 @@ class _Subwindow(object):
for i in range(scrollbar_height):
if i >= slider_top and i <= slider_top + slider_size:
- self.addstr(0, i + top, ' ', Attr.HIGHLIGHT)
+ self.addstr(0, i + top, fill_char, Attr.HIGHLIGHT)
else:
self.addstr(0, i + top, ' ')
diff --git a/test/__init__.py b/test/__init__.py
index 861e46c..f920114 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -14,9 +14,11 @@ from mock import patch, Mock
__all__ = [
'arguments',
- 'expand_path',
+ 'curses',
'installation',
'log',
+ 'panel',
+ 'popups',
'tracker',
]
diff --git a/test/arguments.py b/test/arguments.py
index 58bf954..c146e7d 100644
--- a/test/arguments.py
+++ b/test/arguments.py
@@ -1,3 +1,7 @@
+"""
+Unit tests for nyx.arguments.
+"""
+
import unittest
from nyx.arguments import DEFAULT_ARGS, parse
diff --git a/test/panel/__init__.py b/test/panel/__init__.py
index 0050223..c86ba85 100644
--- a/test/panel/__init__.py
+++ b/test/panel/__init__.py
@@ -4,4 +4,5 @@ Unit tests for nyx's panel modules.
__all__ = [
'header',
+ 'graph',
]
diff --git a/test/subwindow.py b/test/subwindow.py
new file mode 100644
index 0000000..c785ecc
--- /dev/null
+++ b/test/subwindow.py
@@ -0,0 +1,120 @@
+"""
+Unit tests for nyx.curses. Not entirely sure why this file can't be called
+'curses.py' but doing so causes the unittest module to fail internally.
+"""
+
+import unittest
+
+import test
+
+from test import require_curses
+
+EXPECTED_ADDSTR_WRAP = """
+0123456789 0123456789
+0123456789 0123456789
+0123456789 0123456789
+0123456789 0123456789
+0123456789 0123456789
+""".strip()
+
+EXPECTED_BOX = """
++---+
+| |
++---+
+""".strip()
+
+EXPECTED_SCROLLBAR_TOP = """
+*|
+*|
+*|
+ |
+ |
+ |
+ |
+ |
+ |
+-+
+""".strip()
+
+EXPECTED_SCROLLBAR_MIDDLE = """
+ |
+*|
+*|
+*|
+ |
+ |
+ |
+ |
+ |
+-+
+""".strip()
+
+EXPECTED_SCROLLBAR_BOTTOM = """
+ |
+ |
+ |
+ |
+ |
+ |
+*|
+*|
+*|
+-+
+""".strip()
+
+
+class TestCurses(unittest.TestCase):
+ @require_curses
+ def test_addstr(self):
+ def _draw(subwindow):
+ subwindow.addstr(0, 0, '0123456789' * 10)
+
+ # should be trimmed to the subwindow width (80 columns)
+
+ self.assertEqual('01234567890123456789012345678901234567890123456789012345678901234567890123456789', test.render(_draw).content)
+
+ @require_curses
+ def test_addstr_wrap(self):
+ def _draw(subwindow):
+ subwindow.addstr_wrap(0, 0, '0123456789 ' * 10, 25)
+
+ self.assertEqual(EXPECTED_ADDSTR_WRAP, test.render(_draw).content)
+
+ @require_curses
+ def test_addstr_wrap_single_long_word(self):
+ def _draw(subwindow):
+ subwindow.addstr_wrap(0, 0, '0123456789' * 10, 20)
+
+ self.assertEqual('01234567890123456...', test.render(_draw).content)
+
+ @require_curses
+ def test_box(self):
+ def _draw(subwindow):
+ subwindow.box(width = 5, height = 3)
+
+ self.assertEqual(EXPECTED_BOX, test.render(_draw).content)
+
+ @require_curses
+ def test_scrollbar_top(self):
+ def _draw(subwindow):
+ subwindow.scrollbar(15, 0, 30, fill_char = '*')
+
+ self.assertEqual(EXPECTED_SCROLLBAR_TOP, test.render(_draw).content.strip())
+
+ @require_curses
+ def test_scrollbar_middle(self):
+ def _draw(subwindow):
+ subwindow.scrollbar(15, 1, 30, fill_char = '*')
+
+ # even scrolling down just one index should be visible
+
+ self.assertEqual(EXPECTED_SCROLLBAR_MIDDLE, test.render(_draw).content.strip())
+
+ @require_curses
+ def test_scrollbar_bottom(self):
+ def _draw(subwindow):
+ subwindow.scrollbar(15, 30, 30, fill_char = '*')
+
+ self.skipTest('nyx presently has a bug with regard to scrolling to the bottom')
+
+ self.assertEqual(EXPECTED_SCROLLBAR_BOTTOM, test.render(_draw).content.strip())
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits