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_cannot_move_beyond_upper_limit(self):
stdin = (key.UP
+ key.UP
+ 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(['foo'], result)
def test_cannot_move_beyond_upper_limit(self):
stdin = helper.event_factory(
key.UP,
key.UP,
key.UP,
key.SPACE,
key.ENTER,)
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_backspace_limit(self):
self.sut.expect("What's.*", timeout=1)
self.sut.send('a')
self.sut.send(key.BACKSPACE)
self.sut.send(key.BACKSPACE)
self.sut.send('b')
self.sut.send(key.ENTER)
self.sut.expect("{'password': 'b'}", timeout=1)
def test_backspace_limit(self):
self.sut.expect("What's.*", timeout=1)
self.sut.send('a')
self.sut.send(key.BACKSPACE)
self.sut.send(key.BACKSPACE)
self.sut.send('b')
self.sut.send(key.ENTER)
self.sut.expect("{'password': 'b'}", timeout=1)
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)
def test_all_choices_are_shown(self):
stdin = helper.event_factory(key.ENTER)
message = 'Foo message'
variable = 'Bar variable'
choices = ['foo', 'bar', 'bazz']
question = questions.List(variable, message, choices=choices)
sut = ConsoleRender(event_generator=stdin)
sut.render(question)
self.assertInStdout(message)
for choice in choices:
self.assertInStdout(choice)
def test_default_input(self):
self.sut.send(key.ENTER)
self.sut.expect("{'interests': \['Computers', 'Books'\]}.*", timeout=1) # noqa
def test_no_as_default(self):
stdin = helper.event_factory(key.ENTER)
message = 'Foo message'
variable = 'Bar variable'
expected = False
question = questions.Confirm(variable,
message=message)
sut = ConsoleRender(event_generator=stdin)
result = sut.render(question)
self.assertEqual(expected, result)
self.assertInStdout(message)
self.assertInStdout('(y/N)')