From 0bef909f8c32f6cd56618a989f6b783379837b6d Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Mon, 2 Nov 2020 16:34:28 -0800 Subject: [PATCH 01/14] enable custom template path cli option --- openapi_python_client/__init__.py | 23 +++++++++++++++-------- openapi_python_client/cli.py | 6 ++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 2fcca23b3..7068acf46 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -9,7 +9,7 @@ import httpcore import httpx import yaml -from jinja2 import Environment, PackageLoader +from jinja2 import Environment, PackageLoader, ChoiceLoader, FileSystemLoader from openapi_python_client import utils @@ -30,8 +30,15 @@ class Project: project_name_override: Optional[str] = None package_name_override: Optional[str] = None - def __init__(self, *, openapi: GeneratorData) -> None: + def __init__(self, *, openapi: GeneratorData, custom_template_path: Optional[str] = None) -> None: self.openapi: GeneratorData = openapi + + package_loader = PackageLoader(__package__) + if custom_template_path is not None: + loader = ChoiceLoader([FileSystemLoader(custom_template_path), package_loader,]) + else: + loader = package_loader + self.env: Environment = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True) self.env: Environment = Environment(loader=PackageLoader(__package__), trim_blocks=True, lstrip_blocks=True) self.project_name: str = self.project_name_override or f"{utils.kebab_case(openapi.title).lower()}-client" @@ -191,37 +198,37 @@ def _build_api(self) -> None: module_path.write_text(endpoint_template.render(endpoint=endpoint)) -def _get_project_for_url_or_path(url: Optional[str], path: Optional[Path]) -> Union[Project, GeneratorError]: +def _get_project_for_url_or_path(url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None) -> Union[Project, GeneratorError]: data_dict = _get_document(url=url, path=path) if isinstance(data_dict, GeneratorError): return data_dict openapi = GeneratorData.from_dict(data_dict) if isinstance(openapi, GeneratorError): return openapi - return Project(openapi=openapi) + return Project(openapi=openapi, custom_template_path=custom_template_path) -def create_new_client(*, url: Optional[str], path: Optional[Path]) -> Sequence[GeneratorError]: +def create_new_client(*, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None) -> Sequence[GeneratorError]: """ Generate the client library Returns: A list containing any errors encountered when generating. """ - project = _get_project_for_url_or_path(url=url, path=path) + project = _get_project_for_url_or_path(url=url, path=path, custom_template_path=custom_template_path) if isinstance(project, GeneratorError): return [project] return project.build() -def update_existing_client(*, url: Optional[str], path: Optional[Path]) -> Sequence[GeneratorError]: +def update_existing_client(*, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None) -> Sequence[GeneratorError]: """ Update an existing client library Returns: A list containing any errors encountered when generating. """ - project = _get_project_for_url_or_path(url=url, path=path) + project = _get_project_for_url_or_path(url=url, path=path, custom_template_path=custom_template_path) if isinstance(project, GeneratorError): return [project] return project.update() diff --git a/openapi_python_client/cli.py b/openapi_python_client/cli.py index 9bfbe3366..f3796585b 100644 --- a/openapi_python_client/cli.py +++ b/openapi_python_client/cli.py @@ -100,6 +100,7 @@ def handle_errors(errors: Sequence[GeneratorError]) -> None: def generate( url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"), path: Optional[pathlib.Path] = typer.Option(None, help="A path to the JSON file"), + custom_template_path: Optional[str] = typer.Option(None, help="A path to a custom template directory"), ) -> None: """ Generate a new OpenAPI Client library """ from . import create_new_client @@ -110,7 +111,7 @@ def generate( if url and path: typer.secho("Provide either --url or --path, not both", fg=typer.colors.RED) raise typer.Exit(code=1) - errors = create_new_client(url=url, path=path) + errors = create_new_client(url=url, path=path, custom_template_path=custom_template_path) handle_errors(errors) @@ -118,6 +119,7 @@ def generate( def update( url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"), path: Optional[pathlib.Path] = typer.Option(None, help="A path to the JSON file"), + custom_template_path: Optional[str] = typer.Option(None, help="A path to a custom template directory"), ) -> None: """ Update an existing OpenAPI Client library """ from . import update_existing_client @@ -129,5 +131,5 @@ def update( typer.secho("Provide either --url or --path, not both", fg=typer.colors.RED) raise typer.Exit(code=1) - errors = update_existing_client(url=url, path=path) + errors = update_existing_client(url=url, path=path, custom_template_path=custom_template_path) handle_errors(errors) From bbef8b3c87c7bc381a40d4e0261a0394498e3e25 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Mon, 2 Nov 2020 16:35:05 -0800 Subject: [PATCH 02/14] reformat with black --- openapi_python_client/__init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 7068acf46..cbc8418e1 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -35,7 +35,12 @@ def __init__(self, *, openapi: GeneratorData, custom_template_path: Optional[str package_loader = PackageLoader(__package__) if custom_template_path is not None: - loader = ChoiceLoader([FileSystemLoader(custom_template_path), package_loader,]) + loader = ChoiceLoader( + [ + FileSystemLoader(custom_template_path), + package_loader, + ] + ) else: loader = package_loader self.env: Environment = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True) @@ -198,7 +203,9 @@ def _build_api(self) -> None: module_path.write_text(endpoint_template.render(endpoint=endpoint)) -def _get_project_for_url_or_path(url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None) -> Union[Project, GeneratorError]: +def _get_project_for_url_or_path( + url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None +) -> Union[Project, GeneratorError]: data_dict = _get_document(url=url, path=path) if isinstance(data_dict, GeneratorError): return data_dict @@ -208,7 +215,9 @@ def _get_project_for_url_or_path(url: Optional[str], path: Optional[Path], custo return Project(openapi=openapi, custom_template_path=custom_template_path) -def create_new_client(*, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None) -> Sequence[GeneratorError]: +def create_new_client( + *, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None +) -> Sequence[GeneratorError]: """ Generate the client library @@ -221,7 +230,9 @@ def create_new_client(*, url: Optional[str], path: Optional[Path], custom_templa return project.build() -def update_existing_client(*, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None) -> Sequence[GeneratorError]: +def update_existing_client( + *, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None +) -> Sequence[GeneratorError]: """ Update an existing client library From 5c1c95c6dd51ff092ceeafb5f94901e0b52fe426 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Mon, 2 Nov 2020 16:40:03 -0800 Subject: [PATCH 03/14] pass abs path for custom templates to fs loader --- openapi_python_client/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index cbc8418e1..77fa3c565 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -2,6 +2,7 @@ import shutil import subprocess +import os import sys from pathlib import Path from typing import Any, Dict, Optional, Sequence, Union @@ -37,7 +38,7 @@ def __init__(self, *, openapi: GeneratorData, custom_template_path: Optional[str if custom_template_path is not None: loader = ChoiceLoader( [ - FileSystemLoader(custom_template_path), + FileSystemLoader(os.path.abspath(custom_template_path)), package_loader, ] ) From 6b12c9c59f6f974fcd08b45a39392f98e9d5cf3a Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Mon, 2 Nov 2020 16:58:01 -0800 Subject: [PATCH 04/14] unit test custom templates path --- tests/test___init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test___init__.py b/tests/test___init__.py index d7970e054..82a7ab02e 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -416,3 +416,27 @@ def test__get_errors(mocker): project = Project(openapi=openapi) assert project._get_errors() == [1, 2, 3] + + +def test__custom_templates(mocker): + from openapi_python_client import GeneratorData, Project + from openapi_python_client.parser.openapi import EndpointCollection, Schemas + + openapi = mocker.MagicMock( + autospec=GeneratorData, + title="My Test API", + endpoint_collections_by_tag={ + "default": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[1]), + "other": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[2]), + }, + schemas=mocker.MagicMock(autospec=Schemas, errors=[3]), + ) + + project = Project(openapi=openapi) + assert isinstance(project.env.loader, jinja2.PackageLoader) + + project = Project(openapi=openapi, custom_template_path='../end_to_end_tests/test_custom_templates') + assert isinstance(project.env.loader, jinja2.ChoiceLoader) + assert len(project.env.loader.loaders) == 2 + assert isinstance(project.env.loader.loaders[0], jinja2.ChoiceLoader) + assert isinstance(project.env.loader.loaders[1], jinja2.PackageLoader) From 04a0db59d2c1eb4bc5caf20cdcbf044193feee3a Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Mon, 2 Nov 2020 17:36:06 -0800 Subject: [PATCH 05/14] delete redundant env declaration --- .gitignore | 2 +- .../golden-record-custom/.gitignore | 23 ++++ .../golden-record-custom/README.md | 61 +++++++++++ .../my_test_api_client/__init__.py | 1 + .../my_test_api_client/api/__init__.py | 1 + .../api/default/__init__.py | 0 .../api/default/ping_ping_get.py | 33 ++++++ .../my_test_api_client/api/tests/__init__.py | 0 .../api/tests/defaults_tests_defaults_post.py | 99 +++++++++++++++++ .../api/tests/get_basic_list_of_booleans.py | 33 ++++++ .../api/tests/get_basic_list_of_floats.py | 33 ++++++ .../api/tests/get_basic_list_of_integers.py | 33 ++++++ .../api/tests/get_basic_list_of_strings.py | 33 ++++++ .../api/tests/get_user_list.py | 62 +++++++++++ .../api/tests/int_enum_tests_int_enum_post.py | 48 +++++++++ .../tests/json_body_tests_json_body_post.py | 44 ++++++++ .../no_response_tests_no_response_get.py | 25 +++++ .../octet_stream_tests_octet_stream_get.py | 33 ++++++ ...d_content_tests_unsupported_content_get.py | 25 +++++ .../tests/upload_file_tests_upload_post.py | 57 ++++++++++ .../my_test_api_client/client.py | 46 ++++++++ .../my_test_api_client/models/__init__.py | 1 + .../my_test_api_client/models/a_model.py | 100 ++++++++++++++++++ .../my_test_api_client/models/an_enum.py | 6 ++ .../my_test_api_client/models/an_int_enum.py | 7 ++ .../body_upload_file_tests_upload_post.py | 27 +++++ .../models/different_enum.py | 6 ++ .../models/http_validation_error.py | 38 +++++++ .../models/validation_error.py | 38 +++++++ .../my_test_api_client/py.typed | 1 + .../my_test_api_client/types.py | 33 ++++++ .../golden-record-custom/pyproject.toml | 41 +++++++ end_to_end_tests/regen_golden_record.py | 20 +++- .../test_custom_templates/endpoint_module.pyi | 63 +++++++++++ end_to_end_tests/test_end_to_end.py | 26 +++++ openapi_python_client/__init__.py | 1 - 36 files changed, 1095 insertions(+), 5 deletions(-) create mode 100644 end_to_end_tests/golden-record-custom/.gitignore create mode 100644 end_to_end_tests/golden-record-custom/README.md create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/__init__.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/__init__.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/default/__init__.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/default/ping_ping_get.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/__init__.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/defaults_tests_defaults_post.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_booleans.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_floats.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_integers.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_strings.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_user_list.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/json_body_tests_json_body_post.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/no_response_tests_no_response_get.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/upload_file_tests_upload_post.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/client.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/__init__.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/a_model.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/an_enum.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/an_int_enum.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/body_upload_file_tests_upload_post.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/different_enum.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/http_validation_error.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/models/validation_error.py create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/py.typed create mode 100644 end_to_end_tests/golden-record-custom/my_test_api_client/types.py create mode 100644 end_to_end_tests/golden-record-custom/pyproject.toml create mode 100644 end_to_end_tests/test_custom_templates/endpoint_module.pyi diff --git a/.gitignore b/.gitignore index e1c52fb4c..5739d6fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ dmypy.json htmlcov/ # Generated end to end test data -my-test-api-client +tmp/my-test-api-client \ No newline at end of file diff --git a/end_to_end_tests/golden-record-custom/.gitignore b/end_to_end_tests/golden-record-custom/.gitignore new file mode 100644 index 000000000..ed29cb977 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/.gitignore @@ -0,0 +1,23 @@ +__pycache__/ +build/ +dist/ +*.egg-info/ +.pytest_cache/ + +# pyenv +.python-version + +# Environments +.env +.venv + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# JetBrains +.idea/ + +/coverage.xml +/.coverage \ No newline at end of file diff --git a/end_to_end_tests/golden-record-custom/README.md b/end_to_end_tests/golden-record-custom/README.md new file mode 100644 index 000000000..fbbe00c2f --- /dev/null +++ b/end_to_end_tests/golden-record-custom/README.md @@ -0,0 +1,61 @@ +# my-test-api-client +A client library for accessing My Test API + +## Usage +First, create a client: + +```python +from my_test_api_client import Client + +client = Client(base_url="https://api.example.com") +``` + +If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: + +```python +from my_test_api_client import AuthenticatedClient + +client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") +``` + +Now call your endpoint and use your models: + +```python +from my_test_api_client.models import MyDataModel +from my_test_api_client.api.my_tag import get_my_data_model + +my_data: MyDataModel = get_my_data_model(client=client) +``` + +Or do the same thing with an async version: + +```python +from my_test_api_client.models import MyDataModel +from my_test_api_client.async_api.my_tag import get_my_data_model + +my_data: MyDataModel = await get_my_data_model(client=client) +``` + +Things to know: +1. Every path/method combo becomes a Python function with type annotations. +1. All path/query params, and bodies become method arguments. +1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) +1. Any endpoint which did not have a tag will be in `my_test_api_client.api.default` +1. If the API returns a response code that was not declared in the OpenAPI document, a + `my_test_api_client.api.errors.ApiResponseError` wil be raised + with the `response` attribute set to the `httpx.Response` that was received. + + +## Building / publishing this Client +This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: +1. Update the metadata in pyproject.toml (e.g. authors, version) +1. If you're using a private repository, configure it with Poetry + 1. `poetry config repositories. ` + 1. `poetry config http-basic. ` +1. Publish the client with `poetry publish --build -r ` or, if for public PyPI, just `poetry publish --build` + +If you want to install this client into another project without publishing it (e.g. for development) then: +1. If that project **is using Poetry**, you can simply do `poetry add ` from that project +1. If that project is not using Poetry: + 1. Build a wheel with `poetry build -f wheel` + 1. Install that wheel from the other project `pip install ` \ No newline at end of file diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/__init__.py b/end_to_end_tests/golden-record-custom/my_test_api_client/__init__.py new file mode 100644 index 000000000..c8d0f1760 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/__init__.py @@ -0,0 +1 @@ +""" A client library for accessing My Test API """ diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/__init__.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/__init__.py new file mode 100644 index 000000000..dc035f4ce --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/__init__.py @@ -0,0 +1 @@ +""" Contains methods for accessing the API """ diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/default/__init__.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/default/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/default/ping_ping_get.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/default/ping_ping_get.py new file mode 100644 index 000000000..5e4cc9a2d --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/default/ping_ping_get.py @@ -0,0 +1,33 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + + +def _parse_response(*, response: httpx.Response) -> Optional[bool]: + if response.status_code == 200: + return bool(response.text) + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[bool]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[bool]: + + response = client.request( + "get", + "/ping", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/defaults_tests_defaults_post.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/defaults_tests_defaults_post.py new file mode 100644 index 000000000..84347423e --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -0,0 +1,99 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + +import datetime +from typing import Dict, List, Optional, Union, cast + +from dateutil.parser import isoparse + +from ...models.an_enum import AnEnum +from ...models.http_validation_error import HTTPValidationError + + +def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]: + if response.status_code == 200: + return None + if response.status_code == 422: + return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json())) + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[Union[None, HTTPValidationError]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, + json_body: Dict[Any, Any], + string_prop: Optional[str] = "the default string", + datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), + date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(), + float_prop: Optional[float] = 3.14, + int_prop: Optional[int] = 7, + boolean_prop: Optional[bool] = False, + list_prop: Optional[List[AnEnum]] = None, + union_prop: Optional[Union[Optional[float], Optional[str]]] = "not a float", + enum_prop: Optional[AnEnum] = None, +) -> httpx.Response[Union[None, HTTPValidationError]]: + + json_datetime_prop = datetime_prop.isoformat() if datetime_prop else None + + json_date_prop = date_prop.isoformat() if date_prop else None + + if list_prop is None: + json_list_prop = None + else: + json_list_prop = [] + for list_prop_item_data in list_prop: + list_prop_item = list_prop_item_data.value + + json_list_prop.append(list_prop_item) + + if union_prop is None: + json_union_prop: Optional[Union[Optional[float], Optional[str]]] = None + elif isinstance(union_prop, float): + json_union_prop = union_prop + else: + json_union_prop = union_prop + + json_enum_prop = enum_prop.value if enum_prop else None + + params: Dict[str, Any] = {} + if string_prop is not None: + params["string_prop"] = string_prop + if datetime_prop is not None: + params["datetime_prop"] = json_datetime_prop + if date_prop is not None: + params["date_prop"] = json_date_prop + if float_prop is not None: + params["float_prop"] = float_prop + if int_prop is not None: + params["int_prop"] = int_prop + if boolean_prop is not None: + params["boolean_prop"] = boolean_prop + if list_prop is not None: + params["list_prop"] = json_list_prop + if union_prop is not None: + params["union_prop"] = json_union_prop + if enum_prop is not None: + params["enum_prop"] = json_enum_prop + + json_json_body = json_body + + response = client.request( + "post", + "/tests/defaults", + json=json_json_body, + params=params, + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_booleans.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_booleans.py new file mode 100644 index 000000000..20d7c43ab --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_booleans.py @@ -0,0 +1,33 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + + +def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]: + if response.status_code == 200: + return [bool(item) for item in cast(List[bool], response.json())] + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[List[bool]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[List[bool]]: + + response = client.request( + "get", + "/tests/basic_lists/booleans", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_floats.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_floats.py new file mode 100644 index 000000000..e3fc2e4d4 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_floats.py @@ -0,0 +1,33 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + + +def _parse_response(*, response: httpx.Response) -> Optional[List[float]]: + if response.status_code == 200: + return [float(item) for item in cast(List[float], response.json())] + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[List[float]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[List[float]]: + + response = client.request( + "get", + "/tests/basic_lists/floats", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_integers.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_integers.py new file mode 100644 index 000000000..28ec4963c --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_integers.py @@ -0,0 +1,33 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + + +def _parse_response(*, response: httpx.Response) -> Optional[List[int]]: + if response.status_code == 200: + return [int(item) for item in cast(List[int], response.json())] + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[List[int]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[List[int]]: + + response = client.request( + "get", + "/tests/basic_lists/integers", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_strings.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_strings.py new file mode 100644 index 000000000..1acdf6a40 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_basic_list_of_strings.py @@ -0,0 +1,33 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + + +def _parse_response(*, response: httpx.Response) -> Optional[List[str]]: + if response.status_code == 200: + return [str(item) for item in cast(List[str], response.json())] + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[List[str]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[List[str]]: + + response = client.request( + "get", + "/tests/basic_lists/strings", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_user_list.py new file mode 100644 index 000000000..d3a8591bc --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/get_user_list.py @@ -0,0 +1,62 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + +import datetime +from typing import Dict, List, Union, cast + +from ...models.a_model import AModel +from ...models.an_enum import AnEnum +from ...models.http_validation_error import HTTPValidationError + + +def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel], HTTPValidationError]]: + if response.status_code == 200: + return [AModel.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())] + if response.status_code == 422: + return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json())) + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[Union[List[AModel], HTTPValidationError]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, + an_enum_value: List[AnEnum], + some_date: Union[datetime.date, datetime.datetime], +) -> httpx.Response[Union[List[AModel], HTTPValidationError]]: + + json_an_enum_value = [] + for an_enum_value_item_data in an_enum_value: + an_enum_value_item = an_enum_value_item_data.value + + json_an_enum_value.append(an_enum_value_item) + + if isinstance(some_date, datetime.date): + json_some_date = some_date.isoformat() + + else: + json_some_date = some_date.isoformat() + + params: Dict[str, Any] = { + "an_enum_value": json_an_enum_value, + "some_date": json_some_date, + } + + response = client.request( + "get", + "/tests/", + params=params, + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py new file mode 100644 index 000000000..068e6e9c7 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -0,0 +1,48 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + +from typing import Dict, cast + +from ...models.an_int_enum import AnIntEnum +from ...models.http_validation_error import HTTPValidationError + + +def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]: + if response.status_code == 200: + return None + if response.status_code == 422: + return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json())) + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[Union[None, HTTPValidationError]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, + int_enum: AnIntEnum, +) -> httpx.Response[Union[None, HTTPValidationError]]: + + json_int_enum = int_enum.value + + params: Dict[str, Any] = { + "int_enum": json_int_enum, + } + + response = client.request( + "post", + "/tests/int_enum", + params=params, + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/json_body_tests_json_body_post.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/json_body_tests_json_body_post.py new file mode 100644 index 000000000..76f4ffe84 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -0,0 +1,44 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + +from typing import Dict, cast + +from ...models.a_model import AModel +from ...models.http_validation_error import HTTPValidationError + + +def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]: + if response.status_code == 200: + return None + if response.status_code == 422: + return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json())) + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[Union[None, HTTPValidationError]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, + json_body: AModel, +) -> httpx.Response[Union[None, HTTPValidationError]]: + + json_json_body = json_body.to_dict() + + response = client.request( + "post", + "/tests/json_body", + json=json_json_body, + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/no_response_tests_no_response_get.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/no_response_tests_no_response_get.py new file mode 100644 index 000000000..4f4d89cbd --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/no_response_tests_no_response_get.py @@ -0,0 +1,25 @@ +import httpx + +Client = httpx.Client + + +def _build_response(*, response: httpx.Response) -> httpx.Response[None]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=None, + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[None]: + + response = client.request( + "get", + "/tests/no_response", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py new file mode 100644 index 000000000..8f1b83adb --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py @@ -0,0 +1,33 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + + +def _parse_response(*, response: httpx.Response) -> Optional[bytes]: + if response.status_code == 200: + return bytes(response.content) + return None + + +def _build_response(*, response: httpx.Response) -> httpx.Response[bytes]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[bytes]: + + response = client.request( + "get", + "/tests/octet_stream", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py new file mode 100644 index 000000000..c1019e884 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py @@ -0,0 +1,25 @@ +import httpx + +Client = httpx.Client + + +def _build_response(*, response: httpx.Response) -> httpx.Response[None]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=None, + ) + + +def httpx_request( + *, + client: Client, +) -> httpx.Response[None]: + + response = client.request( + "get", + "/tests/unsupported_content", + ) + + return _build_response(response=response) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/upload_file_tests_upload_post.py b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/upload_file_tests_upload_post.py new file mode 100644 index 000000000..1ef04185b --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -0,0 +1,57 @@ +from typing import Optional + +import httpx + +Client = httpx.Client + +from typing import Optional + +from ...models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost +from ...models.http_validation_error import HTTPValidationError + + +def _parse_response(*, response: httpx.Response) -> Optional[Union[ + None, + HTTPValidationError +]]: + if response.status_code == 200: + return None + if response.status_code == 422: + return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json())) + return None + + + +def _build_response(*, response: httpx.Response) -> httpx.Response[Union[ + None, + HTTPValidationError +]]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + parsed=_parse_response(response=response), + ) + + +def httpx_request(*, + client: Client, + multipart_data: BodyUploadFileTestsUploadPost, + keep_alive: Optional[bool] = None, +) -> httpx.Response[Union[ + None, + HTTPValidationError +]]: + if keep_alive is not None: + headers["keep-alive"] = keep_alive + + + + + response = client.request( + "post", + "/tests/upload", + "files": multipart_data.to_dict(), + ) + + return _build_response(response=response) \ No newline at end of file diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/client.py b/end_to_end_tests/golden-record-custom/my_test_api_client/client.py new file mode 100644 index 000000000..c3074040c --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/client.py @@ -0,0 +1,46 @@ +from typing import Dict + +import attr + + +@attr.s(auto_attribs=True) +class Client: + """ A class for keeping track of data related to the API """ + + base_url: str + cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True) + headers: Dict[str, str] = attr.ib(factory=dict, kw_only=True) + timeout: float = attr.ib(5.0, kw_only=True) + + def get_headers(self) -> Dict[str, str]: + """ Get headers to be used in all endpoints """ + return {**self.headers} + + def with_headers(self, headers: Dict[str, str]) -> "Client": + """ Get a new client matching this one with additional headers """ + return attr.evolve(self, headers={**self.headers, **headers}) + + def get_cookies(self) -> Dict[str, str]: + return {**self.cookies} + + def with_cookies(self, cookies: Dict[str, str]) -> "Client": + """ Get a new client matching this one with additional cookies """ + return attr.evolve(self, cookies={**self.cookies, **cookies}) + + def get_timeout(self) -> float: + return self.timeout + + def with_timeout(self, timeout: float) -> "Client": + """ Get a new client matching this one with a new timeout (in seconds) """ + return attr.evolve(self, timeout=timeout) + + +@attr.s(auto_attribs=True) +class AuthenticatedClient(Client): + """ A Client which has been authenticated for use on secured endpoints """ + + token: str + + def get_headers(self) -> Dict[str, str]: + """ Get headers to be used in authenticated endpoints """ + return {"Authorization": f"Bearer {self.token}", **self.headers} diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/__init__.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/__init__.py new file mode 100644 index 000000000..9f38702e3 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/__init__.py @@ -0,0 +1 @@ +""" Contains all the data models used in inputs/outputs """ diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/a_model.py new file mode 100644 index 000000000..a1a0ace0c --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/a_model.py @@ -0,0 +1,100 @@ +import datetime +from typing import Any, Dict, List, Optional, Union + +import attr +from dateutil.parser import isoparse + +from ..models.an_enum import AnEnum +from ..models.different_enum import DifferentEnum + + +@attr.s(auto_attribs=True) +class AModel: + """ A Model for testing all the ways custom objects can be used """ + + an_enum_value: AnEnum + some_dict: Optional[Dict[Any, Any]] + a_camel_date_time: Union[datetime.datetime, datetime.date] + a_date: datetime.date + nested_list_of_enums: Optional[List[List[DifferentEnum]]] = None + attr_1_leading_digit: Optional[str] = None + + def to_dict(self) -> Dict[str, Any]: + an_enum_value = self.an_enum_value.value + + some_dict = self.some_dict + + if isinstance(self.a_camel_date_time, datetime.datetime): + a_camel_date_time = self.a_camel_date_time.isoformat() + + else: + a_camel_date_time = self.a_camel_date_time.isoformat() + + a_date = self.a_date.isoformat() + + if self.nested_list_of_enums is None: + nested_list_of_enums = None + else: + nested_list_of_enums = [] + for nested_list_of_enums_item_data in self.nested_list_of_enums: + nested_list_of_enums_item = [] + for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data: + nested_list_of_enums_item_item = nested_list_of_enums_item_item_data.value + + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + attr_1_leading_digit = self.attr_1_leading_digit + + return { + "an_enum_value": an_enum_value, + "some_dict": some_dict, + "aCamelDateTime": a_camel_date_time, + "a_date": a_date, + "nested_list_of_enums": nested_list_of_enums, + "1_leading_digit": attr_1_leading_digit, + } + + @staticmethod + def from_dict(d: Dict[str, Any]) -> "AModel": + an_enum_value = AnEnum(d["an_enum_value"]) + + some_dict = d["some_dict"] + + def _parse_a_camel_date_time(data: Dict[str, Any]) -> Union[datetime.datetime, datetime.date]: + a_camel_date_time: Union[datetime.datetime, datetime.date] + try: + a_camel_date_time = isoparse(d["aCamelDateTime"]) + + return a_camel_date_time + except: # noqa: E722 + pass + a_camel_date_time = isoparse(d["aCamelDateTime"]).date() + + return a_camel_date_time + + a_camel_date_time = _parse_a_camel_date_time(d["aCamelDateTime"]) + + a_date = isoparse(d["a_date"]).date() + + nested_list_of_enums = [] + for nested_list_of_enums_item_data in d.get("nested_list_of_enums") or []: + nested_list_of_enums_item = [] + for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data: + nested_list_of_enums_item_item = DifferentEnum(nested_list_of_enums_item_item_data) + + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + attr_1_leading_digit = d.get("1_leading_digit") + + return AModel( + an_enum_value=an_enum_value, + some_dict=some_dict, + a_camel_date_time=a_camel_date_time, + a_date=a_date, + nested_list_of_enums=nested_list_of_enums, + attr_1_leading_digit=attr_1_leading_digit, + ) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/an_enum.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/an_enum.py new file mode 100644 index 000000000..9616ca82e --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/an_enum.py @@ -0,0 +1,6 @@ +from enum import Enum + + +class AnEnum(str, Enum): + FIRST_VALUE = "FIRST_VALUE" + SECOND_VALUE = "SECOND_VALUE" diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/an_int_enum.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/an_int_enum.py new file mode 100644 index 000000000..6048add0f --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/an_int_enum.py @@ -0,0 +1,7 @@ +from enum import IntEnum + + +class AnIntEnum(IntEnum): + VALUE_NEGATIVE_1 = -1 + VALUE_1 = 1 + VALUE_2 = 2 diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/body_upload_file_tests_upload_post.py new file mode 100644 index 000000000..4fe7f8476 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/body_upload_file_tests_upload_post.py @@ -0,0 +1,27 @@ +from typing import Any, Dict + +import attr + +from ..types import File + + +@attr.s(auto_attribs=True) +class BodyUploadFileTestsUploadPost: + """ """ + + some_file: File + + def to_dict(self) -> Dict[str, Any]: + some_file = self.some_file.to_tuple() + + return { + "some_file": some_file, + } + + @staticmethod + def from_dict(d: Dict[str, Any]) -> "BodyUploadFileTestsUploadPost": + some_file = d["some_file"] + + return BodyUploadFileTestsUploadPost( + some_file=some_file, + ) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/different_enum.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/different_enum.py new file mode 100644 index 000000000..00357ab7a --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/different_enum.py @@ -0,0 +1,6 @@ +from enum import Enum + + +class DifferentEnum(str, Enum): + DIFFERENT = "DIFFERENT" + OTHER = "OTHER" diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/http_validation_error.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/http_validation_error.py new file mode 100644 index 000000000..90cd71e8c --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/http_validation_error.py @@ -0,0 +1,38 @@ +from typing import Any, Dict, List, Optional + +import attr + +from ..models.validation_error import ValidationError + + +@attr.s(auto_attribs=True) +class HTTPValidationError: + """ """ + + detail: Optional[List[ValidationError]] = None + + def to_dict(self) -> Dict[str, Any]: + if self.detail is None: + detail = None + else: + detail = [] + for detail_item_data in self.detail: + detail_item = detail_item_data.to_dict() + + detail.append(detail_item) + + return { + "detail": detail, + } + + @staticmethod + def from_dict(d: Dict[str, Any]) -> "HTTPValidationError": + detail = [] + for detail_item_data in d.get("detail") or []: + detail_item = ValidationError.from_dict(detail_item_data) + + detail.append(detail_item) + + return HTTPValidationError( + detail=detail, + ) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/models/validation_error.py b/end_to_end_tests/golden-record-custom/my_test_api_client/models/validation_error.py new file mode 100644 index 000000000..1e415c476 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/models/validation_error.py @@ -0,0 +1,38 @@ +from typing import Any, Dict, List + +import attr + + +@attr.s(auto_attribs=True) +class ValidationError: + """ """ + + loc: List[str] + msg: str + type: str + + def to_dict(self) -> Dict[str, Any]: + loc = self.loc + + msg = self.msg + type = self.type + + return { + "loc": loc, + "msg": msg, + "type": type, + } + + @staticmethod + def from_dict(d: Dict[str, Any]) -> "ValidationError": + loc = d["loc"] + + msg = d["msg"] + + type = d["type"] + + return ValidationError( + loc=loc, + msg=msg, + type=type, + ) diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/py.typed b/end_to_end_tests/golden-record-custom/my_test_api_client/py.typed new file mode 100644 index 000000000..1aad32711 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/end_to_end_tests/golden-record-custom/my_test_api_client/types.py b/end_to_end_tests/golden-record-custom/my_test_api_client/types.py new file mode 100644 index 000000000..951227435 --- /dev/null +++ b/end_to_end_tests/golden-record-custom/my_test_api_client/types.py @@ -0,0 +1,33 @@ +""" Contains some shared types for properties """ +from typing import BinaryIO, Generic, MutableMapping, Optional, TextIO, Tuple, TypeVar, Union + +import attr + + +@attr.s(auto_attribs=True) +class File: + """ Contains information for file uploads """ + + payload: Union[BinaryIO, TextIO] + file_name: Optional[str] = None + mime_type: Optional[str] = None + + def to_tuple(self) -> Tuple[Optional[str], Union[BinaryIO, TextIO], Optional[str]]: + """ Return a tuple representation that httpx will accept for multipart/form-data """ + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@attr.s(auto_attribs=True) +class Response(Generic[T]): + """ A response from an endpoint """ + + status_code: int + content: bytes + headers: MutableMapping[str, str] + parsed: Optional[T] + + +__all__ = ["File", "Response"] diff --git a/end_to_end_tests/golden-record-custom/pyproject.toml b/end_to_end_tests/golden-record-custom/pyproject.toml new file mode 100644 index 000000000..eeb1a9e4e --- /dev/null +++ b/end_to_end_tests/golden-record-custom/pyproject.toml @@ -0,0 +1,41 @@ +[tool.poetry] +name = "my-test-api-client" +version = "0.1.0" +description = "A client library for accessing My Test API" + +authors = [] + +readme = "README.md" +packages = [ + {include = "my_test_api_client"}, +] +include = ["CHANGELOG.md", "my_test_api_client/py.typed"] + + +[tool.poetry.dependencies] +python = "^3.8" +httpx = "^0.15.0" +attrs = "^20.1.0" +python-dateutil = "^2.8.1" + +[tool.black] +line-length = 120 +target_version = ['py38'] +exclude = ''' +( + /( + | \.git + | \.venv + | \.mypy_cache + )/ +) +''' + +[tool.isort] +line_length = 120 +multi_line_output = 3 +include_trailing_comma = true + +[build-system] +requires = ["poetry>=1.0"] +build-backend = "poetry.masonry.api" \ No newline at end of file diff --git a/end_to_end_tests/regen_golden_record.py b/end_to_end_tests/regen_golden_record.py index 4fe06cb7b..aa664a781 100644 --- a/end_to_end_tests/regen_golden_record.py +++ b/end_to_end_tests/regen_golden_record.py @@ -1,5 +1,6 @@ """ Regenerate golden-record """ import shutil +import sys from pathlib import Path from typer.testing import CliRunner @@ -9,13 +10,26 @@ if __name__ == "__main__": runner = CliRunner() openapi_path = Path(__file__).parent / "openapi.json" - gr_path = Path(__file__).parent / "golden-record" - shutil.rmtree(gr_path, ignore_errors=True) + output_path = Path.cwd() / "my-test-api-client" + if sys.argv[1] == 'custom': + gr_path = Path(__file__).parent / "golden-record-custom" + else: + gr_path = Path(__file__).parent / "golden-record" + + shutil.rmtree(gr_path, ignore_errors=True) shutil.rmtree(output_path, ignore_errors=True) config_path = Path(__file__).parent / "config.yml" - result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={openapi_path}"]) + if sys.argv[1] == 'custom': + result = runner.invoke(app, [ + f"--config={config_path}", + "generate", + f"--path={openapi_path}", + "--custom-template-path=end_to_end_tests/test_custom_templates"]) + else: + result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={openapi_path}"]) + if result.stdout: print(result.stdout) if result.exception: diff --git a/end_to_end_tests/test_custom_templates/endpoint_module.pyi b/end_to_end_tests/test_custom_templates/endpoint_module.pyi new file mode 100644 index 000000000..a00c442de --- /dev/null +++ b/end_to_end_tests/test_custom_templates/endpoint_module.pyi @@ -0,0 +1,63 @@ +import httpx +from typing import Optional + + +Client = httpx.Client + +{% for relative in endpoint.relative_imports %} +{{ relative }} +{% endfor %} + +{% from "endpoint_macros.pyi" import header_params, query_params, json_body, return_type, arguments, client, kwargs, parse_response %} + +{% set return_string = return_type(endpoint) %} +{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "None" %} + + +{% if parsed_responses %} +def _parse_response(*, response: httpx.Response) -> Optional[{{ return_string }}]: + {% for response in endpoint.responses %} + if response.status_code == {{ response.status_code }}: + return {{ response.constructor() }} + {% endfor %} + return None +{% endif %} + + + +def _build_response(*, response: httpx.Response) -> httpx.Response[{{ return_string }}]: + return httpx.Response( + status_code=response.status_code, + content=response.content, + headers=response.headers, + {% if parsed_responses %} + parsed=_parse_response(response=response), + {% else %} + parsed=None, + {% endif %} + ) + + +def httpx_request({{ arguments(endpoint) | indent(4) }}) -> httpx.Response[{{ return_string }}]: + {{ header_params(endpoint) | indent(4) }} + {{ query_params(endpoint) | indent(4) }} + {{ json_body(endpoint) | indent(4) }} + + response = client.request( + "{{ endpoint.method }}", + "{{ endpoint.path }}", + {% if endpoint.json_body %} + json={{ "json_" + endpoint.json_body.python_name }}, + {% endif %} + {% if endpoint.query_parameters %} + params=params, + {% endif %} + {% if endpoint.form_body_reference %} + "data": asdict(form_data), + {% endif %} + {% if endpoint.multipart_body_reference %} + "files": multipart_data.to_dict(), + {% endif %} + ) + + return _build_response(response=response) \ No newline at end of file diff --git a/end_to_end_tests/test_end_to_end.py b/end_to_end_tests/test_end_to_end.py index 51e895a7b..aead25371 100644 --- a/end_to_end_tests/test_end_to_end.py +++ b/end_to_end_tests/test_end_to_end.py @@ -47,3 +47,29 @@ def test_end_to_end(): assert status == 0, f"Type checking client failed: {out}" shutil.rmtree(output_path) + + +def test_end_to_end_w_custom_templates(): + runner = CliRunner() + openapi_path = Path(__file__).parent / "openapi.json" + config_path = Path(__file__).parent / "config.yml" + gr_path = Path(__file__).parent / "golden-record-custom" + output_path = Path.cwd() / "my-test-api-client-custom" + shutil.rmtree(output_path, ignore_errors=True) + + result = runner.invoke(app, [ + f"--config={config_path}", + "generate", + f"--path={openapi_path}", + "--custom-template-path=end_to_end_tests/test_custom_templates"]) + + if result.exit_code != 0: + raise result.exception + _compare_directories(gr_path, output_path) + + import mypy.api + + out, err, status = mypy.api.run([str(output_path), "--strict"]) + assert status == 0, f"Type checking client failed: {out}" + + shutil.rmtree(output_path) diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 77fa3c565..4905a9084 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -45,7 +45,6 @@ def __init__(self, *, openapi: GeneratorData, custom_template_path: Optional[str else: loader = package_loader self.env: Environment = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True) - self.env: Environment = Environment(loader=PackageLoader(__package__), trim_blocks=True, lstrip_blocks=True) self.project_name: str = self.project_name_override or f"{utils.kebab_case(openapi.title).lower()}-client" self.project_dir: Path = Path.cwd() / self.project_name From eb697d47958abad9fdb97445b489bf74b8debd6b Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 09:05:40 -0800 Subject: [PATCH 06/14] update unit test call assertions --- test-reports/pytest/results.xml | 1658 +++++++++++++++++++++++++++++++ tests/test___init__.py | 12 +- tests/test_cli.py | 10 +- 3 files changed, 1669 insertions(+), 11 deletions(-) create mode 100644 test-reports/pytest/results.xml diff --git a/test-reports/pytest/results.xml b/test-reports/pytest/results.xml new file mode 100644 index 000000000..03ed21f60 --- /dev/null +++ b/test-reports/pytest/results.xml @@ -0,0 +1,1658 @@ +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='Project' id='4564528656'>,) +kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True +msg = "Expected call: Project(openapi=<MagicMock id='4564476176'>)\nActual call: Project(custom_template_path=None, openapi=... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='Project' id='4564528656'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'openapi': <MagicMock id='4564476176'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>}\n Omitting 1 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='Project' id='4564528656'>, args = (), kwargs = {'openapi': <MagicMock id='4564476176'>}, expected = ((), {'openapi': <MagicMock id='4564476176'>}) +_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1101dfd40>, actual = call(custom_template_path=None, openapi=<MagicMock id='4564476176'>) +cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: Project(openapi=<MagicMock id='4564476176'>) +E Actual call: Project(custom_template_path=None, openapi=<MagicMock id='4564476176'>) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='Project' id='4564528656'>,) +kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True +msg = "Expected call: Project(openapi=<MagicMock id='4564476176'>)\nActual call: Project(custom_template_path=None, openapi=... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='Project' id='4564528656'>, args = (), kwargs = {'openapi': <MagicMock id='4564476176'>}, self = <MagicMock name='Project' id='4564528656'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='Project' id='4564528656'>,), kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='Project' id='4564528656'>,) +kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True +msg = "Expected call: Project(openapi=<MagicMock id='4564476176'>)\nActual call: Project(custom_template_path=None, openapi=... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='Project' id='4564528656'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'openapi': <MagicMock id='4564476176'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>}\n Omitting 1 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: Project(openapi=<MagicMock id='4564476176'>) +E Actual call: Project(custom_template_path=None, openapi=<MagicMock id='4564476176'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>} +E Omitting 1 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +mocker = <pytest_mock.plugin.MockerFixture object at 0x11016b690> + + def test__get_project_for_url_or_path(mocker): + data_dict = mocker.MagicMock() + _get_document = mocker.patch("openapi_python_client._get_document", return_value=data_dict) + openapi = mocker.MagicMock() + from_dict = mocker.patch("openapi_python_client.parser.GeneratorData.from_dict", return_value=openapi) + _Project = mocker.patch("openapi_python_client.Project") + url = mocker.MagicMock() + path = mocker.MagicMock() + + from openapi_python_client import _get_project_for_url_or_path + + project = _get_project_for_url_or_path(url=url, path=path) + + _get_document.assert_called_once_with(url=url, path=path) + from_dict.assert_called_once_with(data_dict) +> _Project.assert_called_once_with(openapi=openapi) +E AssertionError: Expected call: Project(openapi=<MagicMock id='4564476176'>) +E Actual call: Project(custom_template_path=None, openapi=<MagicMock id='4564476176'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>} +E Omitting 1 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test___init__.py:26: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,) +kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, args = (), kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} +expected = ((), {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}) +_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1101230e0> +actual = call(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,) +kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, args = (), kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} +self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,), kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,) +kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +mocker = <pytest_mock.plugin.MockerFixture object at 0x1103b0990> + + def test_create_new_client(mocker): + project = mocker.MagicMock() + _get_project_for_url_or_path = mocker.patch( + "openapi_python_client._get_project_for_url_or_path", return_value=project + ) + url = mocker.MagicMock() + path = mocker.MagicMock() + + from openapi_python_client import create_new_client + + result = create_new_client(url=url, path=path) + +> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test___init__.py:78: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,) +kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, args = (), kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} +expected = ((), {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}) +_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11031c050> +actual = call(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,) +kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, args = (), kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} +self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,), kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,) +kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +mocker = <pytest_mock.plugin.MockerFixture object at 0x110066310> + + def test_create_new_client_project_error(mocker): + error = GeneratorError() + _get_project_for_url_or_path = mocker.patch( + "openapi_python_client._get_project_for_url_or_path", return_value=error + ) + url = mocker.MagicMock() + path = mocker.MagicMock() + + from openapi_python_client import create_new_client + + result = create_new_client(url=url, path=path) + +> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test___init__.py:95: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,) +kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, args = (), kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} +expected = ((), {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}) +_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11031cd40> +actual = call(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,) +kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, args = (), kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} +self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,), kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,) +kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +mocker = <pytest_mock.plugin.MockerFixture object at 0x11014e8d0> + + def test_update_existing_client(mocker): + project = mocker.MagicMock() + _get_project_for_url_or_path = mocker.patch( + "openapi_python_client._get_project_for_url_or_path", return_value=project + ) + url = mocker.MagicMock() + path = mocker.MagicMock() + + from openapi_python_client import update_existing_client + + result = update_existing_client(url=url, path=path) + +> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test___init__.py:111: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,) +kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, args = (), kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} +expected = ((), {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}) +_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1101df8c0> +actual = call(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,) +kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, args = (), kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} +self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,), kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,) +kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True +msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, actual_args = () +actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} +introspection = "\nKwargs:\nassert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +mocker = <pytest_mock.plugin.MockerFixture object at 0x110240ed0> + + def test_update_existing_client_project_error(mocker): + error = GeneratorError() + _get_project_for_url_or_path = mocker.patch( + "openapi_python_client._get_project_for_url_or_path", return_value=error + ) + url = mocker.MagicMock() + path = mocker.MagicMock() + + from openapi_python_client import update_existing_client + + result = update_existing_client(url=url, path=path) + +> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) +E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) +E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test___init__.py:128: AssertionErrormocker = <pytest_mock.plugin.MockerFixture object at 0x11013dd50> + + def test__custom_templates(mocker): + from openapi_python_client import GeneratorData, Project + from openapi_python_client.parser.openapi import EndpointCollection, Schemas + + openapi = mocker.MagicMock( + autospec=GeneratorData, + title="My Test API", + endpoint_collections_by_tag={ + "default": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[1]), + "other": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[2]), + }, + schemas=mocker.MagicMock(autospec=Schemas, errors=[3]), + ) + + project = Project(openapi=openapi) + assert isinstance(project.env.loader, jinja2.PackageLoader) + + project = Project(openapi=openapi, custom_template_path='../end_to_end_tests/test_custom_templates') + assert isinstance(project.env.loader, jinja2.ChoiceLoader) + assert len(project.env.loader.loaders) == 2 +> assert isinstance(project.env.loader.loaders[0], jinja2.ChoiceLoader) +E AssertionError: assert False +E + where False = isinstance(<jinja2.loaders.FileSystemLoader object at 0x1101d3a50>, <class 'jinja2.loaders.ChoiceLoader'>) +E + where <class 'jinja2.loaders.ChoiceLoader'> = jinja2.ChoiceLoader + +tests/test___init__.py:441: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4569005456'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='create_new_client' id='4569005456'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} +introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='create_new_client' id='4569005456'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} +expected = ((), {'path': PosixPath('cool/path'), 'url': None}), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11031c440> +actual = call(custom_template_path=None, path=PosixPath('cool/path'), url=None), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) +E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='create_new_client' id='4569005456'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='create_new_client' id='4569005456'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} +self = <MagicMock name='create_new_client' id='4569005456'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='create_new_client' id='4569005456'>,), kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4569005456'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='create_new_client' id='4569005456'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} +introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) +E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +mocker = <pytest_mock.plugin.MockerFixture object at 0x110557ed0>, _create_new_client = <MagicMock name='create_new_client' id='4569005456'> + + def test_config_arg(mocker, _create_new_client): + load_config = mocker.patch("openapi_python_client.config.Config.load_from_path") + from openapi_python_client.cli import app + + config_path = "config/path" + path = "cool/path" + + result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={path}"], catch_exceptions=False) + + assert result.exit_code == 0 + load_config.assert_called_once_with(path=Path(config_path)) +> _create_new_client.assert_called_once_with(url=None, path=Path(path)) +E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) +E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test_cli.py:39: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4564703568'>,) +kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=None, url='cool.url')\nActual call: create_new_client(custom_template_path=None... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='create_new_client' id='4564703568'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} +introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='create_new_client' id='4564703568'>, args = (), kwargs = {'path': None, 'url': 'cool.url'}, expected = ((), {'path': None, 'url': 'cool.url'}) +_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1103e79e0>, actual = call(custom_template_path=None, path=None, url='cool.url'), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: create_new_client(path=None, url='cool.url') +E Actual call: create_new_client(custom_template_path=None, path=None, url='cool.url') + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='create_new_client' id='4564703568'>,) +kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=None, url='cool.url')\nActual call: create_new_client(custom_template_path=None... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='create_new_client' id='4564703568'>, args = (), kwargs = {'path': None, 'url': 'cool.url'}, self = <MagicMock name='create_new_client' id='4564703568'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='create_new_client' id='4564703568'>,), kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4564703568'>,) +kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=None, url='cool.url')\nActual call: create_new_client(custom_template_path=None... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='create_new_client' id='4564703568'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} +introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: create_new_client(path=None, url='cool.url') +E Actual call: create_new_client(custom_template_path=None, path=None, url='cool.url') +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +self = <tests.test_cli.TestGenerate object at 0x1100e0cd0>, _create_new_client = <MagicMock name='create_new_client' id='4564703568'> + + def test_generate_url(self, _create_new_client): + url = "cool.url" + from openapi_python_client.cli import app + + result = runner.invoke(app, ["generate", f"--url={url}"]) + + assert result.exit_code == 0 +> _create_new_client.assert_called_once_with(url=url, path=None) +E AssertionError: Expected call: create_new_client(path=None, url='cool.url') +E Actual call: create_new_client(custom_template_path=None, path=None, url='cool.url') +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test_cli.py:83: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4567271312'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='create_new_client' id='4567271312'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} +introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='create_new_client' id='4567271312'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} +expected = ((), {'path': PosixPath('cool/path'), 'url': None}), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1103e7d40> +actual = call(custom_template_path=None, path=PosixPath('cool/path'), url=None), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) +E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='create_new_client' id='4567271312'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='create_new_client' id='4567271312'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} +self = <MagicMock name='create_new_client' id='4567271312'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='create_new_client' id='4567271312'>,), kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4567271312'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='create_new_client' id='4567271312'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} +introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) +E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +self = <tests.test_cli.TestGenerate object at 0x1103b06d0>, _create_new_client = <MagicMock name='create_new_client' id='4567271312'> + + def test_generate_path(self, _create_new_client): + path = "cool/path" + from openapi_python_client.cli import app + + result = runner.invoke(app, ["generate", f"--path={path}"]) + + assert result.exit_code == 0 +> _create_new_client.assert_called_once_with(url=None, path=Path(path)) +E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) +E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test_cli.py:92: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4564173584'>,) +kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True +msg = "Expected call: update_existing_client(path=None, url='cool.url')\nActual call: update_existing_client(custom_template... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='update_existing_client' id='4564173584'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} +introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='update_existing_client' id='4564173584'>, args = (), kwargs = {'path': None, 'url': 'cool.url'}, expected = ((), {'path': None, 'url': 'cool.url'}) +_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11048fd40>, actual = call(custom_template_path=None, path=None, url='cool.url'), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: update_existing_client(path=None, url='cool.url') +E Actual call: update_existing_client(custom_template_path=None, path=None, url='cool.url') + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='update_existing_client' id='4564173584'>,) +kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True +msg = "Expected call: update_existing_client(path=None, url='cool.url')\nActual call: update_existing_client(custom_template... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='update_existing_client' id='4564173584'>, args = (), kwargs = {'path': None, 'url': 'cool.url'} +self = <MagicMock name='update_existing_client' id='4564173584'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='update_existing_client' id='4564173584'>,), kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4564173584'>,) +kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True +msg = "Expected call: update_existing_client(path=None, url='cool.url')\nActual call: update_existing_client(custom_template... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='update_existing_client' id='4564173584'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} +introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: update_existing_client(path=None, url='cool.url') +E Actual call: update_existing_client(custom_template_path=None, path=None, url='cool.url') +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +self = <tests.test_cli.TestUpdate object at 0x1100bc2d0>, _update_existing_client = <MagicMock name='update_existing_client' id='4564173584'> + + def test_update_url(self, _update_existing_client): + url = "cool.url" + from openapi_python_client.cli import app + + result = runner.invoke(app, ["update", f"--url={url}"]) + + assert result.exit_code == 0 +> _update_existing_client.assert_called_once_with(url=url, path=None) +E AssertionError: Expected call: update_existing_client(path=None, url='cool.url') +E Actual call: update_existing_client(custom_template_path=None, path=None, url='cool.url') +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test_cli.py:162: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4565442512'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: update_existing_client(path=PosixPath('cool/path'), url=None)\nActual call: update_existing_client(cus... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='update_existing_client' id='4565442512'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} +introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='update_existing_client' id='4565442512'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} +expected = ((), {'path': PosixPath('cool/path'), 'url': None}), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x110251440> +actual = call(custom_template_path=None, path=PosixPath('cool/path'), url=None), cause = None + + def assert_called_with(_mock_self, *args, **kwargs): + """assert that the mock was called with the specified arguments. + + Raises an AssertionError if the args and keyword args passed in are + different to the last call to the mock.""" + self = _mock_self + if self.call_args is None: + expected = self._format_mock_call_signature(args, kwargs) + raise AssertionError('Expected call: %s\nNot called' % (expected,)) + + def _error_message(): + msg = self._format_mock_failure_message(args, kwargs) + return msg + expected = self._call_matcher((args, kwargs)) + actual = self._call_matcher(self.call_args) + if expected != actual: + cause = expected if isinstance(expected, Exception) else None +> raise AssertionError(_error_message()) from cause +E AssertionError: Expected call: update_existing_client(path=PosixPath('cool/path'), url=None) +E Actual call: update_existing_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError + +During handling of the above exception, another exception occurred: + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='update_existing_client' id='4565442512'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: update_existing_client(path=PosixPath('cool/path'), url=None)\nActual call: update_existing_client(cus... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: +> __wrapped_mock_method__(*args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +_mock_self = <MagicMock name='update_existing_client' id='4565442512'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} +self = <MagicMock name='update_existing_client' id='4565442512'> + + def assert_called_once_with(_mock_self, *args, **kwargs): + """assert that the mock was called exactly once and that that call was + with the specified arguments.""" + self = _mock_self + if not self.call_count == 1: + msg = ("Expected '%s' to be called once. Called %s times." % + (self._mock_name or 'mock', self.call_count)) + raise AssertionError(msg) +> return self.assert_called_with(*args, **kwargs) + +/opt/miniconda3/lib/python3.7/unittest/mock.py:845: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +args = (<MagicMock name='update_existing_client' id='4565442512'>,), kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True + + def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: + __tracebackhide__ = True +> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4565442512'>,) +kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True +msg = "Expected call: update_existing_client(path=PosixPath('cool/path'), url=None)\nActual call: update_existing_client(cus... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +__mock_self = <MagicMock name='update_existing_client' id='4565442512'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} +introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" +@py_assert2 = None, @py_assert1 = False + + def assert_wrapper( + __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any + ) -> None: + __tracebackhide__ = True + try: + __wrapped_mock_method__(*args, **kwargs) + return + except AssertionError as e: + if getattr(e, "_mock_introspection_applied", 0): + msg = str(e) + else: + __mock_self = args[0] + msg = str(e) + if __mock_self.call_args is not None: + actual_args, actual_kwargs = __mock_self.call_args + introspection = "" + try: + assert actual_args == args[1:] + except AssertionError as e_args: + introspection += "\nArgs:\n" + str(e_args) + try: + assert actual_kwargs == kwargs + except AssertionError as e_kwargs: + introspection += "\nKwargs:\n" + str(e_kwargs) + if introspection: + msg += "\n\npytest introspection follows:\n" + introspection + e = AssertionError(msg) + e._mock_introspection_applied = True # type:ignore[attr-defined] +> raise e +E AssertionError: Expected call: update_existing_client(path=PosixPath('cool/path'), url=None) +E Actual call: update_existing_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError + +During handling of the above exception, another exception occurred: + +self = <tests.test_cli.TestUpdate object at 0x1101f1e50>, _update_existing_client = <MagicMock name='update_existing_client' id='4565442512'> + + def test_update_path(self, _update_existing_client): + path = "cool/path" + from openapi_python_client.cli import app + + result = runner.invoke(app, ["update", f"--path={path}"]) + + assert result.exit_code == 0 +> _update_existing_client.assert_called_once_with(url=None, path=Path(path)) +E AssertionError: Expected call: update_existing_client(path=PosixPath('cool/path'), url=None) +E Actual call: update_existing_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) +E +E pytest introspection follows: +E +E Kwargs: +E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} +E Omitting 2 identical items, use -vv to show +E Left contains 1 more item: +E {'custom_template_path': None} +E Use -v to get the full diff + +tests/test_cli.py:171: AssertionError \ No newline at end of file diff --git a/tests/test___init__.py b/tests/test___init__.py index 82a7ab02e..e15249a47 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -23,7 +23,7 @@ def test__get_project_for_url_or_path(mocker): _get_document.assert_called_once_with(url=url, path=path) from_dict.assert_called_once_with(data_dict) - _Project.assert_called_once_with(openapi=openapi) + _Project.assert_called_once_with(openapi=openapi, custom_template_path=None) assert project == _Project() @@ -75,7 +75,7 @@ def test_create_new_client(mocker): result = create_new_client(url=url, path=path) - _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) + _get_project_for_url_or_path.assert_called_once_with(url=url, path=path, custom_template_path=None) project.build.assert_called_once() assert result == project.build.return_value @@ -92,7 +92,7 @@ def test_create_new_client_project_error(mocker): result = create_new_client(url=url, path=path) - _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) + _get_project_for_url_or_path.assert_called_once_with(url=url, path=path, custom_template_path=None) assert result == [error] @@ -108,7 +108,7 @@ def test_update_existing_client(mocker): result = update_existing_client(url=url, path=path) - _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) + _get_project_for_url_or_path.assert_called_once_with(url=url, path=path, custom_template_path=None) project.update.assert_called_once() assert result == project.update.return_value @@ -125,7 +125,7 @@ def test_update_existing_client_project_error(mocker): result = update_existing_client(url=url, path=path) - _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) + _get_project_for_url_or_path.assert_called_once_with(url=url, path=path, custom_template_path=None) assert result == [error] @@ -438,5 +438,5 @@ def test__custom_templates(mocker): project = Project(openapi=openapi, custom_template_path='../end_to_end_tests/test_custom_templates') assert isinstance(project.env.loader, jinja2.ChoiceLoader) assert len(project.env.loader.loaders) == 2 - assert isinstance(project.env.loader.loaders[0], jinja2.ChoiceLoader) + assert isinstance(project.env.loader.loaders[0], jinja2.FileSystemLoader) assert isinstance(project.env.loader.loaders[1], jinja2.PackageLoader) diff --git a/tests/test_cli.py b/tests/test_cli.py index f4fd9b9cb..1995b7228 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -36,7 +36,7 @@ def test_config_arg(mocker, _create_new_client): assert result.exit_code == 0 load_config.assert_called_once_with(path=Path(config_path)) - _create_new_client.assert_called_once_with(url=None, path=Path(path)) + _create_new_client.assert_called_once_with(url=None, path=Path(path), custom_template_path=None) def test_bad_config(mocker, _create_new_client): @@ -80,7 +80,7 @@ def test_generate_url(self, _create_new_client): result = runner.invoke(app, ["generate", f"--url={url}"]) assert result.exit_code == 0 - _create_new_client.assert_called_once_with(url=url, path=None) + _create_new_client.assert_called_once_with(url=url, path=None, custom_template_path=None) def test_generate_path(self, _create_new_client): path = "cool/path" @@ -89,7 +89,7 @@ def test_generate_path(self, _create_new_client): result = runner.invoke(app, ["generate", f"--path={path}"]) assert result.exit_code == 0 - _create_new_client.assert_called_once_with(url=None, path=Path(path)) + _create_new_client.assert_called_once_with(url=None, path=Path(path), custom_template_path=None) def test_generate_handle_errors(self, _create_new_client): _create_new_client.return_value = [GeneratorError(detail="this is a message")] @@ -159,7 +159,7 @@ def test_update_url(self, _update_existing_client): result = runner.invoke(app, ["update", f"--url={url}"]) assert result.exit_code == 0 - _update_existing_client.assert_called_once_with(url=url, path=None) + _update_existing_client.assert_called_once_with(url=url, path=None, custom_template_path=None) def test_update_path(self, _update_existing_client): path = "cool/path" @@ -168,4 +168,4 @@ def test_update_path(self, _update_existing_client): result = runner.invoke(app, ["update", f"--path={path}"]) assert result.exit_code == 0 - _update_existing_client.assert_called_once_with(url=None, path=Path(path)) + _update_existing_client.assert_called_once_with(url=None, path=Path(path), custom_template_path=None) From ff981e947294c628b9e6302b1b7bfe8b62ddb380 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 09:08:30 -0800 Subject: [PATCH 07/14] ignore format of end to end custom templates --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 0253d3f3b..ffbfab4ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,6 +75,8 @@ exclude = ''' | \.mypy_cache | openapi_python_client/templates | tests/test_templates + | end_to_end_tests/test_custom_templates + | end_to_end_tests/golden-record-custom )/ ) ''' From 82186f589506eabbc82813a628bff1bda799b86b Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 09:11:44 -0800 Subject: [PATCH 08/14] reformat custom template test formatting --- end_to_end_tests/regen_golden_record.py | 18 +++++++++++------- end_to_end_tests/test_end_to_end.py | 14 +++++++++----- tests/test___init__.py | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/end_to_end_tests/regen_golden_record.py b/end_to_end_tests/regen_golden_record.py index aa664a781..37400defc 100644 --- a/end_to_end_tests/regen_golden_record.py +++ b/end_to_end_tests/regen_golden_record.py @@ -12,7 +12,7 @@ openapi_path = Path(__file__).parent / "openapi.json" output_path = Path.cwd() / "my-test-api-client" - if sys.argv[1] == 'custom': + if sys.argv[1] == "custom": gr_path = Path(__file__).parent / "golden-record-custom" else: gr_path = Path(__file__).parent / "golden-record" @@ -21,12 +21,16 @@ shutil.rmtree(output_path, ignore_errors=True) config_path = Path(__file__).parent / "config.yml" - if sys.argv[1] == 'custom': - result = runner.invoke(app, [ - f"--config={config_path}", - "generate", - f"--path={openapi_path}", - "--custom-template-path=end_to_end_tests/test_custom_templates"]) + if sys.argv[1] == "custom": + result = runner.invoke( + app, + [ + f"--config={config_path}", + "generate", + f"--path={openapi_path}", + "--custom-template-path=end_to_end_tests/test_custom_templates", + ], + ) else: result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={openapi_path}"]) diff --git a/end_to_end_tests/test_end_to_end.py b/end_to_end_tests/test_end_to_end.py index aead25371..2d5bdfdae 100644 --- a/end_to_end_tests/test_end_to_end.py +++ b/end_to_end_tests/test_end_to_end.py @@ -57,11 +57,15 @@ def test_end_to_end_w_custom_templates(): output_path = Path.cwd() / "my-test-api-client-custom" shutil.rmtree(output_path, ignore_errors=True) - result = runner.invoke(app, [ - f"--config={config_path}", - "generate", - f"--path={openapi_path}", - "--custom-template-path=end_to_end_tests/test_custom_templates"]) + result = runner.invoke( + app, + [ + f"--config={config_path}", + "generate", + f"--path={openapi_path}", + "--custom-template-path=end_to_end_tests/test_custom_templates", + ], + ) if result.exit_code != 0: raise result.exception diff --git a/tests/test___init__.py b/tests/test___init__.py index e15249a47..3a42b4442 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -435,7 +435,7 @@ def test__custom_templates(mocker): project = Project(openapi=openapi) assert isinstance(project.env.loader, jinja2.PackageLoader) - project = Project(openapi=openapi, custom_template_path='../end_to_end_tests/test_custom_templates') + project = Project(openapi=openapi, custom_template_path="../end_to_end_tests/test_custom_templates") assert isinstance(project.env.loader, jinja2.ChoiceLoader) assert len(project.env.loader.loaders) == 2 assert isinstance(project.env.loader.loaders[0], jinja2.FileSystemLoader) From a32e9f4e79e98e5765d4046bd9ae71f11807c892 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 09:30:59 -0800 Subject: [PATCH 09/14] document custom template usage --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 04cbe06c9..bcf7fb049 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,19 @@ get an error. > For more usage details run `openapi-python-client --help` or read [usage](usage.md) + +### Using custom templates + +This feature leverages Jinja2's [ChoiceLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.ChoiceLoader) and [FileSystemLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.FileSystemLoader). This means you do _not_ need to customize every template. Simply copy the template(s) you want to customize from [the default template directory](openapi_python_client/templates) to your own custom template directory (file names _must_ match exactly) and pass the template directory through the `custom_template_path` flag to the `generate` and `update` commands. For instance, + +``` +openapi-python-client update \ + --url https://my.api.com/openapi.json \ + --custom-template-path=relative/path/to/mytemplates +``` + +_Be forewarned, this is a beta-level feature in the sense that the API exposed in the templates is undocumented and unstable._ + ## What You Get 1. A `pyproject.toml` file with some basic metadata intended to be used with [Poetry]. From 75c47a18a51dea84c5e11966cce263af31afc39f Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 11:28:43 -0800 Subject: [PATCH 10/14] revert ignoring of e2e generated api client --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5739d6fbc..8f9c35601 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ dmypy.json htmlcov/ # Generated end to end test data -tmp/my-test-api-client \ No newline at end of file +my-test-api-client \ No newline at end of file From 658e6c4cda7fbea15770def7f3d0f6f03dc6fb00 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 16:53:37 -0800 Subject: [PATCH 11/14] remove test reports --- test-reports/pytest/results.xml | 1658 ------------------------------- 1 file changed, 1658 deletions(-) delete mode 100644 test-reports/pytest/results.xml diff --git a/test-reports/pytest/results.xml b/test-reports/pytest/results.xml deleted file mode 100644 index 03ed21f60..000000000 --- a/test-reports/pytest/results.xml +++ /dev/null @@ -1,1658 +0,0 @@ -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='Project' id='4564528656'>,) -kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True -msg = "Expected call: Project(openapi=<MagicMock id='4564476176'>)\nActual call: Project(custom_template_path=None, openapi=... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='Project' id='4564528656'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'openapi': <MagicMock id='4564476176'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>}\n Omitting 1 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='Project' id='4564528656'>, args = (), kwargs = {'openapi': <MagicMock id='4564476176'>}, expected = ((), {'openapi': <MagicMock id='4564476176'>}) -_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1101dfd40>, actual = call(custom_template_path=None, openapi=<MagicMock id='4564476176'>) -cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: Project(openapi=<MagicMock id='4564476176'>) -E Actual call: Project(custom_template_path=None, openapi=<MagicMock id='4564476176'>) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='Project' id='4564528656'>,) -kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True -msg = "Expected call: Project(openapi=<MagicMock id='4564476176'>)\nActual call: Project(custom_template_path=None, openapi=... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='Project' id='4564528656'>, args = (), kwargs = {'openapi': <MagicMock id='4564476176'>}, self = <MagicMock name='Project' id='4564528656'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='Project' id='4564528656'>,), kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='Project' id='4564528656'>,) -kwargs = {'openapi': <MagicMock id='4564476176'>}, __tracebackhide__ = True -msg = "Expected call: Project(openapi=<MagicMock id='4564476176'>)\nActual call: Project(custom_template_path=None, openapi=... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='Project' id='4564528656'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'openapi': <MagicMock id='4564476176'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>}\n Omitting 1 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: Project(openapi=<MagicMock id='4564476176'>) -E Actual call: Project(custom_template_path=None, openapi=<MagicMock id='4564476176'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>} -E Omitting 1 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -mocker = <pytest_mock.plugin.MockerFixture object at 0x11016b690> - - def test__get_project_for_url_or_path(mocker): - data_dict = mocker.MagicMock() - _get_document = mocker.patch("openapi_python_client._get_document", return_value=data_dict) - openapi = mocker.MagicMock() - from_dict = mocker.patch("openapi_python_client.parser.GeneratorData.from_dict", return_value=openapi) - _Project = mocker.patch("openapi_python_client.Project") - url = mocker.MagicMock() - path = mocker.MagicMock() - - from openapi_python_client import _get_project_for_url_or_path - - project = _get_project_for_url_or_path(url=url, path=path) - - _get_document.assert_called_once_with(url=url, path=path) - from_dict.assert_called_once_with(data_dict) -> _Project.assert_called_once_with(openapi=openapi) -E AssertionError: Expected call: Project(openapi=<MagicMock id='4564476176'>) -E Actual call: Project(custom_template_path=None, openapi=<MagicMock id='4564476176'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4564476176'>} == {'openapi': <...'4564476176'>} -E Omitting 1 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test___init__.py:26: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,) -kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, args = (), kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} -expected = ((), {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}) -_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1101230e0> -actual = call(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,) -kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, args = (), kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} -self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,), kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564323728'>,) -kwargs = {'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564323728'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565441872'>, 'url': <MagicMock id='4564322128'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -mocker = <pytest_mock.plugin.MockerFixture object at 0x1103b0990> - - def test_create_new_client(mocker): - project = mocker.MagicMock() - _get_project_for_url_or_path = mocker.patch( - "openapi_python_client._get_project_for_url_or_path", return_value=project - ) - url = mocker.MagicMock() - path = mocker.MagicMock() - - from openapi_python_client import create_new_client - - result = create_new_client(url=url, path=path) - -> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565441872'>, url=<MagicMock id='4564322128'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4564322128'>} == {'path': <Mag...'4564322128'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test___init__.py:78: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,) -kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, args = (), kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} -expected = ((), {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}) -_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11031c050> -actual = call(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,) -kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, args = (), kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} -self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,), kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4563822288'>,) -kwargs = {'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4563822288'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565319376'>, 'url': <MagicMock id='4565167376'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -mocker = <pytest_mock.plugin.MockerFixture object at 0x110066310> - - def test_create_new_client_project_error(mocker): - error = GeneratorError() - _get_project_for_url_or_path = mocker.patch( - "openapi_python_client._get_project_for_url_or_path", return_value=error - ) - url = mocker.MagicMock() - path = mocker.MagicMock() - - from openapi_python_client import create_new_client - - result = create_new_client(url=url, path=path) - -> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565319376'>, url=<MagicMock id='4565167376'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4565167376'>} == {'path': <Mag...'4565167376'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test___init__.py:95: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,) -kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, args = (), kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} -expected = ((), {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}) -_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11031cd40> -actual = call(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,) -kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, args = (), kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} -self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,), kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4564176528'>,) -kwargs = {'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4564176528'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565619856'>, 'url': <MagicMock id='4564703888'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -mocker = <pytest_mock.plugin.MockerFixture object at 0x11014e8d0> - - def test_update_existing_client(mocker): - project = mocker.MagicMock() - _get_project_for_url_or_path = mocker.patch( - "openapi_python_client._get_project_for_url_or_path", return_value=project - ) - url = mocker.MagicMock() - path = mocker.MagicMock() - - from openapi_python_client import update_existing_client - - result = update_existing_client(url=url, path=path) - -> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565619856'>, url=<MagicMock id='4564703888'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4564703888'>} == {'path': <Mag...'4564703888'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test___init__.py:111: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,) -kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, args = (), kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} -expected = ((), {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}) -_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1101df8c0> -actual = call(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,) -kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, args = (), kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} -self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,), kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='_get_project_for_url_or_path' id='4565765200'>,) -kwargs = {'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>}, __tracebackhide__ = True -msg = "Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>)\nActua... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='_get_project_for_url_or_path' id='4565765200'>, actual_args = () -actual_kwargs = {'custom_template_path': None, 'path': <MagicMock id='4565727504'>, 'url': <MagicMock id='4565763600'>} -introspection = "\nKwargs:\nassert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -mocker = <pytest_mock.plugin.MockerFixture object at 0x110240ed0> - - def test_update_existing_client_project_error(mocker): - error = GeneratorError() - _get_project_for_url_or_path = mocker.patch( - "openapi_python_client._get_project_for_url_or_path", return_value=error - ) - url = mocker.MagicMock() - path = mocker.MagicMock() - - from openapi_python_client import update_existing_client - - result = update_existing_client(url=url, path=path) - -> _get_project_for_url_or_path.assert_called_once_with(url=url, path=path) -E AssertionError: Expected call: _get_project_for_url_or_path(path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) -E Actual call: _get_project_for_url_or_path(custom_template_path=None, path=<MagicMock id='4565727504'>, url=<MagicMock id='4565763600'>) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...'4565763600'>} == {'path': <Mag...'4565763600'>} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test___init__.py:128: AssertionErrormocker = <pytest_mock.plugin.MockerFixture object at 0x11013dd50> - - def test__custom_templates(mocker): - from openapi_python_client import GeneratorData, Project - from openapi_python_client.parser.openapi import EndpointCollection, Schemas - - openapi = mocker.MagicMock( - autospec=GeneratorData, - title="My Test API", - endpoint_collections_by_tag={ - "default": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[1]), - "other": mocker.MagicMock(autospec=EndpointCollection, parse_errors=[2]), - }, - schemas=mocker.MagicMock(autospec=Schemas, errors=[3]), - ) - - project = Project(openapi=openapi) - assert isinstance(project.env.loader, jinja2.PackageLoader) - - project = Project(openapi=openapi, custom_template_path='../end_to_end_tests/test_custom_templates') - assert isinstance(project.env.loader, jinja2.ChoiceLoader) - assert len(project.env.loader.loaders) == 2 -> assert isinstance(project.env.loader.loaders[0], jinja2.ChoiceLoader) -E AssertionError: assert False -E + where False = isinstance(<jinja2.loaders.FileSystemLoader object at 0x1101d3a50>, <class 'jinja2.loaders.ChoiceLoader'>) -E + where <class 'jinja2.loaders.ChoiceLoader'> = jinja2.ChoiceLoader - -tests/test___init__.py:441: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4569005456'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='create_new_client' id='4569005456'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} -introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='create_new_client' id='4569005456'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} -expected = ((), {'path': PosixPath('cool/path'), 'url': None}), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11031c440> -actual = call(custom_template_path=None, path=PosixPath('cool/path'), url=None), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) -E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='create_new_client' id='4569005456'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='create_new_client' id='4569005456'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} -self = <MagicMock name='create_new_client' id='4569005456'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='create_new_client' id='4569005456'>,), kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4569005456'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='create_new_client' id='4569005456'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} -introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) -E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -mocker = <pytest_mock.plugin.MockerFixture object at 0x110557ed0>, _create_new_client = <MagicMock name='create_new_client' id='4569005456'> - - def test_config_arg(mocker, _create_new_client): - load_config = mocker.patch("openapi_python_client.config.Config.load_from_path") - from openapi_python_client.cli import app - - config_path = "config/path" - path = "cool/path" - - result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={path}"], catch_exceptions=False) - - assert result.exit_code == 0 - load_config.assert_called_once_with(path=Path(config_path)) -> _create_new_client.assert_called_once_with(url=None, path=Path(path)) -E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) -E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test_cli.py:39: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4564703568'>,) -kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=None, url='cool.url')\nActual call: create_new_client(custom_template_path=None... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='create_new_client' id='4564703568'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} -introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='create_new_client' id='4564703568'>, args = (), kwargs = {'path': None, 'url': 'cool.url'}, expected = ((), {'path': None, 'url': 'cool.url'}) -_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1103e79e0>, actual = call(custom_template_path=None, path=None, url='cool.url'), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: create_new_client(path=None, url='cool.url') -E Actual call: create_new_client(custom_template_path=None, path=None, url='cool.url') - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='create_new_client' id='4564703568'>,) -kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=None, url='cool.url')\nActual call: create_new_client(custom_template_path=None... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='create_new_client' id='4564703568'>, args = (), kwargs = {'path': None, 'url': 'cool.url'}, self = <MagicMock name='create_new_client' id='4564703568'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='create_new_client' id='4564703568'>,), kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4564703568'>,) -kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=None, url='cool.url')\nActual call: create_new_client(custom_template_path=None... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='create_new_client' id='4564703568'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} -introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: create_new_client(path=None, url='cool.url') -E Actual call: create_new_client(custom_template_path=None, path=None, url='cool.url') -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -self = <tests.test_cli.TestGenerate object at 0x1100e0cd0>, _create_new_client = <MagicMock name='create_new_client' id='4564703568'> - - def test_generate_url(self, _create_new_client): - url = "cool.url" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["generate", f"--url={url}"]) - - assert result.exit_code == 0 -> _create_new_client.assert_called_once_with(url=url, path=None) -E AssertionError: Expected call: create_new_client(path=None, url='cool.url') -E Actual call: create_new_client(custom_template_path=None, path=None, url='cool.url') -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test_cli.py:83: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4567271312'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='create_new_client' id='4567271312'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} -introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='create_new_client' id='4567271312'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} -expected = ((), {'path': PosixPath('cool/path'), 'url': None}), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x1103e7d40> -actual = call(custom_template_path=None, path=PosixPath('cool/path'), url=None), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) -E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='create_new_client' id='4567271312'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='create_new_client' id='4567271312'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} -self = <MagicMock name='create_new_client' id='4567271312'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='create_new_client' id='4567271312'>,), kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='create_new_client' id='4567271312'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: create_new_client(path=PosixPath('cool/path'), url=None)\nActual call: create_new_client(custom_templa... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='create_new_client' id='4567271312'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} -introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) -E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -self = <tests.test_cli.TestGenerate object at 0x1103b06d0>, _create_new_client = <MagicMock name='create_new_client' id='4567271312'> - - def test_generate_path(self, _create_new_client): - path = "cool/path" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["generate", f"--path={path}"]) - - assert result.exit_code == 0 -> _create_new_client.assert_called_once_with(url=None, path=Path(path)) -E AssertionError: Expected call: create_new_client(path=PosixPath('cool/path'), url=None) -E Actual call: create_new_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test_cli.py:92: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4564173584'>,) -kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True -msg = "Expected call: update_existing_client(path=None, url='cool.url')\nActual call: update_existing_client(custom_template... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='update_existing_client' id='4564173584'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} -introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='update_existing_client' id='4564173584'>, args = (), kwargs = {'path': None, 'url': 'cool.url'}, expected = ((), {'path': None, 'url': 'cool.url'}) -_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x11048fd40>, actual = call(custom_template_path=None, path=None, url='cool.url'), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: update_existing_client(path=None, url='cool.url') -E Actual call: update_existing_client(custom_template_path=None, path=None, url='cool.url') - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='update_existing_client' id='4564173584'>,) -kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True -msg = "Expected call: update_existing_client(path=None, url='cool.url')\nActual call: update_existing_client(custom_template... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='update_existing_client' id='4564173584'>, args = (), kwargs = {'path': None, 'url': 'cool.url'} -self = <MagicMock name='update_existing_client' id='4564173584'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='update_existing_client' id='4564173584'>,), kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4564173584'>,) -kwargs = {'path': None, 'url': 'cool.url'}, __tracebackhide__ = True -msg = "Expected call: update_existing_client(path=None, url='cool.url')\nActual call: update_existing_client(custom_template... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='update_existing_client' id='4564173584'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': None, 'url': 'cool.url'} -introspection = "\nKwargs:\nassert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: update_existing_client(path=None, url='cool.url') -E Actual call: update_existing_client(custom_template_path=None, path=None, url='cool.url') -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -self = <tests.test_cli.TestUpdate object at 0x1100bc2d0>, _update_existing_client = <MagicMock name='update_existing_client' id='4564173584'> - - def test_update_url(self, _update_existing_client): - url = "cool.url" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["update", f"--url={url}"]) - - assert result.exit_code == 0 -> _update_existing_client.assert_called_once_with(url=url, path=None) -E AssertionError: Expected call: update_existing_client(path=None, url='cool.url') -E Actual call: update_existing_client(custom_template_path=None, path=None, url='cool.url') -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp...': 'cool.url'} == {'path': None...': 'cool.url'} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test_cli.py:162: AssertionError__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4565442512'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: update_existing_client(path=PosixPath('cool/path'), url=None)\nActual call: update_existing_client(cus... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='update_existing_client' id='4565442512'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} -introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='update_existing_client' id='4565442512'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} -expected = ((), {'path': PosixPath('cool/path'), 'url': None}), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x110251440> -actual = call(custom_template_path=None, path=PosixPath('cool/path'), url=None), cause = None - - def assert_called_with(_mock_self, *args, **kwargs): - """assert that the mock was called with the specified arguments. - - Raises an AssertionError if the args and keyword args passed in are - different to the last call to the mock.""" - self = _mock_self - if self.call_args is None: - expected = self._format_mock_call_signature(args, kwargs) - raise AssertionError('Expected call: %s\nNot called' % (expected,)) - - def _error_message(): - msg = self._format_mock_failure_message(args, kwargs) - return msg - expected = self._call_matcher((args, kwargs)) - actual = self._call_matcher(self.call_args) - if expected != actual: - cause = expected if isinstance(expected, Exception) else None -> raise AssertionError(_error_message()) from cause -E AssertionError: Expected call: update_existing_client(path=PosixPath('cool/path'), url=None) -E Actual call: update_existing_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:834: AssertionError - -During handling of the above exception, another exception occurred: - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x10e82f440>, args = (<MagicMock name='update_existing_client' id='4565442512'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: update_existing_client(path=PosixPath('cool/path'), url=None)\nActual call: update_existing_client(cus... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: -> __wrapped_mock_method__(*args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:371: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -_mock_self = <MagicMock name='update_existing_client' id='4565442512'>, args = (), kwargs = {'path': PosixPath('cool/path'), 'url': None} -self = <MagicMock name='update_existing_client' id='4565442512'> - - def assert_called_once_with(_mock_self, *args, **kwargs): - """assert that the mock was called exactly once and that that call was - with the specified arguments.""" - self = _mock_self - if not self.call_count == 1: - msg = ("Expected '%s' to be called once. Called %s times." % - (self._mock_name or 'mock', self.call_count)) - raise AssertionError(msg) -> return self.assert_called_with(*args, **kwargs) - -/opt/miniconda3/lib/python3.7/unittest/mock.py:845: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -args = (<MagicMock name='update_existing_client' id='4565442512'>,), kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True - - def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None: - __tracebackhide__ = True -> assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs) - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:404: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x10e82f3b0>, args = (<MagicMock name='update_existing_client' id='4565442512'>,) -kwargs = {'path': PosixPath('cool/path'), 'url': None}, __tracebackhide__ = True -msg = "Expected call: update_existing_client(path=PosixPath('cool/path'), url=None)\nActual call: update_existing_client(cus... items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -__mock_self = <MagicMock name='update_existing_client' id='4565442512'>, actual_args = (), actual_kwargs = {'custom_template_path': None, 'path': PosixPath('cool/path'), 'url': None} -introspection = "\nKwargs:\nassert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None}\n Omitting 2 identical items, use -vv to show\n Left contains 1 more item:\n {'custom_template_path': None}\n Use -v to get the full diff" -@py_assert2 = None, @py_assert1 = False - - def assert_wrapper( - __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any - ) -> None: - __tracebackhide__ = True - try: - __wrapped_mock_method__(*args, **kwargs) - return - except AssertionError as e: - if getattr(e, "_mock_introspection_applied", 0): - msg = str(e) - else: - __mock_self = args[0] - msg = str(e) - if __mock_self.call_args is not None: - actual_args, actual_kwargs = __mock_self.call_args - introspection = "" - try: - assert actual_args == args[1:] - except AssertionError as e_args: - introspection += "\nArgs:\n" + str(e_args) - try: - assert actual_kwargs == kwargs - except AssertionError as e_kwargs: - introspection += "\nKwargs:\n" + str(e_kwargs) - if introspection: - msg += "\n\npytest introspection follows:\n" + introspection - e = AssertionError(msg) - e._mock_introspection_applied = True # type:ignore[attr-defined] -> raise e -E AssertionError: Expected call: update_existing_client(path=PosixPath('cool/path'), url=None) -E Actual call: update_existing_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -../../Library/Caches/pypoetry/virtualenvs/openapi-python-client-KTN6QUgq-py3.7/lib/python3.7/site-packages/pytest_mock/plugin.py:394: AssertionError - -During handling of the above exception, another exception occurred: - -self = <tests.test_cli.TestUpdate object at 0x1101f1e50>, _update_existing_client = <MagicMock name='update_existing_client' id='4565442512'> - - def test_update_path(self, _update_existing_client): - path = "cool/path" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["update", f"--path={path}"]) - - assert result.exit_code == 0 -> _update_existing_client.assert_called_once_with(url=None, path=Path(path)) -E AssertionError: Expected call: update_existing_client(path=PosixPath('cool/path'), url=None) -E Actual call: update_existing_client(custom_template_path=None, path=PosixPath('cool/path'), url=None) -E -E pytest introspection follows: -E -E Kwargs: -E assert {'custom_temp..., 'url': None} == {'path': Posi..., 'url': None} -E Omitting 2 identical items, use -vv to show -E Left contains 1 more item: -E {'custom_template_path': None} -E Use -v to get the full diff - -tests/test_cli.py:171: AssertionError \ No newline at end of file From d22dfc37f44baeca76fc6ab91ab8f59f1e6ca99f Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 16:54:07 -0800 Subject: [PATCH 12/14] ignore test reports --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 8f9c35601..bba4f232a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,8 @@ dmypy.json # JetBrains .idea/ +test-reports/ + /coverage.xml /.coverage htmlcov/ From 94d314c9ca0ed75753a1d181240a705868fb0010 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 17:15:01 -0800 Subject: [PATCH 13/14] use pathlib.Path for custom template path for validation --- openapi_python_client/__init__.py | 11 +++++------ openapi_python_client/cli.py | 13 +++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 4905a9084..3a4d48a2b 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -2,7 +2,6 @@ import shutil import subprocess -import os import sys from pathlib import Path from typing import Any, Dict, Optional, Sequence, Union @@ -31,14 +30,14 @@ class Project: project_name_override: Optional[str] = None package_name_override: Optional[str] = None - def __init__(self, *, openapi: GeneratorData, custom_template_path: Optional[str] = None) -> None: + def __init__(self, *, openapi: GeneratorData, custom_template_path: Optional[Path] = None) -> None: self.openapi: GeneratorData = openapi package_loader = PackageLoader(__package__) if custom_template_path is not None: loader = ChoiceLoader( [ - FileSystemLoader(os.path.abspath(custom_template_path)), + FileSystemLoader(str(custom_template_path)), package_loader, ] ) @@ -204,7 +203,7 @@ def _build_api(self) -> None: def _get_project_for_url_or_path( - url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None + url: Optional[str], path: Optional[Path], custom_template_path: Optional[Path] = None ) -> Union[Project, GeneratorError]: data_dict = _get_document(url=url, path=path) if isinstance(data_dict, GeneratorError): @@ -216,7 +215,7 @@ def _get_project_for_url_or_path( def create_new_client( - *, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None + *, url: Optional[str], path: Optional[Path], custom_template_path: Optional[Path] = None ) -> Sequence[GeneratorError]: """ Generate the client library @@ -231,7 +230,7 @@ def create_new_client( def update_existing_client( - *, url: Optional[str], path: Optional[Path], custom_template_path: Optional[str] = None + *, url: Optional[str], path: Optional[Path], custom_template_path: Optional[Path] = None ) -> Sequence[GeneratorError]: """ Update an existing client library diff --git a/openapi_python_client/cli.py b/openapi_python_client/cli.py index f3796585b..2643ce85d 100644 --- a/openapi_python_client/cli.py +++ b/openapi_python_client/cli.py @@ -96,11 +96,20 @@ def handle_errors(errors: Sequence[GeneratorError]) -> None: raise typer.Exit(code=1) +custom_template_path_options = { + "help": "A path to a directory containing custom template(s)", + "file_okay": False, + "dir_okay": True, + "readable": True, + "resolve_path": True, +} + + @app.command() def generate( url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"), path: Optional[pathlib.Path] = typer.Option(None, help="A path to the JSON file"), - custom_template_path: Optional[str] = typer.Option(None, help="A path to a custom template directory"), + custom_template_path: Optional[pathlib.Path] = typer.Option(None, **custom_template_path_options), ) -> None: """ Generate a new OpenAPI Client library """ from . import create_new_client @@ -119,7 +128,7 @@ def generate( def update( url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"), path: Optional[pathlib.Path] = typer.Option(None, help="A path to the JSON file"), - custom_template_path: Optional[str] = typer.Option(None, help="A path to a custom template directory"), + custom_template_path: Optional[pathlib.Path] = typer.Option(None, **custom_template_path_options), ) -> None: """ Update an existing OpenAPI Client library """ from . import update_existing_client From af321db1354ddd06b89eaa5b106d9c84852af074 Mon Sep 17 00:00:00 2001 From: Eric Hulburd Date: Tue, 3 Nov 2020 17:15:16 -0800 Subject: [PATCH 14/14] do not make type assertions on custom templates --- end_to_end_tests/test_end_to_end.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/end_to_end_tests/test_end_to_end.py b/end_to_end_tests/test_end_to_end.py index 2d5bdfdae..ce4942f7f 100644 --- a/end_to_end_tests/test_end_to_end.py +++ b/end_to_end_tests/test_end_to_end.py @@ -54,7 +54,7 @@ def test_end_to_end_w_custom_templates(): openapi_path = Path(__file__).parent / "openapi.json" config_path = Path(__file__).parent / "config.yml" gr_path = Path(__file__).parent / "golden-record-custom" - output_path = Path.cwd() / "my-test-api-client-custom" + output_path = Path.cwd() / "my-test-api-client" shutil.rmtree(output_path, ignore_errors=True) result = runner.invoke( @@ -71,9 +71,4 @@ def test_end_to_end_w_custom_templates(): raise result.exception _compare_directories(gr_path, output_path) - import mypy.api - - out, err, status = mypy.api.run([str(output_path), "--strict"]) - assert status == 0, f"Type checking client failed: {out}" - shutil.rmtree(output_path)