mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 21:30:22 -07:00
Remove uses of assert in production code (#32079)
* Remove uses of assert in production code * Fix assertion * Add code smell test for assertions, currently limited to lib/ansible * Fix assertion * Add docs for no-assert * Remove new assert from enos * Fix assert in module_utils.connection
This commit is contained in:
parent
464ded80f5
commit
99d4f5bab4
38 changed files with 195 additions and 89 deletions
|
@ -8,7 +8,7 @@ import multiprocessing
|
|||
import random
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.errors import AnsibleError, AnsibleAssertionError
|
||||
from ansible.module_utils.six import text_type
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
|
||||
|
@ -67,7 +67,8 @@ def random_password(length=DEFAULT_PASSWORD_LENGTH, chars=C.DEFAULT_PASSWORD_CHA
|
|||
:kwarg chars: The characters to choose from. The default is all ascii
|
||||
letters, ascii digits, and these symbols ``.,:-_``
|
||||
'''
|
||||
assert isinstance(chars, text_type), '%s (%s) is not a text_type' % (chars, type(chars))
|
||||
if not isinstance(chars, text_type):
|
||||
raise AnsibleAssertionError('%s (%s) is not a text_type' % (chars, type(chars)))
|
||||
|
||||
random_generator = random.SystemRandom()
|
||||
return u''.join(random_generator.choice(chars) for dummy in range(length))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue