about summary refs log tree commit diff stats
path: root/test/tc_commandlist.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-13 18:47:39 +0100
committerhut <hut@lavabit.com>2010-01-13 18:47:39 +0100
commitccd3f3c3f8baccf700f7f5286d33156a6938edfe (patch)
tree17ed97e6134af8328aaf6f8c9fc36eeb298c83ef /test/tc_commandlist.py
parentb3556b21e23eb3381b220e0d3319d94b3a89e0ac (diff)
downloadranger-ccd3f3c3f8baccf700f7f5286d33156a6938edfe.tar.gz
commandlist: improvements and test case
Diffstat (limited to 'test/tc_commandlist.py')
-rw-r--r--test/tc_commandlist.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/tc_commandlist.py b/test/tc_commandlist.py
new file mode 100644
index 00000000..ed9b1bd7
--- /dev/null
+++ b/test/tc_commandlist.py
@@ -0,0 +1,54 @@
+if __name__ == '__main__': from __init__ import init; init()
+
+from unittest import TestCase, main
+from ranger.container.commandlist import CommandList as CL
+
+class Test(TestCase):
+	def assertKeyError(self, obj, key):
+		self.assertRaises(KeyError, obj.__getitem__, key)
+
+	def test_commandist(self):
+		cl = CL()
+		fnc = lambda arg: 1
+		dmy = cl.dummy_object
+
+		cl.bind(fnc, 'aaaa')
+		cl.rebuild_paths()
+
+		self.assertEqual(dmy, cl['a'])
+		self.assertEqual(dmy, cl['aa'])
+		self.assertEqual(dmy, cl['aaa'])
+		self.assertEqual(fnc, cl['aaaa'].execute)
+		self.assertKeyError(cl, 'aabb')
+		self.assertKeyError(cl, 'aaaaa')
+
+		cl.bind(fnc, 'aabb')
+		cl.rebuild_paths()
+
+		self.assertEqual(dmy, cl['a'])
+		self.assertEqual(dmy, cl['aa'])
+		self.assertEqual(dmy, cl['aab'])
+		self.assertEqual(fnc, cl['aabb'].execute)
+		self.assertEqual(dmy, cl['aaa'])
+		self.assertEqual(fnc, cl['aaaa'].execute)
+
+		cl.unbind('aabb')
+		cl.rebuild_paths()
+
+		self.assertEqual(dmy, cl['a'])
+		self.assertEqual(dmy, cl['aa'])
+		self.assertKeyError(cl, 'aabb')
+		self.assertKeyError(cl, 'aab')
+		self.assertEqual(dmy, cl['aaa'])
+		self.assertEqual(fnc, cl['aaaa'].execute)
+
+		hint_text = 'some tip blablablba'
+		cl.hint(hint_text, 'aa')
+		cl.rebuild_paths()
+
+		self.assertEqual(dmy, cl['a'])
+		self.assertEqual(hint_text, cl['aa'].text)
+		self.assertEqual(dmy, cl['aaa'])
+		self.assertEqual(fnc, cl['aaaa'].execute)
+
+if __name__ == '__main__': main()