jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/671657 )
Change subject: [tests] add test for pywikibot.input_yn ......................................................................
[tests] add test for pywikibot.input_yn
Bug: T60941 Change-Id: I202e34d53be9c8a6a1a55c4196a87984b75b2b63 --- M tests/ui_tests.py 1 file changed, 10 insertions(+), 11 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/ui_tests.py b/tests/ui_tests.py index 2d39155..0d4aca9 100644 --- a/tests/ui_tests.py +++ b/tests/ui_tests.py @@ -309,15 +309,22 @@ def testInput(self): newstdin.write('input to read\n') newstdin.seek(0) - returned = pywikibot.input('question')
self.assertEqual(newstdout.getvalue(), '') self.assertEqual(newstderr.getvalue(), 'question: ') - self.assertIsInstance(returned, str) self.assertEqual(returned, 'input to read')
+ def test_input_yn(self): + newstdin.write('\n') + newstdin.seek(0) + returned = pywikibot.input_yn('question', False, automatic_quit=False) + + self.assertEqual(newstdout.getvalue(), '') + self.assertEqual(newstderr.getvalue(), 'question ([y]es, [N]o): ') + self.assertFalse(returned) + def _call_input_choice(self): rv = pywikibot.input_choice( 'question', @@ -334,7 +341,6 @@ def testInputChoiceDefault(self): newstdin.write('\n') newstdin.seek(0) - returned = self._call_input_choice()
self.assertEqual(returned, 'a') @@ -342,32 +348,25 @@ def testInputChoiceCapital(self): newstdin.write('N\n') newstdin.seek(0) - returned = self._call_input_choice()
self.assertEqual(newstderr.getvalue(), self.input_choice_output) - self.assertEqual(returned, 'n')
def testInputChoiceNonCapital(self): newstdin.write('n\n') newstdin.seek(0) - returned = self._call_input_choice()
self.assertEqual(newstderr.getvalue(), self.input_choice_output) - self.assertEqual(returned, 'n')
def testInputChoiceIncorrectAnswer(self): newstdin.write('X\nN\n') newstdin.seek(0) - returned = self._call_input_choice()
- self.assertEqual(newstderr.getvalue(), - self.input_choice_output * 2) - + self.assertEqual(newstderr.getvalue(), self.input_choice_output * 2) self.assertEqual(returned, 'n')
pywikibot-commits@lists.wikimedia.org