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


Python mock.NonCallableMock方法代碼示例

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


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

示例1: vim

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def vim():
    """A wide-open mock vim object.

    We'll just have to be careful since we can't import a real vim object to
    use autospec and guarantee that we're calling real APIs.
    """
    def vimeval(expr):
        # Default Editor.isneovim to False.
        # TODO: easy way to override this; neovim mock fixture?
        if expr == "has('nvim')":
            return False
        else:
            return mock.DEFAULT

    attrs = {'eval.side_effect': vimeval}
    return mock.NonCallableMock(name='mockvim', **attrs) 
開發者ID:ensime,項目名稱:ensime-vim,代碼行數:18,代碼來源:conftest.py

示例2: test_get_real_user_not_callable

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def test_get_real_user_not_callable(self):
        """
        Test user_email, user_username, and user_language not available
        """
        self.xblock.runtime.get_real_user = NonCallableMock()

        real_user_data = self.xblock.extract_real_user_data()
        self.assertIsNone(real_user_data['user_email'])
        self.assertIsNone(real_user_data['user_username'])
        self.assertIsNone(real_user_data['user_language']) 
開發者ID:edx,項目名稱:xblock-lti-consumer,代碼行數:12,代碼來源:test_lti_consumer.py

示例3: test_rejects_questionnaire_from_returns_none

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def test_rejects_questionnaire_from_returns_none(self, recruiter):
        dummy = mock.NonCallableMock()
        assert recruiter.rejects_questionnaire_from(participant=dummy) is None 
開發者ID:Dallinger,項目名稱:Dallinger,代碼行數:5,代碼來源:test_recruiters.py

示例4: test_close

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def test_close():
    mock_transport = mock.NonCallableMock()
    client = subscriber.Client(transport=mock_transport)

    client.close()

    mock_transport.channel.close.assert_called() 
開發者ID:googleapis,項目名稱:python-pubsub,代碼行數:9,代碼來源:test_subscriber_client.py

示例5: test_closes_channel_as_context_manager

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def test_closes_channel_as_context_manager():
    mock_transport = mock.NonCallableMock()
    client = subscriber.Client(transport=mock_transport)

    with client:
        pass

    mock_transport.channel.close.assert_called() 
開發者ID:googleapis,項目名稱:python-pubsub,代碼行數:10,代碼來源:test_subscriber_client.py

示例6: test_streaming_pull_gapic_monkeypatch

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def test_streaming_pull_gapic_monkeypatch():
    transport = mock.NonCallableMock(spec=["streaming_pull"])
    transport.streaming_pull = mock.Mock(spec=[])
    client = subscriber.Client(transport=transport)

    client.streaming_pull(requests=iter([]))

    assert client.api.transport is transport
    assert hasattr(transport.streaming_pull, "_prefetch_first_result_")
    assert not transport.streaming_pull._prefetch_first_result_ 
開發者ID:googleapis,項目名稱:python-pubsub,代碼行數:12,代碼來源:test_subscriber_client.py

示例7: test_labels_setter_with_removal

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def test_labels_setter_with_removal(self):
        # Make sure the bucket labels look correct and follow the expected
        # public structure.
        bucket = self._make_one(name="name")
        self.assertEqual(bucket.labels, {})
        bucket.labels = {"color": "red", "flavor": "cherry"}
        self.assertEqual(bucket.labels, {"color": "red", "flavor": "cherry"})
        bucket.labels = {"color": "red"}
        self.assertEqual(bucket.labels, {"color": "red"})

        # Make sure that a patch call correctly removes the flavor label.
        client = mock.NonCallableMock(spec=("_connection",))
        client._connection = mock.NonCallableMock(spec=("api_request",))
        bucket.patch(client=client)
        client._connection.api_request.assert_called()
        _, _, kwargs = client._connection.api_request.mock_calls[0]
        self.assertEqual(len(kwargs["data"]["labels"]), 2)
        self.assertEqual(kwargs["data"]["labels"]["color"], "red")
        self.assertIsNone(kwargs["data"]["labels"]["flavor"])
        self.assertEqual(kwargs["timeout"], self._get_default_timeout())

        # A second patch call should be a no-op for labels.
        client._connection.api_request.reset_mock()
        bucket.patch(client=client, timeout=42)
        client._connection.api_request.assert_called()
        _, _, kwargs = client._connection.api_request.mock_calls[0]
        self.assertNotIn("labels", kwargs["data"])
        self.assertEqual(kwargs["timeout"], 42) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:30,代碼來源:test_bucket.py

示例8: mock_sql

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def mock_sql():
    mock_sql_query = Mock(spec_set=['_execute_sql', 'query', 'as_sql'])
    mock_sql_query._execute_sql = Mock()
    mock_sql_query.query = NonCallableMock(spec_set=['model'])
    mock_sql_query.query.model = Mock()
    query_string = 'SELECT * from table_name'
    mock_sql_query.as_sql = Mock(return_value=(query_string, ()))
    return mock_sql_query, query_string 
開發者ID:jazzband,項目名稱:django-silk,代碼行數:10,代碼來源:test_execute_sql.py

示例9: _mock_response

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def _mock_response(self):
        response = NonCallableMock()
        response._headers = {}
        response.status_code = 200
        response.queries = []
        response.get = response._headers.get
        response.content = ''
        return response 
開發者ID:jazzband,項目名稱:django-silk,代碼行數:10,代碼來源:test_config_meta.py

示例10: mock_cloneable

# 需要導入模塊: import mock [as 別名]
# 或者: from mock import NonCallableMock [as 別名]
def mock_cloneable(cloneable_subclass_with_api_call_method):

    # pylint:disable=abstract-method
    class MockCloneable(cloneable_subclass_with_api_call_method, NonCallableMock):
        pass

    return MockCloneable(spec_set=cloneable_subclass_with_api_call_method, name='Cloneable') 
開發者ID:box,項目名稱:box-python-sdk,代碼行數:9,代碼來源:test_api_call_decorator.py


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