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_keyboard_interrupt_ctrl_c_no_input(self, *m):
with InputContext(readchar.key.CTRL_C):
with self.assertRaises(KeyboardInterrupt):
cutie.select(["foo"])
def test_keyboard_interrupt_ctrl_c_selected(self, *m):
with InputContext(readchar.key.DOWN, readchar.key.CTRL_C):
with self.assertRaises(KeyboardInterrupt):
cutie.select(["foo"], selected_index=0)
def test_ctrl_c_breaks_execution(self):
stdin_array = [key.CTRL_C]
stdin = helper.event_factory(*stdin_array)
message = 'Foo message'
variable = 'Bar variable'
question = questions.List(variable, message)
sut = ConsoleRender(event_generator=stdin)
with self.assertRaises(KeyboardInterrupt):
sut.render(question)
def test_ctrl_c_breaks_execution(self):
stdin_array = [key.CTRL_C]
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)
with self.assertRaises(KeyboardInterrupt):
sut.render(question)
def test_evaluate_written_input_no_case_sensitive(self, mock_print):
expected_calls = (('\x1b[3A\r\x1b[Kfoo (Y/N) no',), {"end": '', "flush": True},)
with InputContext("n", "o", readchar.key.CTRL_C):
res = None
with self.assertRaises(KeyboardInterrupt):
res = cutie.prompt_yes_or_no("foo", has_to_match_case=True)
self.assertIsNone(res)
self.assertEqual(mock_print.call_args_list[-1], expected_calls)
print_call("No", "selected"),
(('\x1b[3A\r\x1b[Kfoo (Y/N) ',), {"end": '', "flush": True},),
(tuple(),),
print_call("Yes"),
print_call("No"),
(('\x1b[3A\r\x1b[Kfoo (Y/N) f',), {"end": '', "flush": True},),
(tuple(),),
print_call("Yes"),
print_call("No"),
(('\x1b[3A\r\x1b[Kfoo (Y/N) fo',), {"end": '', "flush": True},),
(tuple(),),
print_call("Yes"),
print_call("No"),
(('\x1b[3A\r\x1b[Kfoo (Y/N) foo',), {"end": '', "flush": True},),
]
with InputContext("f", "o", "o", readchar.key.CTRL_C):
with self.assertRaises(KeyboardInterrupt):
cutie.prompt_yes_or_no("foo")
self.assertEqual(mock_print.call_args_list, expected_calls)
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()
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()
def process_input(self, pressed):
if pressed == key.CTRL_C:
raise KeyboardInterrupt()
if pressed.lower() == key.ENTER:
raise errors.EndOfInput(self.question.default)
if pressed in 'yY':
print(pressed)
raise errors.EndOfInput(True)
if pressed in 'nN':
print(pressed)
raise errors.EndOfInput(False)