Python mock.NonCallableMock() Examples

The following are 10 code examples of mock.NonCallableMock(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mock , or try the search function .
Example #1
Source File: conftest.py    From ensime-vim with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: test_lti_consumer.py    From xblock-lti-consumer with GNU Affero General Public License v3.0 5 votes vote down vote up
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']) 
Example #3
Source File: test_recruiters.py    From Dallinger with MIT License 5 votes vote down vote up
def test_rejects_questionnaire_from_returns_none(self, recruiter):
        dummy = mock.NonCallableMock()
        assert recruiter.rejects_questionnaire_from(participant=dummy) is None 
Example #4
Source File: test_subscriber_client.py    From python-pubsub with Apache License 2.0 5 votes vote down vote up
def test_close():
    mock_transport = mock.NonCallableMock()
    client = subscriber.Client(transport=mock_transport)

    client.close()

    mock_transport.channel.close.assert_called() 
Example #5
Source File: test_subscriber_client.py    From python-pubsub with Apache License 2.0 5 votes vote down vote up
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() 
Example #6
Source File: test_subscriber_client.py    From python-pubsub with Apache License 2.0 5 votes vote down vote up
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_ 
Example #7
Source File: test_bucket.py    From python-storage with Apache License 2.0 5 votes vote down vote up
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) 
Example #8
Source File: test_execute_sql.py    From django-silk with MIT License 5 votes vote down vote up
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 
Example #9
Source File: test_config_meta.py    From django-silk with MIT License 5 votes vote down vote up
def _mock_response(self):
        response = NonCallableMock()
        response._headers = {}
        response.status_code = 200
        response.queries = []
        response.get = response._headers.get
        response.content = ''
        return response 
Example #10
Source File: test_api_call_decorator.py    From box-python-sdk with Apache License 2.0 5 votes vote down vote up
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')