Skip to content

Commit

Permalink
avoid setting debug property if not needed (#18872)
Browse files Browse the repository at this point in the history
* avoid setting debug property if not needed

* update samples

* fix compatibility with python 3.7

* always set Configuration.__debug

* update samples

* check `Configuration` behavior when debug parameter is / is not set

* address PR requests
  • Loading branch information
ZeeD committed Jun 20, 2024
1 parent 7747cc9 commit e5ae07c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ conf = {{{packageName}}}.Configuration(
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
retries=None,
*,
debug: Optional[bool] = None
) -> None:
"""Constructor
"""
Expand Down Expand Up @@ -214,7 +216,10 @@ conf = {{{packageName}}}.Configuration(
self.logger_file = None
"""Debug file location
"""
self.debug = False
if debug is not None:
self.debug = debug
else:
self.__debug = False
"""Debug switch
"""

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,14 @@ def test_get_host_from_settings(self):
self.assertEqual("http://petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'port': '8080'}))
self.assertEqual("http://dev-petstore.swagger.io:8080/v2", self.config.get_host_from_settings(0, {'server': 'dev-petstore', 'port': '8080'}))

def testConfigurationDebug(self):
for debug, expected in [(True, True), (False, False), (None, False)]:
with self.subTest('expicitly passing debug parameter', debug=debug, expected=expected):
c = petstore_api.Configuration(debug=debug)
self.assertEqual(expected, c.debug)
with self.subTest('not passing debug parameter'):
c = petstore_api.Configuration()
self.assertFalse(c.debug)

if __name__ == '__main__':
unittest.main()

0 comments on commit e5ae07c

Please sign in to comment.