Merge "Remove usage of six.PY2"

This commit is contained in:
Zuul 2020-05-26 16:21:41 +00:00 committed by Gerrit Code Review
commit 4d0527d3ca
3 changed files with 11 additions and 26 deletions

View File

@ -13,19 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
import builtins
import gettext
from debtcollector import removals
import six
if six.PY2:
# pylint: disable=unexpected-keyword-arg
gettext.install('neutron', unicode=1)
else:
gettext.install('neutron')
gettext.install('neutron')
six.moves.builtins.__dict__['_'] = removals.remove(
builtins.__dict__['_'] = removals.remove(
message='Builtin _ translation function is deprecated in OpenStack; '
'use the function from _i18n module for your project.')(_) # noqa

View File

@ -19,7 +19,6 @@ import decorator
from oslo_concurrency import lockutils
from oslo_log import log
from oslo_utils import timeutils
import six
LOG = log.getLogger(__name__)
@ -61,13 +60,9 @@ def synchronized(lock_name):
@decorator.decorator
def _synchronized(f, *a, **k):
if six.PY2:
# pylint: disable=deprecated-method
call_args = inspect.getcallargs(f, *a, **k)
else:
sig = inspect.signature(f).bind(*a, **k)
sig.apply_defaults()
call_args = sig.arguments
sig = inspect.signature(f).bind(*a, **k)
sig.apply_defaults()
call_args = sig.arguments
call_args['f_name'] = f.__name__
lock_format_name = lock_name.format(**call_args)
t1 = timeutils.now()

View File

@ -17,7 +17,6 @@ import signal
import socket
from unittest import mock
import six
import testtools
from neutron_lib import exceptions
@ -154,16 +153,11 @@ class AgentUtilsExecuteTest(base.BaseTestCase):
def test_encode_process_input(self):
str_idata = "%s\n" % self.test_file[:-1]
str_odata = "%s\n" % self.test_file
if six.PY3:
bytes_idata = str_idata.encode(encoding='utf-8')
bytes_odata = str_odata.encode(encoding='utf-8')
self.mock_popen.return_value = [bytes_odata, b'']
result = utils.execute(['cat'], process_input=str_idata)
self.mock_popen.assert_called_once_with(bytes_idata)
else:
self.mock_popen.return_value = [str_odata, '']
result = utils.execute(['cat'], process_input=str_idata)
self.mock_popen.assert_called_once_with(str_idata)
bytes_idata = str_idata.encode(encoding='utf-8')
bytes_odata = str_odata.encode(encoding='utf-8')
self.mock_popen.return_value = [bytes_odata, b'']
result = utils.execute(['cat'], process_input=str_idata)
self.mock_popen.assert_called_once_with(bytes_idata)
self.assertEqual(str_odata, result)
def test_return_str_data(self):