diff options
author | hut <hut@lavabit.com> | 2010-04-14 20:01:47 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-04-14 20:01:47 +0200 |
commit | ef18cd85cd48117dd8bd36325887bb2a7cc49653 (patch) | |
tree | ca320ae025cc0426527f62b27c08ebbc406b0590 /test/tc_newkeys.py | |
parent | 681d9f6adf185f1c3adf0801da3d3baac99e1ea7 (diff) | |
parent | 5a8c735198079d928a7611b1f9c5aa7bf6d62a1e (diff) | |
download | ranger-ef18cd85cd48117dd8bd36325887bb2a7cc49653.tar.gz |
Merge branch 'newkey' into devel
Diffstat (limited to 'test/tc_newkeys.py')
-rw-r--r-- | test/tc_newkeys.py | 594 |
1 files changed, 594 insertions, 0 deletions
diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py new file mode 100644 index 00000000..c06c2894 --- /dev/null +++ b/test/tc_newkeys.py @@ -0,0 +1,594 @@ +# coding=utf-8 +# Copyright (C) 2009, 2010 Roman Zimbelmann <romanz@lavabit.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +if __name__ == '__main__': from __init__ import init; init() +from unittest import TestCase, main + +from ranger.ext.tree import Tree +from ranger.container.keymap import * + +import sys + +class PressTestCase(TestCase): + """Some useful methods for the actual test""" + def _mkpress(self, keybuffer, _=0): + def press(keys): + keybuffer.clear() + match = keybuffer.simulate_press(keys) + self.assertFalse(keybuffer.failure, + "parsing keys '"+keys+"' did fail!") + self.assertTrue(keybuffer.done, + "parsing keys '"+keys+"' did not complete!") + arg = CommandArgs(None, None, keybuffer) + self.assert_(match.function, "No function found! " + \ + str(match.__dict__)) + return match.function(arg) + return press + + def assertPressFails(self, kb, keys): + kb.clear() + kb.simulate_press(keys) + self.assertTrue(kb.failure, "Keypress did not fail as expected") + kb.clear() + + def assertPressIncomplete(self, kb, keys): + kb.clear() + kb.simulate_press(keys) + self.assertFalse(kb.failure, "Keypress failed, expected incomplete") + self.assertFalse(kb.done, "Keypress done which was unexpected") + kb.clear() + +class Test(PressTestCase): + """The test cases""" + def test_passive_action(self): + km = KeyMap() + directions = KeyMap() + kb = KeyBuffer(km, directions) + def n(value): + """return n or value""" + def fnc(arg=None): + if arg is None or arg.n is None: + return value + return arg.n + return fnc + + km.map('ppp', n(5)) + km.map('pp<bg>', n(8)) + km.map('pp<dir>', n(2)) + directions.map('j', dir=Direction(down=1)) + + press = self._mkpress(kb, km) + self.assertEqual(5, press('ppp')) + self.assertEqual(3, press('3ppp')) + + self.assertEqual(2, press('ppj')) + + kb.clear() + match = kb.simulate_press('pp') + args = CommandArgs(0, 0, kb) + self. |