Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid setting debug property if not needed #18872

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ conf = {{{packageName}}}.Configuration(
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
*,
debug: Optional[bool] = None
) -> None:
"""Constructor
"""
Expand Down Expand Up @@ -212,7 +214,8 @@ conf = {{{packageName}}}.Configuration(
self.logger_file = None
"""Debug file location
"""
self.debug = False
if debug is not None:
self.debug = debug
Comment on lines +219 to +220
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this self.debug property is not always set, then the underlying __debug property will also not always be set, which may produce AttributeError.

I would suggest to at least set self.__debug to False by default so that the debug setter/getter don't have a way to fail, and all the code that are also using this attribute will also not fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can easily add a default value for self.__debug, but I'm not sure how to write the tests.
Can you point me to a sample I can adapt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check here for instance: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/openapi3/client/petstore/python/tests/test_configuration.py

There are several tests around this class, you should be able to create a test that fails with your current change and make it pass by setting an initial value for __debug.

There may be other places with this kind of tests (they are written manually), but I didn't check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm... I was starting to write some tests, but it seems there are some unrelated failures.

$ cd samples/openapi3/client/petstore/python
$ poetry install
[...]
$ poetry run pytest
[...]
================================================= short test summary info ==================================================
FAILED tests/test_model.py::ModelTests::test_valdiator - AttributeError: 'ModelTests' object has no attribute 'assertEquals'. Did you mean: 'assertEqual'?
FAILED tests/test_pet_api.py::PetApiTests::test_add_pet_and_get_pet_by_id - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_add_pet_and_get_pet_by_id_with_http_info - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_add_pet_and_get_pet_by_id_without_preload_content_flag - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_delete_pet - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_find_pets_by_status - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_find_pets_by_tags - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_get_pet_by_id_serialize - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_update_pet - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_update_pet_with_form - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
FAILED tests/test_pet_api.py::PetApiTests::test_upload_file - urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v2/pet...
================================== 11 failed, 264 passed, 3 skipped, 9 warnings in 14.25s ==================================

I'm normally using python 3.12, where it was removed
Should I also update the unrelated tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • For assertEquals, this should be migrated in another PR I think. Can you test with 3.11 instead?
  • For the URL failures, there's an explanation how to start a test container to support the tests at the top of tests/test_pet_api.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(oh, and for the various PetApiTests failed tests, while it's easy to follow the instructions in the tests

Run the tests.
$ docker pull swaggerapi/petstore
$ docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore
$ pip install -U pytest
$ cd petstore_api-python
$ pytest
I would suggest to enhance them with testcontainers so you can avoid launching the docker image by hand

"""Debug switch
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def __init__(self, host=None,
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
*,
debug: Optional[bool] = None
) -> None:
"""Constructor
"""
Expand Down Expand Up @@ -141,7 +143,8 @@ def __init__(self, host=None,
self.logger_file = None
"""Debug file location
"""
self.debug = False
if debug is not None:
self.debug = debug
"""Debug switch
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def __init__(self, host=None,
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
*,
debug: Optional[bool] = None
) -> None:
"""Constructor
"""
Expand Down Expand Up @@ -141,7 +143,8 @@ def __init__(self, host=None,
self.logger_file = None
"""Debug file location
"""
self.debug = False
if debug is not None:
self.debug = debug
"""Debug switch
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def __init__(self, host=None,
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
*,
debug: Optional[bool] = None
) -> None:
"""Constructor
"""
Expand Down Expand Up @@ -205,7 +207,8 @@ def __init__(self, host=None,
self.logger_file = None
"""Debug file location
"""
self.debug = False
if debug is not None:
self.debug = debug
"""Debug switch
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def __init__(self, host=None,
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
*,
debug: Optional[bool] = None
) -> None:
"""Constructor
"""
Expand Down Expand Up @@ -206,7 +208,8 @@ def __init__(self, host=None,
self.logger_file = None
"""Debug file location
"""
self.debug = False
if debug is not None:
self.debug = debug
"""Debug switch
"""

Expand Down
Loading