def test_ask_hidden_response(io): question = Question("What time is it?", "2PM") question.hide() io.set_input("8AM\n") assert "8AM" == question.ask(io) assert "What time is it? " == io.fetch_error()
def test_ask(io): question = Question("What time is it?", "2PM") io.set_input("\n8AM\n") assert "2PM" == question.ask(io) io.clear_error() assert "8AM" == question.ask(io) assert "What time is it? " == io.fetch_error()
def create_question(self, question, type=None, **kwargs): """ Returns a Question of specified type. """ if not type: return Question(question, **kwargs) if type == "choice": return ChoiceQuestion(question, **kwargs) if type == "confirmation": return ConfirmationQuestion(question, **kwargs)
def test_ask_and_validate(io): error = "This is not a color!" def validator(color): if color not in ["white", "black"]: raise Exception(error) return color question = Question("What color was the white horse of Henry IV?", "white") question.set_validator(validator) question.set_max_attempts(2) io.set_input("\nblack\n") assert "white" == question.ask(io) assert "black" == question.ask(io) io.set_input("green\nyellow\norange\n") with pytest.raises(Exception) as e: question.ask(io) assert error == str(e.value)
def confirmation_question(self, question): q = Question(question) cq = ConfirmationQuestion(question=q.question) return cq.ask(self.io())
def question_with_options(self, question, options, multi=False): q = Question(question) cq = ChoiceQuestion(q.question, options) cq.set_multi_select(multi) return cq.ask(self.io())
def ask_hidden(self, question): question = Question(question) question.hide() return self.ask_question(question)
def ask(self, question, default=None): question = Question(question, default) return self.ask_question(question)
def test_no_interaction(io): io.set_interactive(False) question = Question("Do you have a job?", "not yet") assert "not yet" == question.ask(io)
def ask_hidden(self, question): question = Question(question) question.hide() return self.ask_question(question)
def test_ask_question_with_special_characters(io): question = Question("What time is it, Sébastien?", "2PMë") io.set_input("\n") assert "2PMë" == question.ask(io) assert "What time is it, Sébastien? " == io.fetch_error()