mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Migrate basestring to a python3 compatible type (#17199)
This commit is contained in:
16
test/code-smell/no-basestring.sh
Executable file
16
test/code-smell/no-basestring.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
BASEDIR=${1-"."}
|
||||
|
||||
# Not entirely correct but
|
||||
# * basestring is still present and harmless in comments
|
||||
# * basestring is also currently present in modules. Porting of modules is more
|
||||
# of an Ansible 2.3 or greater goal.
|
||||
BASESTRING_USERS=$(grep -r basestring $BASEDIR |grep isinstance| grep -v lib/ansible/compat/six/_six.py|grep -v lib/ansible/module_utils/six.py|grep -v lib/ansible/modules/core|grep -v lib/ansible/modules/extras)
|
||||
|
||||
if test -n "$BASESTRING_USERS" ; then
|
||||
printf "$BASESTRING_USERS"
|
||||
exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
@@ -3,16 +3,18 @@ import mock
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
from nose.tools import eq_
|
||||
try:
|
||||
from nose.tools import assert_raises_regexp
|
||||
except ImportError:
|
||||
from ansible.compat.six import string_types
|
||||
# Python < 2.7
|
||||
def assert_raises_regexp(expected, regexp, callable, *a, **kw):
|
||||
try:
|
||||
callable(*a, **kw)
|
||||
except expected as e:
|
||||
if isinstance(regexp, basestring):
|
||||
if isinstance(regexp, string_types):
|
||||
regexp = re.compile(regexp)
|
||||
if not regexp.search(str(e)):
|
||||
raise Exception('"%s" does not match "%s"' %
|
||||
|
||||
Reference in New Issue
Block a user