Skip to content

Local variable pagein unit test conflicts with API type page #576

@busunkim96

Description

@busunkim96

Dialogflow CX v3beta1

Dialogflow has a page type that causes two of the generated unit tests to fail because of a name conflict.

def test_list_pages_pages():
    client = PagesClient(credentials=credentials.AnonymousCredentials,)

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.list_pages), "__call__") as call:
        # Set the response to a series of pages.
        call.side_effect = (
            page.ListPagesResponse(  # page as a type
                pages=[page.Page(), page.Page(), page.Page(),], next_page_token="abc",
            ),
            page.ListPagesResponse(pages=[], next_page_token="def",),
            page.ListPagesResponse(pages=[page.Page(),], next_page_token="ghi",),
            page.ListPagesResponse(pages=[page.Page(), page.Page(),],),
            RuntimeError,
        )
        pages = list(client.list_pages(request={}).pages)
        for page, token in zip(pages, ["abc", "def", "ghi", ""]):  # page used as local var
            assert page.raw_page.next_page_token == token
@pytest.mark.asyncio
async def test_list_pages_async_pages():
    client = PagesAsyncClient(credentials=credentials.AnonymousCredentials,)

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
        type(client._client._transport.list_pages),
        "__call__",
        new_callable=mock.AsyncMock,
    ) as call:
        # Set the response to a series of pages.
        call.side_effect = (
            page.ListPagesResponse(
                pages=[page.Page(), page.Page(), page.Page(),], next_page_token="abc",
            ),
            page.ListPagesResponse(pages=[], next_page_token="def",),
            page.ListPagesResponse(pages=[page.Page(),], next_page_token="ghi",),
            page.ListPagesResponse(pages=[page.Page(), page.Page(),],),
            RuntimeError,
        )
        pages = []
        async for page in (await client.list_pages(request={})).pages:
            pages.append(page)
        for page, token in zip(pages, ["abc", "def", "ghi", ""]):
            assert page.raw_page.next_page_token == token
E           UnboundLocalError: local variable 'page' referenced before assignment

tests/unit/gapic/dialogflowcx_v3beta1/test_pages.py:622: UnboundLocalError

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions