コード例 #1
0
ファイル: test_command.py プロジェクト: wyuenho/blueberrypy
    def test_str_not_required_no_default_no_matcher(self):
        (self.input_expectation
         .with_args("question: ")
         .and_return('', "answer")
         .one_by_one())

        self.assertEqual(get_answer(prompt="question: "), '')
        self.assertEqual(get_answer(prompt="question: "), 'answer')
コード例 #2
0
    def test_str_required_on_condition(self):
        (self.input_expectation.with_args("question: ").and_return("answer"))

        answer = get_answer(prompt="question: ",
                            required="condition",
                            config={"condition": True})
        self.assertEqual(answer, "answer")

        answer = get_answer(prompt="question: ",
                            required="condition",
                            config={"condition": False})
        self.assertEqual(answer, '')
コード例 #3
0
ファイル: test_command.py プロジェクト: wyuenho/blueberrypy
    def test_str_required_on_condition(self):
        (self.input_expectation
         .with_args("question: ")
         .and_return("answer"))

        answer = get_answer(prompt="question: ", required="condition",
                            config={"condition": True})
        self.assertEqual(answer, "answer")

        answer = get_answer(prompt="question: ", required="condition",
                            config={"condition": False})
        self.assertEqual(answer, '')
コード例 #4
0
    def test_str_not_required_default_matcher(self):
        (self.input_expectation.with_args("question: ").and_return(
            "answer", "abcccc", '').one_by_one())

        answer = get_answer(prompt="question: ",
                            default="hello",
                            matcher=re.compile(r"^abc+$").match)
        self.assertEqual(answer, "abcccc")

        answer = get_answer(prompt="question: ",
                            default="hello",
                            matcher=re.compile(r"^abc+$").match)
        self.assertEqual(answer, "hello")
コード例 #5
0
ファイル: test_command.py プロジェクト: wyuenho/blueberrypy
    def test_str_required_default_matcher(self):
        (self.input_expectation
         .with_args("question: ")
         .and_return('', "abcccc")
         .one_by_one())

        answer = get_answer(prompt="question: ", required=True, default="answer",
                            matcher=re.compile(r"^abc+$").match)
        self.assertEqual(answer, "answer")

        answer = get_answer(prompt="question: ", required=True, default="answer",
                            matcher=re.compile(r"^abc+$").match)
        self.assertEqual(answer, "abcccc")
コード例 #6
0
    def test_str_required_default_no_matcher(self):
        (self.input_expectation.with_args("question: ").and_return(''))

        answer = get_answer(prompt="question: ",
                            required=True,
                            default="answer")
        self.assertEqual(answer, "answer")
コード例 #7
0
    def test_callable_default(self):
        (self.input_expectation.with_args("question: ").and_return("answer"))

        answer = get_answer(prompt="question: ",
                            default=lambda config: config["default"],
                            config={"default": "question: "})
        self.assertEqual(answer, "answer")
コード例 #8
0
ファイル: test_command.py プロジェクト: wyuenho/blueberrypy
    def test_str_required_default_no_matcher(self):
        (self.input_expectation
         .with_args("question: ")
         .and_return(''))

        answer = get_answer(prompt="question: ", required=True, default="answer")
        self.assertEqual(answer, "answer")
コード例 #9
0
ファイル: test_command.py プロジェクト: wyuenho/blueberrypy
    def test_callable_prompt(self):
        (self.input_expectation
         .with_args("question: ")
         .and_return("answer"))

        answer = get_answer(prompt=lambda config: config["prompt"],
                            config={"prompt": "question: "})
        self.assertEqual(answer, "answer")
コード例 #10
0
    def test_not_required_default_no_matcher(self):
        (self.input_expectation.with_args("question: ").and_return(
            '', "foo", 'bool', 'y', 'n', '').one_by_one())

        answer = get_answer(prompt="question: ", default="answer")
        self.assertEqual(answer, "answer")

        answer = get_answer(prompt="question: ", default="answer")
        self.assertEqual(answer, "foo")

        answer = get_answer(prompt="question: ", type=bool, default=True)
        self.assertEqual(answer, True)

        answer = get_answer(prompt="question: ", type=bool, default=True)
        self.assertEqual(answer, False)

        answer = get_answer(prompt="question: ", type=bool, default=True)
        self.assertEqual(answer, True)
コード例 #11
0
ファイル: test_command.py プロジェクト: wyuenho/blueberrypy
    def test_not_required_default_no_matcher(self):
        (self.input_expectation
         .with_args("question: ")
         .and_return('', "foo", 'bool', 'y', 'n', '')
         .one_by_one())

        answer = get_answer(prompt="question: ", default="answer")
        self.assertEqual(answer, "answer")

        answer = get_answer(prompt="question: ", default="answer")
        self.assertEqual(answer, "foo")

        answer = get_answer(prompt="question: ", type=bool, default=True)
        self.assertEqual(answer, True)

        answer = get_answer(prompt="question: ", type=bool, default=True)
        self.assertEqual(answer, False)

        answer = get_answer(prompt="question: ", type=bool, default=True)
        self.assertEqual(answer, True)
コード例 #12
0
    def test_str_not_required_no_default_no_matcher(self):
        (self.input_expectation.with_args("question: ").and_return(
            '', "answer").one_by_one())

        self.assertEqual(get_answer(prompt="question: "), '')
        self.assertEqual(get_answer(prompt="question: "), 'answer')