Example #1
0
 def test_single_letter_responses(self):
     with patch_stdin('y\n'):
         with redirect_output() as out:
             output = boolean_prompt("Yes or no?")
     self.assertEqual(out.getvalue(), "Yes or no? [y/n] ")
     self.assertTrue(output)
     with patch_stdin('N\n'):
         with redirect_output() as out:
             output = boolean_prompt("Yes or no?")
     self.assertEqual(out.getvalue(), "Yes or no? [y/n] ")
     self.assertFalse(output)
Example #2
0
 def test_different_capitalizations(self):
     with patch_stdin('Yes\n'):
         with redirect_output() as out:
             output = boolean_prompt("Yes or no?")
     self.assertEqual(out.getvalue(), "Yes or no? [y/n] ")
     self.assertTrue(output)
     with patch_stdin('NO\n'):
         with redirect_output() as out:
             output = boolean_prompt("Yes or no?")
     self.assertEqual(out.getvalue(), "Yes or no? [y/n] ")
     self.assertFalse(output)
Example #3
0
 def test_default_with_valid_response(self):
     with patch_stdin('nope\nNo\n'):
         with redirect_output(StringIO()) as out:
             output = boolean_prompt("Yes or no?", default=True)
     self.assertEqual(
         out.getvalue(), "Yes or no? [Y/n] "
         "\nPlease enter 'yes' or 'no'.\n\n"
         "Yes or no? [Y/n] ")
     self.assertFalse(output)
     with patch_stdin('YES\n'):
         with redirect_output(StringIO()) as out:
             output = boolean_prompt("Yes or no?", default=True)
     self.assertEqual(out.getvalue(), "Yes or no? [Y/n] ")
     self.assertTrue(output)
Example #4
0
 def test_default_with_nonblank_responses(self):
     with patch_stdin('yep\nyes\n'):
         with redirect_output(StringIO()) as out:
             output = boolean_prompt("Yes or no?", default=True)
     self.assertEqual(
         out.getvalue(), "Yes or no? [Y/n] "
         "\nPlease enter 'yes' or 'no'.\n\n"
         "Yes or no? [Y/n] ")
     self.assertTrue(output)
Example #5
0
 def test_first_response_invalid(self):
     with patch_stdin('yeah\nyes'):
         with redirect_output(StringIO()) as out:
             output = boolean_prompt("Yes or no?")
     self.assertEqual(
         out.getvalue(), "Yes or no? [y/n] "
         "\nPlease enter 'yes' or 'no'.\n\n"
         "Yes or no? [y/n] ")
     self.assertTrue(output)
Example #6
0
 def test_multiple_invalid_responses(self):
     with patch_stdin('eh\n\nnope\nno'):
         with redirect_output(StringIO()) as out:
             output = boolean_prompt("Yes or no?")
     self.assertEqual(
         out.getvalue(), "Yes or no? [y/n] "
         "\nPlease enter 'yes' or 'no'.\n\n"
         "Yes or no? [y/n] "
         "\nPlease enter 'yes' or 'no'.\n\n"
         "Yes or no? [y/n] "
         "\nPlease enter 'yes' or 'no'.\n\n"
         "Yes or no? [y/n] ")
     self.assertFalse(output)
Example #7
0
 def test_default_of_false(self):
     with patch_stdin('\n'):
         with redirect_output(StringIO()) as out:
             output = boolean_prompt("Yes or no?", default=False)
     self.assertEqual(out.getvalue(), "Yes or no? [y/N] ")
     self.assertFalse(output)
Example #8
0
 def test_whitespace(self):
     with patch_stdin(' yes  \n'):
         with redirect_output() as out:
             output = boolean_prompt("Is the sky blue?")
     self.assertEqual(out.getvalue(), "Is the sky blue? [y/n] ")
     self.assertTrue(output)
Example #9
0
 def test_no(self):
     with patch_stdin('no\n'):
         with redirect_output() as out:
             output = boolean_prompt("Yes or no?")
     self.assertEqual(out.getvalue(), "Yes or no? [y/n] ")
     self.assertFalse(output)