示例#1
0
 def test_guessing_game_win(self):
     user_input = [1, 7, 4]
     expected_output = ["Too Low!", "Too High!", "You win!"]
     with patch('builtins.input', side_effect=user_input):
         with patch('sys.stdout', new=StringIO()) as fake:
             target.guessing_game(4)
             output = fake.getvalue().rstrip('\n').split('\n')
     self.assertEqual(output, expected_output)
示例#2
0
 def test_guessing_game_q(self):
     user_input = ["q"]
     expected_output = "Goodbye, quitter!"
     with patch('builtins.input', side_effect=user_input):
         with patch('sys.stdout', new=StringIO()) as fake:
             target.guessing_game(6)
             output = fake.getvalue().strip('\n')
     self.assertEqual(output, expected_output)