[tor-commits] [nyx/master] Basic menu item tests
atagar at torproject.org
atagar at torproject.org
Sat Aug 27 18:23:50 UTC 2016
commit 3d1e6b93f5677de86e61d76ab92e5383aa199a07
Author: Damian Johnson <atagar at torproject.org>
Date: Sun Aug 14 10:15:02 2016 -0700
Basic menu item tests
Just a few MenuItem tests to get us started.
---
test/__init__.py | 1 +
test/menu.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/test/__init__.py b/test/__init__.py
index f920114..ebb0793 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -17,6 +17,7 @@ __all__ = [
'curses',
'installation',
'log',
+ 'menu',
'panel',
'popups',
'tracker',
diff --git a/test/menu.py b/test/menu.py
new file mode 100644
index 0000000..f0de66f
--- /dev/null
+++ b/test/menu.py
@@ -0,0 +1,60 @@
+"""
+Unit tests for nyx.menu.
+"""
+
+import unittest
+
+from nyx.menu import MenuItem, Submenu, RadioMenuItem, RadioGroup
+
+NO_OP = lambda: None
+
+
+class TestMenu(unittest.TestCase):
+ def test_menu_item_parameters(self):
+ menu_item = MenuItem('Test Item', NO_OP)
+
+ self.assertEqual('', menu_item.prefix)
+ self.assertEqual('Test Item', menu_item.label)
+ self.assertEqual('', menu_item.suffix)
+ self.assertEqual(None, menu_item.parent)
+ self.assertEqual(menu_item, menu_item.submenu)
+
+ def test_submenu_parameters(self):
+ menu_item = Submenu('Test Item')
+
+ self.assertEqual('', menu_item.prefix)
+ self.assertEqual('Test Item', menu_item.label)
+ self.assertEqual(' >', menu_item.suffix)
+ self.assertEqual(None, menu_item.parent)
+ self.assertEqual(menu_item, menu_item.submenu)
+
+ def test_radio_menu_item_parameters(self):
+ group = RadioGroup(NO_OP, 'selected_item')
+ menu_item = RadioMenuItem('Test Item', group, 'selected_item')
+
+ self.assertEqual('[X] ', menu_item.prefix)
+ self.assertEqual('Test Item', menu_item.label)
+ self.assertEqual('', menu_item.suffix)
+ self.assertEqual(None, menu_item.parent)
+ self.assertEqual(menu_item, menu_item.submenu)
+
+ def test_menu_item_hierarchy(self):
+ root_submenu = Submenu('Root Submenu')
+ middle_submenu = Submenu('Middle Submenu')
+
+ root_submenu.add(MenuItem('Middle Item 1', NO_OP))
+ root_submenu.add(MenuItem('Middle Item 2', NO_OP))
+ root_submenu.add(middle_submenu)
+
+ bottom_item = MenuItem('Bottom Item', NO_OP)
+ middle_submenu.add(bottom_item)
+
+ self.assertEqual(middle_submenu, bottom_item.parent)
+ self.assertEqual(middle_submenu, bottom_item.submenu)
+ self.assertEqual(bottom_item, bottom_item.next())
+ self.assertEqual(bottom_item, bottom_item.prev())
+
+ self.assertEqual(root_submenu, middle_submenu.parent)
+ self.assertEqual(middle_submenu, middle_submenu.submenu)
+ self.assertEqual('Middle Item 1', middle_submenu.next().label)
+ self.assertEqual('Middle Item 2', middle_submenu.prev().label)
More information about the tor-commits
mailing list