Remove remaining six.moves usage

Change-Id: Ibca3884e1ea3d0fb170bcc9e70a176d144ee24cc
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2021-12-21 12:22:04 +00:00
parent 87ba56161b
commit 931809c037
10 changed files with 31 additions and 40 deletions

View File

@ -18,5 +18,4 @@ glance Specific Commandments
- [G327] Prevent use of deprecated contextlib.nested
- [G328] Must use a dict comprehension instead of a dict constructor with
a sequence of key-value pairs
- [G329] Python 3: Do not use xrange.
- [G330] Log.warn is deprecated. Enforce use of LOG.warning.

View File

@ -31,8 +31,6 @@ import uuid
from oslo_utils import encodeutils
import prettytable
from six.moves import input
# If ../glance/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),

View File

@ -12,12 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import configparser
import re
from oslo_config import cfg
from oslo_log import log as logging
from oslo_policy import policy
from six.moves import configparser
import glance.api.policy
from glance.common import exception

View File

@ -11,9 +11,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import configparser
from oslo_config import cfg
from oslo_log import log as logging
from six.moves import configparser
from glance.common import exception
from glance.i18n import _, _LE

View File

@ -116,13 +116,6 @@ def dict_constructor_with_list_copy(logical_line):
yield (0, msg)
@core.flake8ext
def check_python3_xrange(logical_line):
if re.search(r"\bxrange\s*\(", logical_line):
yield(0, "G329: Do not use xrange. Use range, or six.moves.range for "
"large loops.")
@core.flake8ext
def no_log_warn(logical_line):
"""Disallow 'LOG.warn('

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import builtins
import os
import eventlet
@ -36,8 +37,7 @@ glance.async_.set_threadpool_model('eventlet')
# See http://code.google.com/p/python-nose/issues/detail?id=373
# The code below enables tests to work with i18n _() blocks
import six.moves.builtins as __builtin__
setattr(__builtin__, '_', lambda x: x)
setattr(builtins, '_', lambda x: x)
# Set up logging to output debugging
import logging

View File

@ -17,12 +17,12 @@
import copy
import datetime
import functools
from unittest import mock
import uuid
from oslo_db import exception as db_exception
from oslo_db.sqlalchemy import utils as sqlalchemyutils
from six.moves import reduce
from sqlalchemy.dialects import sqlite
from glance.common import exception
@ -1508,14 +1508,18 @@ class DriverQuotaTests(test_utils.BaseTestCase):
self.db_api.image_create(self.context1, fixture)
def test_storage_quota(self):
total = reduce(lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures])
total = functools.reduce(
lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures],
)
x = self.db_api.user_get_storage_usage(self.context1, self.owner_id1)
self.assertEqual(total, x)
def test_storage_quota_without_image_id(self):
total = reduce(lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures])
total = functools.reduce(
lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures],
)
total = total - self.owner1_fixtures[0]['size']
x = self.db_api.user_get_storage_usage(
self.context1, self.owner_id1,
@ -1534,8 +1538,10 @@ class DriverQuotaTests(test_utils.BaseTestCase):
'status': 'active'})
self.db_api.image_create(self.context1, new_fixture)
total = reduce(lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures]) + (sz * 2)
total = functools.reduce(
lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures],
) + (sz * 2)
x = self.db_api.user_get_storage_usage(self.context1, self.owner_id1)
self.assertEqual(total, x)
@ -1555,8 +1561,10 @@ class DriverQuotaTests(test_utils.BaseTestCase):
'status': 'active'})
self.db_api.image_create(self.context1, new_fixture)
total = reduce(lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures])
total = functools.reduce(
lambda x, y: x + y,
[f['size'] for f in self.owner1_fixtures],
)
x = self.db_api.user_get_storage_usage(self.context1, self.owner_id1)
self.assertEqual(total + (sz * 2), x)

View File

@ -90,14 +90,6 @@ class HackingTestCase(utils.BaseTestCase):
self.assertEqual(0, len(list(checks.dict_constructor_with_list_copy(
" self._render_dict(xml, data_el, data.__dict__)"))))
def test_check_python3_xrange(self):
func = checks.check_python3_xrange
self.assertEqual(1, len(list(func('for i in xrange(10)'))))
self.assertEqual(1, len(list(func('for i in xrange (10)'))))
self.assertEqual(0, len(list(func('for i in range(10)'))))
self.assertEqual(0, len(list(func('for i in six.moves.range(10)'))))
self.assertEqual(0, len(list(func('testxrange(10)'))))
def test_no_log_warn(self):
code = """
LOG.warn("LOG.warn is deprecated")

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import http.client as http
import io
from unittest import mock
@ -23,7 +24,6 @@ import uuid
import fixtures
from oslo_serialization import jsonutils
from six import moves
import webob
from glance.cmd import replicator as glance_replicator
@ -306,7 +306,7 @@ def get_image_service():
def check_no_args(command, args):
options = moves.UserDict()
options = collections.UserDict()
no_args_error = False
orig_img_service = glance_replicator.get_image_service
@ -323,7 +323,7 @@ def check_no_args(command, args):
def check_bad_args(command, args):
options = moves.UserDict()
options = collections.UserDict()
bad_args_error = False
orig_img_service = glance_replicator.get_image_service
@ -351,7 +351,7 @@ class ReplicationCommandsTestCase(test_utils.BaseTestCase):
self.assertEqual(2, mock_lookup_command.call_count)
def test_replication_size(self):
options = moves.UserDict()
options = collections.UserDict()
options.targettoken = 'targettoken'
args = ['localhost:9292']
@ -405,7 +405,7 @@ class ReplicationCommandsTestCase(test_utils.BaseTestCase):
def test_replication_dump(self):
tempdir = self.useFixture(fixtures.TempDir()).path
options = moves.UserDict()
options = collections.UserDict()
options.chunksize = 4096
options.sourcetoken = 'sourcetoken'
options.metaonly = False
@ -492,7 +492,7 @@ class ReplicationCommandsTestCase(test_utils.BaseTestCase):
f.write(jsonutils.dumps([1, 2, 3, 4, 5]))
# Finally, we're ready to test
options = moves.UserDict()
options = collections.UserDict()
options.dontreplicate = 'dontrepl dontreplabsent'
options.targettoken = 'targettoken'
args = ['localhost:9292', tempdir]
@ -520,7 +520,7 @@ class ReplicationCommandsTestCase(test_utils.BaseTestCase):
self.assertTrue(check_bad_args(command, args))
def test_replication_livecopy(self):
options = moves.UserDict()
options = collections.UserDict()
options.chunksize = 4096
options.dontreplicate = 'dontrepl dontreplabsent'
options.sourcetoken = 'livesourcetoken'
@ -548,7 +548,7 @@ class ReplicationCommandsTestCase(test_utils.BaseTestCase):
self.assertTrue(check_bad_args(command, args))
def test_replication_compare(self):
options = moves.UserDict()
options = collections.UserDict()
options.chunksize = 4096
options.dontreplicate = 'dontrepl dontreplabsent'
options.sourcetoken = 'livesourcetoken'

View File

@ -146,7 +146,6 @@ extension =
G319 = checks:no_translate_debug_logs
G327 = checks:check_no_contextlib_nested
G328 = checks:dict_constructor_with_list_copy
G329 = checks:check_python3_xrange
G330 = checks:no_log_warn
paths = ./glance/hacking