Commit 2124e9a7 authored by Jérome Perrin's avatar Jérome Perrin

ProcessingNodeTestCase: python3 compatibility for DictPersistentWrapper

parent c78c9aff
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import abc
import errno, logging, mock, os, socket, time import errno, logging, mock, os, socket, time
import itertools import itertools
from threading import Thread from threading import Thread
from UserDict import IterableUserDict import six
if six.PY2:
from UserDict import IterableUserDict as UserDict
else:
from collections import UserDict
import Lifetime import Lifetime
import transaction import transaction
from Testing import ZopeTestCase from Testing import ZopeTestCase
...@@ -16,9 +21,8 @@ from Products.ERP5Type.tests.utils import \ ...@@ -16,9 +21,8 @@ from Products.ERP5Type.tests.utils import \
from Products.CMFActivity.ActivityTool import getCurrentNode from Products.CMFActivity.ActivityTool import getCurrentNode
class DictPersistentWrapper(IterableUserDict, object): class DictPersistentWrapperMetaClass(abc.ABCMeta):
def __new__(cls, name, base, d):
def __metaclass__(name, base, d):
def wrap(attr): def wrap(attr):
wrapped = getattr(base[0], attr) wrapped = getattr(base[0], attr)
def wrapper(self, *args, **kw): def wrapper(self, *args, **kw):
...@@ -28,7 +32,12 @@ class DictPersistentWrapper(IterableUserDict, object): ...@@ -28,7 +32,12 @@ class DictPersistentWrapper(IterableUserDict, object):
return wrapper return wrapper
for attr in ('clear', 'setdefault', 'update', '__setitem__', '__delitem__'): for attr in ('clear', 'setdefault', 'update', '__setitem__', '__delitem__'):
d[attr] = wrap(attr) d[attr] = wrap(attr)
return type(name, base, d) return super(
DictPersistentWrapperMetaClass, cls).__new__(cls, name, base, d)
@six.add_metaclass(DictPersistentWrapperMetaClass)
class DictPersistentWrapper(UserDict, object):
def __init__(self, dict, persistent_object): def __init__(self, dict, persistent_object):
self.data = dict self.data = dict
...@@ -172,7 +181,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -172,7 +181,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
s.listen(0) s.listen(0)
except socket.error as e: except socket.error as e:
s.close() s.close()
if e[0] != errno.EADDRINUSE: if e.args[0] != errno.EADDRINUSE:
raise raise
if zserver: if zserver:
raise RuntimeError(str(e)) raise RuntimeError(str(e))
...@@ -337,7 +346,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -337,7 +346,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
This aborts current transaction. This aborts current transaction.
""" """
for i in xrange(60): for i in range(60):
node_list = list(self.portal.portal_activities.getProcessingNodeList()) node_list = list(self.portal.portal_activities.getProcessingNodeList())
if len(node_list) >= node_count: if len(node_list) >= node_count:
node_list.remove(getCurrentNode()) node_list.remove(getCurrentNode())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment