Merge "fixture: Drop use of OrderedDict for Python compat"
This commit is contained in:
commit
dabebb5bf1
@ -26,6 +26,7 @@ import copy
|
||||
import datetime
|
||||
import inspect
|
||||
import logging
|
||||
from reprlib import recursive_repr
|
||||
from unittest import mock
|
||||
|
||||
import fixtures
|
||||
@ -101,6 +102,22 @@ def compare_obj(test, obj, db_obj, subs=None, allow_missing=None,
|
||||
test.assertEqual(db_val, obj_val)
|
||||
|
||||
|
||||
class OsloOrderedDict(OrderedDict):
|
||||
"""Oslo version of OrderedDict for Python consistency."""
|
||||
|
||||
@recursive_repr()
|
||||
def __repr__(self):
|
||||
if not self:
|
||||
return '%s()' % self.__class__.__bases__[0].__name__
|
||||
# NOTE(jamespage):
|
||||
# Python >= 3.12 uses a dict instead of a list which changes the
|
||||
# repr of the versioned object and its associated hash value
|
||||
# Switch back to using list an use super class name.
|
||||
return '%s(%r)' % (
|
||||
self.__class__.__bases__[0].__name__, list(self.items())
|
||||
)
|
||||
|
||||
|
||||
class FakeIndirectionAPI(base.VersionedObjectIndirectionAPI):
|
||||
def __init__(self, serializer=None):
|
||||
super(FakeIndirectionAPI, self).__init__()
|
||||
@ -263,7 +280,7 @@ class ObjectVersionChecker(object):
|
||||
# and return value changes, for example).
|
||||
if hasattr(obj_class, 'child_versions'):
|
||||
relevant_data = (obj_fields, methods,
|
||||
OrderedDict(
|
||||
OsloOrderedDict(
|
||||
sorted(obj_class.child_versions.items())))
|
||||
else:
|
||||
relevant_data = (obj_fields, methods)
|
||||
|
@ -12,7 +12,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
import copy
|
||||
import datetime
|
||||
import hashlib
|
||||
@ -565,8 +564,9 @@ class TestObjectVersionChecker(test.TestCase):
|
||||
exp_fields = sorted(list(MyObject.fields.items()))
|
||||
exp_methods = sorted([('remotable_method', argspec),
|
||||
('remotable_classmethod', argspec)])
|
||||
exp_child_versions = collections.OrderedDict(sorted(
|
||||
child_versions.items()))
|
||||
exp_child_versions = fixture.OsloOrderedDict(
|
||||
sorted(child_versions.items())
|
||||
)
|
||||
exp_relevant_data = (exp_fields, exp_methods, exp_child_versions)
|
||||
|
||||
# NOTE(hberaud) the following hashlib usage will emit a bandit
|
||||
|
Loading…
Reference in New Issue
Block a user