def test_keyseqprompt(self): result = None def cb(s): nonlocal result result = s w = prompt.KeySeqPrompt(mocks.FE(), prompt=': ', keymap=keymap.Keymap({'a': 0}), callback=cb) w.keyecho('a') # how do you test that somethign did nothing? w.echo_keystroke('a') self.assertEqual(w.keystrokes, ['a']) self.assertEqual(w.input(), 'a ') w.runcallback() self.assertEqual(result, (['a'], None)) self.assertEqual([(0, [ ({'bold'}, ': '), ((), 'a '), ({'cursor', 'visible'}, ''), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])
def test_set_cheatsheet(self): w = window.Window(None) c = [] w.set_cheatsheet(c) self.assertIs(w.cheatsheet, c) self.assertIs(w._normal_cheatsheet, c) k = keymap.Keymap() k.set_cheatsheet(['bar']) w.maybe_install_cheatsheet(k) self.assertEqual(w.cheatsheet, ['bar'])
async def test_input_char(self): with mocks.mocked_up_actual_fe_window(window.Window) as w: w.fe.supervisor = await imbroglio.get_supervisor() save = [] w.intermediate_action = ( lambda keystroke=None: save.append(keystroke)) with self.assertLogs(w.log.name, level='ERROR'): w.input_char('x') self.assertEqual(w.context._message, 'unknown command') w.keyerror_action = lambda k: save.append('E' + k) w.input_char('x') self.assertEqual(save, ['x', 'x', 'Ex']) w.keymap['y'] = lambda: save.append('y') w.input_char('y') self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y']) w.intermediate_action = None w.keymap['z'] = keymap.Keymap() w.keymap['z']['Z'] = lambda: save.append('z') w.input_char('z') w.input_char('Z') self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y', 'z']) async def key_action(): save.append('0') w.keymap['0'] = key_action self.assertFalse(w.tasks) w.input_char('0') self.assertTrue(w.tasks) await w.tasks[0] self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y', 'z', '0']) w.keymap['1'] = lambda: {}[None] with self.assertLogs(w.log, logging.ERROR): w.input_char('1') async def key_raises(): {}[None] w.keymap['2'] = key_raises w.input_char('2') with self.assertLogs(w.log, logging.ERROR): await w.tasks[0]
def test_input_char(self): with mocks.mocked_up_actual_fe_window(window.Window) as w: save = [] w.intermediate_action = ( lambda keystroke=None: save.append(keystroke)) with self.assertLogs(w.log.name, level='ERROR'): w.input_char('x') self.assertEqual(w.context._message, 'unknown command') w.keyerror_action = lambda k: save.append('E' + k) w.input_char('x') self.assertEqual(save, ['x', 'x', 'Ex']) w.keymap['y'] = lambda: save.append('y') w.input_char('y') self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y']) w.intermediate_action = None w.keymap['z'] = keymap.Keymap() w.keymap['z']['Z'] = lambda: save.append('z') w.input_char('z') w.input_char('Z') self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y', 'z']) w.keymap['0'] = asyncio.coroutine(lambda: save.append('0')) self.assertFalse(w.tasks) w.input_char('0') self.assertTrue(w.tasks) loop = asyncio.get_event_loop() loop.run_until_complete(w.tasks[0]) self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y', 'z', '0']) w.keymap['1'] = lambda: {}[None] with self.assertLogs(w.log, logging.ERROR): w.input_char('1') w.keymap['2'] = asyncio.coroutine(lambda: {}[None]) w.input_char('2') with self.assertLogs(w.log, logging.ERROR): loop.run_until_complete(w.tasks[0])
def test_input_char(self): with mocks.mocked_up_actual_fe_window(window.Window) as w: save = [] w.intermediate_action = ( lambda keystroke=None: save.append(keystroke)) with self.assertLogs(w.log.name, level='ERROR'): w.input_char('x') self.assertEqual(w.context._message, 'unknown command') w.keyerror_action = lambda k: save.append('E' + k) w.input_char('x') self.assertEqual(save, ['x', 'x', 'Ex']) w.keymap['y'] = lambda: save.append('y') w.input_char('y') self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y']) w.intermediate_action = None w.keymap['z'] = keymap.Keymap() w.keymap['z']['Z'] = lambda: save.append('z') w.input_char('z') w.input_char('Z') self.assertEqual(save, ['x', 'x', 'Ex', 'y', 'y', 'z'])