Fix deprecation warnings

This addresses a couple sources of deprecation warnings in the code.

The collections package has moved abstract base classes from
collections.* to collections.abc.*. Use of the old path causes
DeprecationWarning messages now, but will eventually be removed. Six
does not support this yet, so for now just try the newer preferred path
and fall back to the old path if the import fails.

This also addresses unit test deprecation methods with self.skip()
changing to self.skipTest().

Change-Id: I0463ab2109adeee6468261f9e96225766a55998e
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2019-04-09 15:18:14 -05:00
parent ca9dec1ad6
commit 37473e3afa
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
2 changed files with 15 additions and 8 deletions

View File

@ -13,7 +13,14 @@
# under the License.
import abc
import collections
# TODO(smcginnis) update this once six has support for collections.abc
# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7.
try:
from collections.abc import Iterable
from collections.abc import Mapping
except ImportError:
from collections import Iterable
from collections import Mapping
import datetime
from distutils import versionpredicate
import re
@ -625,14 +632,14 @@ class IPV6Network(IPNetwork):
'fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|'
# ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255
'::(ffff(:0{1,4}){0,1}:){0,1}'
'(' + ipv4seg + '\.){3,3}' +
'(' + ipv4seg + r'\.){3,3}' +
ipv4seg + '|'
# 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33
'(' + ipv6seg + ':){1,4}:'
'(' + ipv4seg + '\.){3,3}' +
'(' + ipv4seg + r'\.){3,3}' +
ipv4seg +
# /128
'(\/(d|dd|1[0-1]d|12[0-8]))$'
r'(\/(d|dd|1[0-1]d|12[0-8]))$'
)
@ -644,8 +651,8 @@ class CompoundFieldType(FieldType):
class List(CompoundFieldType):
def coerce(self, obj, attr, value):
if (not isinstance(value, collections.Iterable) or
isinstance(value, six.string_types + (collections.Mapping,))):
if (not isinstance(value, Iterable) or
isinstance(value, six.string_types + (Mapping,))):
raise ValueError(_('A list is required in field %(attr)s, '
'not a %(type)s') %
{'attr': attr, 'type': type(value).__name__})

View File

@ -1080,7 +1080,7 @@ class _TestObject(object):
set(TestSubclassedObject.fields.keys()))
def test_obj_as_admin(self):
self.skip('oslo.context does not support elevated()')
self.skipTest('oslo.context does not support elevated()')
obj = MyObj(context=self.context)
def fake(*args, **kwargs):
@ -1740,7 +1740,7 @@ class TestObjectListBase(test.TestCase):
list_obj_class.__name__))
def test_object_version_mappings(self):
self.skip('this needs to be generalized')
self.skipTest('this needs to be generalized')
# Find all object list classes and make sure that they at least handle
# all the current object versions
for obj_classes in base.VersionedObjectRegistry.obj_classes().values():