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_yes_as_default(self):
stdin = helper.event_factory(key.ENTER)
message = 'Foo message'
variable = 'Bar variable'
expected = True
question = questions.Confirm(variable,
message=message,
default=True)
sut = ConsoleRender(event_generator=stdin)
result = sut.render(question)
self.assertEqual(expected, result)
self.assertInStdout(message)
self.assertInStdout('(Y/n)')
def test_unselect_with_arrows(self):
self.sut.send(key.DOWN)
self.sut.send(key.LEFT)
self.sut.send(key.ENTER)
self.sut.expect("{'interests': \['Computers'\]}.*", timeout=1) # noqa
def test_can_move(self):
stdin = (key.DOWN
+ key.DOWN
+ key.UP
+ key.SPACE
+ key.ENTER)
message = 'Foo message'
variable = 'Bar variable'
choices = ['foo', 'bar', 'bazz']
sys.stdin = StringIO(stdin)
question = questions.Checkbox(variable, message, choices=choices)
sut = ConsoleRender(key_generator=fake_key_generator)
result = sut.render(question)
self.assertEqual(['bar'], result)
keypress = readchar.readkey()
if keypress == readchar.key.UP:
new_index = selected_index
while new_index > 0:
new_index -= 1
selected_index = new_index
break
elif keypress == readchar.key.DOWN:
new_index = selected_index
while new_index < len(options) - 1:
new_index += 1
selected_index = new_index
break
elif keypress == readchar.key.ENTER:
break
elif keypress == readchar.key.CTRL_C:
raise KeyboardInterrupt
return selected_index
if pressed == key.UP:
if question.carousel and self.current == 0:
self.current = len(question.choices) - 1
else:
self.current = max(0, self.current - 1)
return
if pressed == key.DOWN:
if question.carousel and self.current == len(question.choices) - 1:
self.current = 0
else:
self.current = min(
len(self.question.choices) - 1,
self.current + 1
)
return
if pressed == key.ENTER:
value = self.question.choices[self.current]
raise errors.EndOfInput(getattr(value, 'value', value))
if pressed == key.CTRL_C:
raise KeyboardInterrupt()