def test_insert(self, commander_tctx): edit = commander.CommandEdit(commander_tctx.master, '') edit.keypress(1, 'a') assert edit.get_edit_text() == 'a' # Don't let users type a space before starting a command # as a usability feature edit = commander.CommandEdit(commander_tctx.master, '') edit.keypress(1, ' ') assert edit.get_edit_text() == ''
def test_insert(self): with taddons.context() as tctx: history = commander.CommandHistory(tctx.master, size=3) edit = commander.CommandEdit(tctx.master, '', history) edit.keypress(1, 'a') assert edit.get_edit_text() == 'a' # Don't let users type a space before starting a command # as a usability feature history = commander.CommandHistory(tctx.master, size=3) edit = commander.CommandEdit(tctx.master, '', history) edit.keypress(1, ' ') assert edit.get_edit_text() == ''
def test_open_command_bar(self, commander_tctx): edit = commander.CommandEdit(commander_tctx.master, '') try: edit.update() except IndexError: pytest.faied("Unexpected IndexError")
def test_backspace(self): with taddons.context() as tctx: history = commander.CommandHistory(tctx.master, size=3) edit = commander.CommandEdit(tctx.master, '', history) edit.keypress(1, 'a') edit.keypress(1, 'b') assert edit.get_edit_text() == 'ab' edit.keypress(1, 'backspace') assert edit.get_edit_text() == 'a'
def test_open_command_bar(self): with taddons.context() as tctx: history = commander.CommandHistory(tctx.master, size=3) edit = commander.CommandEdit(tctx.master, '', history) try: edit.update() except IndexError: pytest.faied("Unexpected IndexError")
def test_backspace(self, commander_tctx): edit = commander.CommandEdit(commander_tctx.master, '') edit.keypress(1, 'a') edit.keypress(1, 'b') assert edit.get_edit_text() == 'ab' edit.keypress(1, 'backspace') assert edit.get_edit_text() == 'a'
def test_left(self): with taddons.context() as tctx: history = commander.CommandHistory(tctx.master, size=3) edit = commander.CommandEdit(tctx.master, '', history) edit.keypress(1, 'a') assert edit.cbuf.cursor == 1 edit.keypress(1, 'left') assert edit.cbuf.cursor == 0 # Do it again to make sure it won't go negative edit.keypress(1, 'left') assert edit.cbuf.cursor == 0
def sig_prompt_command(self, sender, partial: str = "", cursor: Optional[int] = None): signals.focus.send(self, section="footer") self._w = commander.CommandEdit( self.master, partial, ) if cursor is not None: self._w.cbuf.cursor = cursor self.prompting = self.execute_command
def test_left(self, commander_tctx): edit = commander.CommandEdit(commander_tctx.master, '') edit.keypress(1, 'a') assert edit.cbuf.cursor == 1 edit.keypress(1, 'left') assert edit.cbuf.cursor == 0 # Do it again to make sure it won't go negative edit.keypress(1, 'left') assert edit.cbuf.cursor == 0
def test_up_and_down(self): with taddons.context() as tctx: history = commander.CommandHistory(tctx.master, size=3) edit = commander.CommandEdit(tctx.master, '', history) buf = commander.CommandBuffer(tctx.master, 'cmd1') history.add_command(buf) buf = commander.CommandBuffer(tctx.master, 'cmd2') history.add_command(buf) edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' history = commander.CommandHistory(tctx.master, size=5) edit = commander.CommandEdit(tctx.master, '', history) edit.keypress(1, 'a') edit.keypress(1, 'b') edit.keypress(1, 'c') assert edit.get_edit_text() == 'abc' edit.keypress(1, 'up') assert edit.get_edit_text() == '' edit.keypress(1, 'down') assert edit.get_edit_text() == 'abc' edit.keypress(1, 'down') assert edit.get_edit_text() == 'abc' history = commander.CommandHistory(tctx.master, size=5) edit = commander.CommandEdit(tctx.master, '', history) buf = commander.CommandBuffer(tctx.master, 'cmd3') history.add_command(buf) edit.keypress(1, 'z') edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'down') assert edit.get_edit_text() == 'z'
def test_right(self): with taddons.context() as tctx: history = commander.CommandHistory(tctx.master, size=3) edit = commander.CommandEdit(tctx.master, '', history) edit.keypress(1, 'a') assert edit.cbuf.cursor == 1 # Make sure cursor won't go past the text edit.keypress(1, 'right') assert edit.cbuf.cursor == 1 # Make sure cursor goes left and then back right edit.keypress(1, 'left') assert edit.cbuf.cursor == 0 edit.keypress(1, 'right') assert edit.cbuf.cursor == 1
def test_right(self, commander_tctx): edit = commander.CommandEdit(commander_tctx.master, '') edit.keypress(1, 'a') assert edit.cbuf.cursor == 1 # Make sure cursor won't go past the text edit.keypress(1, 'right') assert edit.cbuf.cursor == 1 # Make sure cursor goes left and then back right edit.keypress(1, 'left') assert edit.cbuf.cursor == 0 edit.keypress(1, 'right') assert edit.cbuf.cursor == 1
def test_cycle_completion(self): with taddons.context() as commander_tctx: cb = commander.CommandBuffer(commander_tctx.master) cb.text = "foo bar" cb.cursor = len(cb.text) cb.cycle_completion() ce = commander.CommandEdit(commander_tctx.master, "se") ce.keypress(1, 'tab') ce.update() ret = ce.cbuf.render() assert ret == [ ('commander_command', 'set'), ('text', ' '), ('commander_hint', 'option '), ('commander_hint', 'value '), ]
def sig_prompt_command(self, sender, partial=""): signals.focus.send(self, section="footer") self._w = commander.CommandEdit(self.master, partial) self.prompting = commandexecutor.CommandExecutor(self.master)
def test_up_and_down(self, commander_tctx): edit = commander.CommandEdit(commander_tctx.master, '') commander_tctx.master.commands.execute('commands.history.clear') commander_tctx.master.commands.execute('commands.history.add "cmd1"') edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit = commander.CommandEdit(commander_tctx.master, '') commander_tctx.master.commands.execute('commands.history.clear') commander_tctx.master.commands.execute('commands.history.add "cmd1"') commander_tctx.master.commands.execute('commands.history.add "cmd2"') edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'a') edit.keypress(1, 'b') edit.keypress(1, 'c') assert edit.get_edit_text() == 'abc' edit.keypress(1, 'up') assert edit.get_edit_text() == 'abc' edit.keypress(1, 'down') assert edit.get_edit_text() == 'abc' edit.keypress(1, 'down') assert edit.get_edit_text() == 'abc' edit.keypress(1, 'up') assert edit.get_edit_text() == 'abc' edit = commander.CommandEdit(commander_tctx.master, '') commander_tctx.master.commands.execute('commands.history.add "cmd3"') edit.keypress(1, 'z') edit.keypress(1, 'up') assert edit.get_edit_text() == 'z' edit.keypress(1, 'down') assert edit.get_edit_text() == 'z' edit.keypress(1, 'down') assert edit.get_edit_text() == 'z' edit.keypress(1, 'backspace') assert edit.get_edit_text() == '' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'c') assert edit.get_edit_text() == 'c' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'down') assert edit.get_edit_text() == '' edit.keypress(1, 'backspace') assert edit.get_edit_text() == '' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'up') assert edit.get_edit_text() == 'cmd1' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd2' edit.keypress(1, 'down') assert edit.get_edit_text() == 'cmd3' edit.keypress(1, 'down') assert edit.get_edit_text() == ''