def test_choice_asks_again_for_invalid_input(self): """Test that prompt_choice prints an error and asks again if an invalid choice is made""" returns = ["invalid input", "5", "1"] side_effect = lambda x: returns.pop(0) with mock.patch("__builtin__.raw_input", side_effect=side_effect): utils.prompt_choice(["first test option", "second test option"])
def test_choice_unicode(self): """Test prompt_choice with with unicode options""" with mock.patch("__builtin__.raw_input", return_value="1"): utils.prompt_choice( [u"first test option with \u2007", u"second test option with \u2007" u"third test option with \u2007"] )
def test_choice_result_matches_selection(self): """Test that the number returned by prompt_choice corresponds to the option chosen""" for choice in ("0", "1", "2", "3"): with mock.patch("__builtin__.raw_input", return_value=choice): res = utils.prompt_choice(["first test option", "second test option", "third test option"]) assert res == int(choice)
def test_choice(self): """Test prompt_choice with ascii options""" with mock.patch("__builtin__.raw_input", return_value="1"): utils.prompt_choice(["first test option", "second test option", "third test option"])