From 80a7914a3fa737b7dd05af43d9347dc654db6064 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 3 Feb 2014 16:33:46 +0100 Subject: ext.keybinding_parser: added doctests --- ranger/ext/keybinding_parser.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ranger/ext/keybinding_parser.py b/ranger/ext/keybinding_parser.py index 0519f69f..d7b24be3 100644 --- a/ranger/ext/keybinding_parser.py +++ b/ranger/ext/keybinding_parser.py @@ -63,10 +63,18 @@ reversed_special_keys = dict((v, k) for k, v in special_keys.items()) def parse_keybinding(obj): """Translate a keybinding to a sequence of integers - Example: - lol => (ord('l'), ord('o'), ord('l'), ord('\\n')) - => (108, 111, 108, 10) - x => (120, (27, curses.KEY_LEFT)) + >>> tuple(parse_keybinding("lol")) + (108, 111, 108, 10) + + >>> out = tuple(parse_keybinding("x")) + >>> out # it's kind of dumb that you cant test for constants... + (120, 9003, 260) + >>> out[0] == ord('x') + True + >>> out[1] == ALT_KEY + True + >>> out[2] == curses.KEY_LEFT + True """ assert isinstance(obj, (tuple, int, str)) if isinstance(obj, tuple): @@ -249,3 +257,7 @@ class KeyBuffer(object): def __str__(self): return "".join(key_to_string(c) for c in self.keys) + +if __name__ == '__main__': + import doctest + doctest.testmod() -- cgit 1.4.1-2-gfad0