Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cursor_movement(self):
stdin_array = [
'a',
key.UP,
'b',
key.DOWN,
'c',
key.LEFT,
'd',
key.RIGHT,
'e',
key.ENTER,
]
stdin = helper.event_factory(*stdin_array)
message = 'Foo message'
variable = 'Bar variable'
question = questions.Text(variable, message)
sut = ConsoleRender(event_generator=stdin)
result = sut.render(question)
self.assertEqual('abdce', result)
def test_right_cursor_do_not_unselect(self):
stdin_array = [key.RIGHT, key.RIGHT, key.ENTER]
stdin = helper.event_factory(*stdin_array)
message = 'Foo message'
variable = 'Bar variable'
choices = ['foo', 'bar', 'bazz']
question = questions.Checkbox(variable, message, choices=choices)
sut = ConsoleRender(event_generator=stdin)
result = sut.render(question)
self.assertEqual(['foo'], result)
def test_cursor_movement(self):
stdin_array = [
'a',
key.UP,
'b',
key.DOWN,
'c',
key.LEFT,
'd',
key.RIGHT,
'e',
key.ENTER,
]
stdin = helper.event_factory(*stdin_array)
message = 'Foo message'
variable = 'Bar variable'
question = questions.Password(variable, message)
sut = ConsoleRender(event_generator=stdin)
result = sut.render(question)
self.assertEqual('abdce', result)
def test_select_with_arrows(self):
self.sut.send(key.DOWN)
self.sut.send(key.DOWN)
self.sut.send(key.RIGHT)
self.sut.send(key.ENTER)
self.sut.expect(
"{'interests': \['Computers', 'Books', 'Science'\]}.*", # noqa
timeout=1
)
if pressed == key.UP:
self.current = max(0, self.current - 1)
return
elif pressed == key.DOWN:
self.current = min(len(self.question.choices) - 1,
self.current + 1)
return
elif pressed == key.SPACE:
if self.current in self.selection:
self.selection.remove(self.current)
else:
self.selection.append(self.current)
elif pressed == key.LEFT:
if self.current in self.selection:
self.selection.remove(self.current)
elif pressed == key.RIGHT:
if self.current not in self.selection:
self.selection.append(self.current)
elif pressed == key.ENTER:
result = []
for x in self.selection:
value = self.question.choices[x]
result.append(getattr(value, 'value', value))
raise errors.EndOfInput(result)
elif pressed == key.CTRL_C:
raise KeyboardInterrupt()
raise KeyboardInterrupt()
if pressed in (key.CR, key.LF, key.ENTER):
raise errors.EndOfInput(self.current)
if pressed == key.BACKSPACE:
if self.current and self.cursor_offset != len(self.current):
if self.cursor_offset > 0:
self.current = (self.current[:-self.cursor_offset - 1] +
self.current[-self.cursor_offset:])
else:
self.current = self.current[:-1]
elif pressed == key.LEFT:
if self.cursor_offset < len(self.current):
self.cursor_offset += 1
elif pressed == key.RIGHT:
self.cursor_offset = max(self.cursor_offset - 1, 0)
elif len(pressed) != 1:
return
else:
if self.cursor_offset == 0:
self.current += pressed
else:
self.current = ''.join((
self.current[:-self.cursor_offset],
pressed,
self.current[-self.cursor_offset:]
))