googleapis / gapic-generator

Tools for generating API client libraries from API Service Configuration descriptions.
Apache License 2.0
304 stars 129 forks source link

Python unit test failure. #1211

Closed lukesneeringer closed 7 years ago

lukesneeringer commented 7 years ago

There are still 30 failures on the pubsub API with the newest toolkit changes:

A quick eyeball suggests most of them look like this:

TestSubscriberClient.test_update_subscription _____________________________

self = <test_subscriber_client.TestSubscriberClient testMethod=test_update_subscription>
mock_create_stub = <MagicMock name='create_stub' spec='function' id='140480702165792'>

    @mock.patch('google.gax.config.create_stub', spec=True)
    def test_update_subscription(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        subscription = pubsub_pb2.Subscription()
        update_mask = field_mask_pb2.FieldMask()

        # Mock response
        name = 'name3373707'
        topic = 'topic110546223'
        ack_deadline_seconds = 2135351438
        retain_acked_messages = False
        expected_response = pubsub_pb2.Subscription(
            name=name,
            topic=topic,
            ack_deadline_seconds=ack_deadline_seconds,
            retain_acked_messages=retain_acked_messages)
        grpc_stub.UpdateSubscription.return_value = expected_response

        response = client.update_subscription(subscription, update_mask)
        self.assertEqual(expected_response, response)

        grpc_stub.UpdateSubscription.assert_called_once()
        args, kwargs = grpc_stub.UpdateSubscription.call_args[0]
>       self.assertEqual(1, len(args))
E       TypeError: object of type 'UpdateSubscriptionRequest' has no len()

test/google/cloud/gapic/pubsub/v1/test_subscriber_client.py:170: TypeError

I think that this is because this line:

args, kwargs = grpc_stub.UpdateSubscription.call_args[0]

...is probably wrong. I think the [0] is errant there.

lukesneeringer commented 7 years ago

Confirmed:

(gapic-test) lukesneeringer@lukesneeringer0:~/Code/Google/artman/output/gapic-google-cloud-pubsub-v1:master$ python
Python 3.6.0 (default, Jan  5 2017, 10:44:51) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mock
>>> m = mock.Mock()
>>> m('foo', 'bar', baz='bacon', spam='eggs')
<Mock name='mock()' id='140706205734392'>
>>> m.call_args
call('foo', 'bar', baz='bacon', spam='eggs')
>>> m.call_args[0]
('foo', 'bar')
>>> m.call_args[1]
{'baz': 'bacon', 'spam': 'eggs'}
>>> args, kwargs = m.call_args
>>> args
('foo', 'bar')
>>> kwargs
{'baz': 'bacon', 'spam': 'eggs'}
lukesneeringer commented 7 years ago

Tagging #1207, which is related (it is the previous fix which turned out to be incorrect).