當前位置: 首頁>>代碼示例>>Python>>正文


Python DnstestConfig.prompt_input方法代碼示例

本文整理匯總了Python中pydnstest.config.DnstestConfig.prompt_input方法的典型用法代碼示例。如果您正苦於以下問題:Python DnstestConfig.prompt_input方法的具體用法?Python DnstestConfig.prompt_input怎麽用?Python DnstestConfig.prompt_input使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pydnstest.config.DnstestConfig的用法示例。


在下文中一共展示了DnstestConfig.prompt_input方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_prompt_input_validate_failure

# 需要導入模塊: from pydnstest.config import DnstestConfig [as 別名]
# 或者: from pydnstest.config.DnstestConfig import prompt_input [as 別名]
    def test_prompt_input_validate_failure(self, capfd):
        # this is a bit complex, because our mocks need to do different things on first and second calls
        input_returns = ['hello', 'goodbye']

        def input_se(*args):
            return input_returns.pop(0)

        input_mock = mock.MagicMock(side_effect=input_se)
        confirm_mock = mock.MagicMock()
        confirm_mock.return_value = True
        validate_returns = [None, 'eybdoog']

        def validate_se(*args):
            return validate_returns.pop(0)

        validate_mock = mock.MagicMock(side_effect=validate_se)

        dc = DnstestConfig()
        with mock.patch('pydnstest.config.DnstestConfig.input_wrapper', input_mock):
            with mock.patch('pydnstest.config.DnstestConfig.confirm_response', confirm_mock):
                foo = dc.prompt_input("foo", validate_cb=validate_mock)
        assert input_mock.call_count == 2
        out, err = capfd.readouterr()
        assert out == "ERROR: invalid response: hello\n"
        assert err == ""
        assert confirm_mock.call_count == 1
        assert validate_mock.call_count == 2
        assert foo == 'eybdoog'
開發者ID:,項目名稱:,代碼行數:30,代碼來源:

示例2: test_prompt_input_default

# 需要導入模塊: from pydnstest.config import DnstestConfig [as 別名]
# 或者: from pydnstest.config.DnstestConfig import prompt_input [as 別名]
    def test_prompt_input_default(self):
        input_mock = mock.MagicMock()
        input_mock.return_value = ''
        confirm_mock = mock.MagicMock()
        confirm_mock.return_value = True

        dc = DnstestConfig()
        with mock.patch('pydnstest.config.DnstestConfig.input_wrapper', input_mock):
            with mock.patch('pydnstest.config.DnstestConfig.confirm_response', confirm_mock):
                foo = dc.prompt_input("foo", default='bar')
        assert input_mock.call_count == 1
        assert input_mock.call_args == mock.call("foo (default: bar): ")
        assert confirm_mock.call_count == 1
        assert foo == 'bar'
開發者ID:,項目名稱:,代碼行數:16,代碼來源:

示例3: test_prompt_input_validate_success

# 需要導入模塊: from pydnstest.config import DnstestConfig [as 別名]
# 或者: from pydnstest.config.DnstestConfig import prompt_input [as 別名]
    def test_prompt_input_validate_success(self):
        input_mock = mock.MagicMock()
        input_mock.return_value = 'hello'
        confirm_mock = mock.MagicMock()
        confirm_mock.return_value = True
        validate_mock = mock.MagicMock()
        validate_mock.return_value = 'goodbye'

        dc = DnstestConfig()
        with mock.patch('pydnstest.config.DnstestConfig.input_wrapper', input_mock):
            with mock.patch('pydnstest.config.DnstestConfig.confirm_response', confirm_mock):
                foo = dc.prompt_input("foo", validate_cb=validate_mock)
        assert input_mock.call_count == 1
        assert confirm_mock.call_count == 1
        assert validate_mock.call_count == 1
        assert foo == 'goodbye'
開發者ID:,項目名稱:,代碼行數:18,代碼來源:

示例4: test_prompt_input_no_confirm

# 需要導入模塊: from pydnstest.config import DnstestConfig [as 別名]
# 或者: from pydnstest.config.DnstestConfig import prompt_input [as 別名]
    def test_prompt_input_no_confirm(self):
        input_mock = mock.MagicMock()
        input_mock.return_value = 'hello'

        def confirm_se(*args):
            return confirm_returns.pop(0)

        confirm_returns = [False, True]
        confirm_mock = mock.MagicMock(side_effect=confirm_se)

        dc = DnstestConfig()
        with mock.patch('pydnstest.config.DnstestConfig.input_wrapper', input_mock):
            with mock.patch('pydnstest.config.DnstestConfig.confirm_response', confirm_mock):
                foo = dc.prompt_input("foo")
        assert input_mock.call_count == 2
        assert confirm_mock.call_count == 2
        assert foo == 'hello'
開發者ID:,項目名稱:,代碼行數:19,代碼來源:

示例5: test_prompt_input_default_float

# 需要導入模塊: from pydnstest.config import DnstestConfig [as 別名]
# 或者: from pydnstest.config.DnstestConfig import prompt_input [as 別名]
    def test_prompt_input_default_float(self):
        input_mock = mock.MagicMock()
        input_mock.return_value = ''
        confirm_mock = mock.MagicMock()
        confirm_mock.return_value = True
        validate_mock = mock.MagicMock()
        validate_mock.return_value = 123.456

        dc = DnstestConfig()
        with mock.patch('pydnstest.config.DnstestConfig.input_wrapper', input_mock):
            with mock.patch('pydnstest.config.DnstestConfig.confirm_response', confirm_mock):
                foo = dc.prompt_input("foo", default=123.456, validate_cb=validate_mock)
        assert input_mock.call_count == 1
        assert input_mock.call_args == mock.call("foo (default: 123.456): ")
        assert confirm_mock.call_count == 1
        assert validate_mock.call_count == 1
        assert validate_mock.call_args == mock.call('123.456')
        assert foo == 123.456
開發者ID:,項目名稱:,代碼行數:20,代碼來源:


注:本文中的pydnstest.config.DnstestConfig.prompt_input方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。