def test_evaluated_key_does_not_replace_original_key(self):
# Create a list of widgets that translate 'j' to 'down' in their
# keypress() methods.
lst_contents = [self.mk_widget(urwid.Text, str(i), context='item')
for i in range(1, 10)]
self.keymap.bind('j', context='item', action=Key('down'))
# Create ListBox with separate key context. If the ListBox gets to
# handle 'j', it just checks a mark we can look for.
lst_widget = self.mk_widget(urwid.ListBox, urwid.SimpleFocusListWalker(lst_contents), context='list')
lst_got_j = FakeAction()
self.keymap.bind('j', context='list', action=lst_got_j)
# Make sure everything works regularly
size = (3, 3)
self.assert_lines(lst_widget, size, exp_lines=('1 ', '2 ', '3 '), exp_focus_pos=0)
lst_widget.keypress(size, 'down')
self.assert_lines(lst_widget, size, exp_lines=('1 ', '2 ', '3 '), exp_focus_pos=1)
# Do the actual test: Pressing 'j' should pass 'j' to the focused item,
# which evaluates it to 'down'. But the list widget must get 'j'.
lst_widget.keypress(size, 'j')
self.assert_lines(lst_widget, size, exp_lines=('1 ', '2 ', '3 '), exp_focus_pos=1)
self.assertEqual(lst_got_j.callnum, 1)
评论列表
文章目录