From 1431f6969c98f198cd91c17005afd0346cf0934d Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Sat, 15 Apr 2023 14:32:10 +0200 Subject: [PATCH] chore: black --- setup.py | 53 ++- src/plone/__init__.py | 2 +- src/plone/folder/default.py | 53 +-- src/plone/folder/interfaces.py | 62 +-- src/plone/folder/nogopip.py | 38 +- src/plone/folder/ordered.py | 91 ++-- src/plone/folder/partial.py | 53 +-- src/plone/folder/testing.py | 7 +- src/plone/folder/tests/benchmarks.py | 6 +- src/plone/folder/tests/test_dict_interface.py | 72 +-- src/plone/folder/tests/test_integration.py | 17 +- .../folder/tests/test_ordering_adapters.py | 10 +- src/plone/folder/tests/test_ordersupport.py | 416 +++++++++--------- .../folder/tests/test_partialordering.py | 325 +++++++------- .../folder/tests/test_unorderedordering.py | 38 +- src/plone/folder/tests/test_webdav.py | 25 +- src/plone/folder/tests/utils.py | 5 +- src/plone/folder/unordered.py | 2 +- 18 files changed, 631 insertions(+), 644 deletions(-) diff --git a/setup.py b/setup.py index 32b90b4..dfeee90 100644 --- a/setup.py +++ b/setup.py @@ -2,14 +2,13 @@ from setuptools import setup -version = '3.1.1.dev0' +version = "3.1.1.dev0" setup( - name='plone.folder', + name="plone.folder", version=version, - description='BTree-based folder implementation with order support', - long_description=(open("README.rst").read() + "\n" + - open("CHANGES.rst").read()), + description="BTree-based folder implementation with order support", + long_description=(open("README.rst").read() + "\n" + open("CHANGES.rst").read()), classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", @@ -29,33 +28,33 @@ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", ], - keywords='folder btree order', - author='Plone Foundation', - author_email='plone-developers@lists.sourceforge.net', - url='https://pypi.org/project/plone.folder', - license='GPL version 2', - packages=find_packages('src'), - package_dir={'': 'src'}, - namespace_packages=['plone'], + keywords="folder btree order", + author="Plone Foundation", + author_email="plone-developers@lists.sourceforge.net", + url="https://pypi.org/project/plone.folder", + license="GPL version 2", + packages=find_packages("src"), + package_dir={"": "src"}, + namespace_packages=["plone"], include_package_data=True, - platforms='Any', + platforms="Any", zip_safe=False, install_requires=[ - 'plone.memoize', - 'Products.BTreeFolder2', - 'Products.CMFCore', - 'Products.ZCatalog', - 'setuptools', - 'six', - 'zope.annotation', - 'zope.component', - 'zope.container', - 'zope.interface', - 'Zope2', + "plone.memoize", + "Products.BTreeFolder2", + "Products.CMFCore", + "Products.ZCatalog", + "setuptools", + "six", + "zope.annotation", + "zope.component", + "zope.container", + "zope.interface", + "Zope2", ], extras_require={ - 'test': [ - 'profilehooks', + "test": [ + "profilehooks", ] }, ) diff --git a/src/plone/__init__.py b/src/plone/__init__.py index de40ea7..5284146 100644 --- a/src/plone/__init__.py +++ b/src/plone/__init__.py @@ -1 +1 @@ -__import__('pkg_resources').declare_namespace(__name__) +__import__("pkg_resources").declare_namespace(__name__) diff --git a/src/plone/folder/default.py b/src/plone/folder/default.py index 7294f66..57c4d90 100644 --- a/src/plone/folder/default.py +++ b/src/plone/folder/default.py @@ -13,8 +13,8 @@ @implementer(IExplicitOrdering) @adapter(IOrderableFolder) class DefaultOrdering: - """ This implementation uses annotations to store the order on the - object, and supports explicit ordering. """ + """This implementation uses annotations to store the order on the + object, and supports explicit ordering.""" ORDER_KEY = "plone.folder.ordered.order" POS_KEY = "plone.folder.ordered.pos" @@ -23,14 +23,14 @@ def __init__(self, context): self.context = context def notifyAdded(self, obj_id): - """ see interfaces.py """ + """see interfaces.py""" order = self._order(True) pos = self._pos(True) order.append(obj_id) pos[obj_id] = len(order) - 1 def notifyRemoved(self, obj_id): - """ see interfaces.py """ + """see interfaces.py""" order = self._order() pos = self._pos() try: @@ -43,14 +43,8 @@ def notifyRemoved(self, obj_id): for count, obj_id in enumerate(order): pos[obj_id] = count - def moveObjectsByDelta( - self, - ids, - delta, - subset_ids=None, - suppress_events=False - ): - """ see interfaces.py """ + def moveObjectsByDelta(self, ids, delta, subset_ids=None, suppress_events=False): + """see interfaces.py""" order = self._order() pos = self._pos() min_position = 0 @@ -60,7 +54,7 @@ def moveObjectsByDelta( subset_ids = self.idsInOrder() elif not isinstance(subset_ids, list): subset_ids = list(subset_ids) - if delta > 0: # unify moving direction + if delta > 0: # unify moving direction ids = reversed(ids) subset_ids.reverse() counter = 0 @@ -93,41 +87,37 @@ def moveObjectsByDelta( pos[obj_id] = i idx += 1 except KeyError: - raise ValueError( - f'No object with id "{obj_id:s}" exists.' - ) + raise ValueError(f'No object with id "{obj_id:s}" exists.') if not suppress_events: notifyContainerModified(self.context) return counter def moveObjectsUp(self, ids, delta=1, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, -delta, subset_ids) def moveObjectsDown(self, ids, delta=1, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, delta, subset_ids) def moveObjectsToTop(self, ids, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, -len(self._order()), subset_ids) def moveObjectsToBottom(self, ids, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, len(self._order()), subset_ids) def moveObjectToPosition(self, obj_id, position, suppress_events=False): - """ see interfaces.py """ + """see interfaces.py""" delta = position - self.getObjectPosition(obj_id) if delta: return self.moveObjectsByDelta( - obj_id, - delta, - suppress_events=suppress_events + obj_id, delta, suppress_events=suppress_events ) def orderObjects(self, key=None, reverse=None): - """ see interfaces.py """ + """see interfaces.py""" if key is None and not reverse: return -1 order = self._order() @@ -137,11 +127,13 @@ def orderObjects(self, key=None, reverse=None): # Simply reverse the current ordering. order.reverse() else: + def keyfn(obj_id): attr = getattr(self.context._getOb(obj_id), key) if callable(attr): return attr() return attr + # order.sort(cmd=None, key=keyfn, reverse=bool(reverse)) order = sorted(order, key=keyfn, reverse=bool(reverse)) self._set_order(order) @@ -150,15 +142,18 @@ def keyfn(obj_id): return -1 def getObjectPosition(self, obj_id): - """ see interfaces.py """ + """see interfaces.py""" pos = self._pos() if obj_id in pos: return pos[obj_id] - raise ValueError('No object with id "{:s}" exists in "{:s}".'.format( - obj_id, '/'.join(self.context.getPhysicalPath()))) + raise ValueError( + 'No object with id "{:s}" exists in "{:s}".'.format( + obj_id, "/".join(self.context.getPhysicalPath()) + ) + ) def idsInOrder(self): - """ see interfaces.py """ + """see interfaces.py""" return list(self._order()) def __getitem__(self, index): diff --git a/src/plone/folder/interfaces.py b/src/plone/folder/interfaces.py index 2a73a21..d3aab8d 100644 --- a/src/plone/folder/interfaces.py +++ b/src/plone/folder/interfaces.py @@ -2,73 +2,73 @@ class IOrderable(Interface): - """ Marker interface for orderable portal content """ + """Marker interface for orderable portal content""" class IFolder(Interface): - """ Marker interface for Plone-like folders """ + """Marker interface for Plone-like folders""" class IOrderableFolder(IFolder): - """ A Plone-like folder with ordering support """ + """A Plone-like folder with ordering support""" def getOrdering(): - """ return the currently active ordering adapter for this folder """ + """return the currently active ordering adapter for this folder""" - def setOrdering(ordering=''): - """ (re)set ordering adapter to be used for this folder """ + def setOrdering(ordering=""): + """(re)set ordering adapter to be used for this folder""" class IOrdering(Interface): - """ An adapter providing ordering operations on its context folder. + """An adapter providing ordering operations on its context folder. - The OrderedBTreeFolderBase mix-in class will adapt self (the - folder) to this interface when trying to get object position or - find the order of items. There is a default implementation, but - you can provide a different policy. + The OrderedBTreeFolderBase mix-in class will adapt self (the + folder) to this interface when trying to get object position or + find the order of items. There is a default implementation, but + you can provide a different policy. - Your adapter (which should still adapt to IOrdered) can - optionally provide IExplicitOrdering, defined below. This is - used to support explicit ordering, e.g. through a UI. """ + Your adapter (which should still adapt to IOrdered) can + optionally provide IExplicitOrdering, defined below. This is + used to support explicit ordering, e.g. through a UI.""" def notifyAdded(obj_id): - """ Inform the ordering implementation that an item was added """ + """Inform the ordering implementation that an item was added""" def notifyRemoved(obj_id): - """ Inform the ordering implementation that an item was removed """ + """Inform the ordering implementation that an item was removed""" def getObjectPosition(obj_id): - """ Get the position of the given object id """ + """Get the position of the given object id""" def idsInOrder(): - """ Return all object ids, in the correct order """ + """Return all object ids, in the correct order""" class IExplicitOrdering(IOrdering): - """ An adapter allowing explicit ordering """ + """An adapter allowing explicit ordering""" def moveObjectsByDelta(ids, delta, subset_ids=None, suppress_events=False): - """ Move the specified ids (a sequence, or a single string id) - by the given delta (a positive or negative number). By - default, this moves the objects within the whole set of - sub-items in the context container, but if subset_ids is - specified, it gives a subset of ids to consider. - Should return the number of objects that changed position. """ + """Move the specified ids (a sequence, or a single string id) + by the given delta (a positive or negative number). By + default, this moves the objects within the whole set of + sub-items in the context container, but if subset_ids is + specified, it gives a subset of ids to consider. + Should return the number of objects that changed position.""" def moveObjectsUp(ids, delta=1, subset_ids=None): - """ Move specified sub-objects up by delta in container. """ + """Move specified sub-objects up by delta in container.""" def moveObjectsDown(ids, delta=1, subset_ids=None): - """ Move specified sub-objects down by delta in container. """ + """Move specified sub-objects down by delta in container.""" def moveObjectsToTop(ids, subset_ids=None): - """ Move specified sub-objects to top of container. """ + """Move specified sub-objects to top of container.""" def moveObjectsToBottom(ids, subset_ids=None): - """ Move specified sub-objects to bottom of container. """ + """Move specified sub-objects to bottom of container.""" def moveObjectToPosition(obj_id, position, suppress_events=False): - """ Move specified object to absolute position. """ + """Move specified object to absolute position.""" def orderObjects(key, reverse=None): - """ Order sub-objects by key and direction. """ + """Order sub-objects by key and direction.""" diff --git a/src/plone/folder/nogopip.py b/src/plone/folder/nogopip.py index c800657..d8b25f4 100644 --- a/src/plone/folder/nogopip.py +++ b/src/plone/folder/nogopip.py @@ -20,7 +20,7 @@ def traverse(base, path): returns: content at the end or None """ current = base - for cid in path.split('/'): + for cid in path.split("/"): if not cid: continue try: @@ -32,7 +32,7 @@ def traverse(base, path): @implementer(IPluggableIndex) class StubIndex(SimpleItem): - """ stub catalog index doing nothing """ + """stub catalog index doing nothing""" def __init__(self, id, *args, **kw): self.id = id @@ -64,10 +64,10 @@ def clear(self): @implementer(ISortIndex) class GopipIndex(StubIndex): - """ fake index for sorting against `getObjPositionInParent` """ + """fake index for sorting against `getObjPositionInParent`""" - meta_type = 'GopipIndex' - manage_options = dict(label='Settings', action='manage_main'), + meta_type = "GopipIndex" + manage_options = (dict(label="Settings", action="manage_main"),) keyForDocument = 42 @@ -87,7 +87,7 @@ def documentToKeyMap(self): # results themselves. luckily this is only ever called from # `sortResults`, so we can get it form there. oh, and lurker # says this won't work in jython, though! :) - rs = currentframe().f_back.f_locals['rs'] + rs = currentframe().f_back.f_locals["rs"] rids = {} items = [] containers = {} @@ -95,17 +95,17 @@ def documentToKeyMap(self): root = getUtility(ISiteRoot).getPhysicalRoot() for rid in rs: path = getpath(rid) - parent, id = path.rsplit('/', 1) + parent, id = path.rsplit("/", 1) container = containers.get(parent) if container is None: containers[parent] = container = traverse(root, parent) - rids[id] = rid # remember in case of single folder + rids[id] = rid # remember in case of single folder items.append((rid, container, id)) # or else for deferred lookup pos = {} if len(containers) == 1: # the usual "all from one folder" case can be optimized folder = list(containers.values())[0] - if getattr(aq_base(folder), 'getOrdering', None): + if getattr(aq_base(folder), "getOrdering", None): ids = folder.getOrdering().idsInOrder() else: # site root or old folders @@ -117,7 +117,7 @@ def documentToKeyMap(self): return pos # otherwise the entire map needs to be constructed... for rid, container, id in items: - if getattr(aq_base(container), 'getObjectPosition', None): + if getattr(aq_base(container), "getObjectPosition", None): pos[rid] = container.getObjectPosition(id) else: # fallback for unordered folders @@ -125,21 +125,11 @@ def documentToKeyMap(self): return pos -manage_addGopipForm = DTMLFile('dtml/addGopipIndex', globals()) +manage_addGopipForm = DTMLFile("dtml/addGopipIndex", globals()) -def manage_addGopipIndex( - self, - identifier, - REQUEST=None, - RESPONSE=None, - URL3=None -): - """ add a fake gopip index """ +def manage_addGopipIndex(self, identifier, REQUEST=None, RESPONSE=None, URL3=None): + """add a fake gopip index""" return self.manage_addIndex( - identifier, - 'GopipIndex', - REQUEST=REQUEST, - RESPONSE=RESPONSE, - URL1=URL3 + identifier, "GopipIndex", REQUEST=REQUEST, RESPONSE=RESPONSE, URL1=URL3 ) diff --git a/src/plone/folder/ordered.py b/src/plone/folder/ordered.py index 65db8c8..72edf91 100644 --- a/src/plone/folder/ordered.py +++ b/src/plone/folder/ordered.py @@ -30,29 +30,29 @@ @implementer(IOrderedContainer, IOrderableFolder, IAttributeAnnotatable) class OrderedBTreeFolderBase(BTreeFolder2Base): - """ BTree folder base class with ordering support. The ordering - is done by a named adapter (to IOrdering), which makes the policy - changeable. """ + """BTree folder base class with ordering support. The ordering + is done by a named adapter (to IOrdering), which makes the policy + changeable.""" - _ordering = '' # name of adapter defining ordering policy + _ordering = "" # name of adapter defining ordering policy security = ClassSecurityInfo() def __bool__(self): - """ a folder is something, even if it's empty """ + """a folder is something, even if it's empty""" return True @security.protected(access_contents_information) def getOrdering(self): - """ return the currently active ordering adapter for this folder """ + """return the currently active ordering adapter for this folder""" adapter = queryAdapter(self, IOrdering, name=self._ordering) if adapter is None: adapter = getAdapter(self, IOrdering) return adapter @security.protected(manage_properties) - def setOrdering(self, ordering=''): - """ (re)set ordering adapter to be used for this folder """ + def setOrdering(self, ordering=""): + """(re)set ordering adapter to be used for this folder""" if ordering: # make sure the adapter exists... getAdapter(self, IOrdering, name=ordering) @@ -61,21 +61,21 @@ def setOrdering(self, ordering=''): # IObjectManager def _getOb(self, id, default=_marker): - """ Return the named object from the folder. """ + """Return the named object from the folder.""" try: return super()._getOb(id, default) except KeyError as e: raise AttributeError(e) def _setOb(self, id, object): - """ Store the named object in the folder. """ + """Store the named object in the folder.""" super()._setOb(id, object) - self.getOrdering().notifyAdded(id) # notify the ordering adapter + self.getOrdering().notifyAdded(id) # notify the ordering adapter def _delOb(self, id): - """ Remove the named object from the folder. """ + """Remove the named object from the folder.""" super()._delOb(id) - self.getOrdering().notifyRemoved(id) # notify the ordering adapter + self.getOrdering().notifyRemoved(id) # notify the ordering adapter def objectIds(self, spec=None, ordered=True): if not ordered: @@ -100,19 +100,20 @@ def objectItems(self, spec=None): # Returns a list of (id, subobject) tuples of the current object. # If 'spec' is specified, returns only objects whose meta_type match # 'spec' - return LazyMap(lambda id, _getOb=self._getOb: (id, _getOb(id)), - self.objectIds(spec)) + return LazyMap( + lambda id, _getOb=self._getOb: (id, _getOb(id)), self.objectIds(spec) + ) # IOrderSupport - mostly deprecated, use the adapter directly instead @security.protected(access_contents_information) def getObjectPosition(self, id): - """ Get the position of an object by its id. """ + """Get the position of an object by its id.""" return self.getOrdering().getObjectPosition(id) @security.protected(manage_properties) def moveObjectsUp(self, ids, delta=1, subset_ids=None): - """ Move specified sub-objects up by delta in container. """ + """Move specified sub-objects up by delta in container.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): return ordering.moveObjectsUp(ids, delta, subset_ids) @@ -121,7 +122,7 @@ def moveObjectsUp(self, ids, delta=1, subset_ids=None): @security.protected(manage_properties) def moveObjectsDown(self, ids, delta=1, subset_ids=None): - """ Move specified sub-objects down by delta in container. """ + """Move specified sub-objects down by delta in container.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): return ordering.moveObjectsDown(ids, delta, subset_ids) @@ -130,7 +131,7 @@ def moveObjectsDown(self, ids, delta=1, subset_ids=None): @security.protected(manage_properties) def moveObjectsToTop(self, ids, subset_ids=None): - """ Move specified sub-objects to top of container. """ + """Move specified sub-objects to top of container.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): return ordering.moveObjectsToTop(ids, subset_ids) @@ -139,7 +140,7 @@ def moveObjectsToTop(self, ids, subset_ids=None): @security.protected(manage_properties) def moveObjectsToBottom(self, ids, subset_ids=None): - """ Move specified sub-objects to bottom of container. """ + """Move specified sub-objects to bottom of container.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): return ordering.moveObjectsToBottom(ids, subset_ids) @@ -148,7 +149,7 @@ def moveObjectsToBottom(self, ids, subset_ids=None): @security.protected(ModifyPortalContent) def moveObject(self, id, position): - """ Move specified object to absolute position. """ + """Move specified object to absolute position.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): return ordering.moveObjectToPosition(id, position) @@ -157,7 +158,7 @@ def moveObject(self, id, position): @security.protected(manage_properties) def moveObjectToPosition(self, id, position, suppress_events=False): - """ Move specified object to absolute position. """ + """Move specified object to absolute position.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): return ordering.moveObjectToPosition(id, position, suppress_events) @@ -165,24 +166,17 @@ def moveObjectToPosition(self, id, position, suppress_events=False): return 0 @security.protected(manage_properties) - def moveObjectsByDelta( - self, ids, delta, subset_ids=None, suppress_events=False - ): - """ Move specified sub-objects by delta. """ + def moveObjectsByDelta(self, ids, delta, subset_ids=None, suppress_events=False): + """Move specified sub-objects by delta.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): - return ordering.moveObjectsByDelta( - ids, - delta, - subset_ids, - suppress_events - ) + return ordering.moveObjectsByDelta(ids, delta, subset_ids, suppress_events) else: return 0 @security.protected(manage_properties) def orderObjects(self, key=None, reverse=None): - """ Order sub-objects by key and direction. """ + """Order sub-objects by key and direction.""" ordering = self.getOrdering() if IExplicitOrdering.providedBy(ordering): return ordering.orderObjects(key, reverse) @@ -195,19 +189,15 @@ def iterkeys(self): return iter(self.objectIds()) def manage_renameObject(self, id, new_id, REQUEST=None): - """ Rename a particular sub-object without changing its position. """ + """Rename a particular sub-object without changing its position.""" old_position = self.getObjectPosition(id) - result = super().manage_renameObject( - id, - new_id, - REQUEST - ) + result = super().manage_renameObject(id, new_id, REQUEST) if old_position is None: return result self.moveObjectToPosition(new_id, old_position, suppress_events=True) - reindex = getattr(self._getOb(new_id), 'reindexObject', None) + reindex = getattr(self._getOb(new_id), "reindexObject", None) if reindex is not None: - reindex(idxs=['getObjPositionInParent']) + reindex(idxs=["getObjPositionInParent"]) return result # Dict interface @@ -227,11 +217,14 @@ def __getitem__(self, key): return value # WebDAV PUT support - if hasattr(self, 'REQUEST'): + if hasattr(self, "REQUEST"): request = self.REQUEST - method = request.get('REQUEST_METHOD', 'GET') - if (HAS_WEBDAV and getattr(request, 'maybe_webdav_client', False) - and method not in ('GET', 'POST')): + method = request.get("REQUEST_METHOD", "GET") + if ( + HAS_WEBDAV + and getattr(request, "maybe_webdav_client", False) + and method not in ("GET", "POST") + ): return NullResource(self, key, request).__of__(self) raise KeyError(key) @@ -242,11 +235,11 @@ def __getitem__(self, key): class CMFOrderedBTreeFolderBase(OrderedBTreeFolderBase, PortalFolderBase): - """ BTree folder for CMF sites, with ordering support. The ordering - is done by adapter (to IOrdering), which makes the policy - changeable. """ + """BTree folder for CMF sites, with ordering support. The ordering + is done by adapter (to IOrdering), which makes the policy + changeable.""" - def __init__(self, id, title=''): + def __init__(self, id, title=""): PortalFolderBase.__init__(self, id, title) BTreeFolder2Base.__init__(self, id) diff --git a/src/plone/folder/partial.py b/src/plone/folder/partial.py index 17cae95..0ae54c2 100644 --- a/src/plone/folder/partial.py +++ b/src/plone/folder/partial.py @@ -9,14 +9,15 @@ import six -ORDER_ATTR = '_objectordering' +ORDER_ATTR = "_objectordering" @implementer(IExplicitOrdering) class PartialOrdering: - """ this implementation uses a list to store order information on a - regular attribute of the folderish object; explicit ordering - is supported """ + """this implementation uses a list to store order information on a + regular attribute of the folderish object; explicit ordering + is supported""" + adapts(IOrderableFolder) def __init__(self, context): @@ -38,24 +39,24 @@ def order(self, value): setattr(context, ORDER_ATTR, value) def notifyAdded(self, id): - """ see interfaces.py """ + """see interfaces.py""" assert not id in self.order context = aq_base(self.context) obj = context._getOb(id) if IOrderable.providedBy(obj): self.order.append(id) - self.context._p_changed = True # the order was changed + self.context._p_changed = True # the order was changed def notifyRemoved(self, id): - """ see interfaces.py """ + """see interfaces.py""" try: self.order.remove(id) - self.context._p_changed = True # the order was changed - except ValueError: # removing non-orderable items is okay + self.context._p_changed = True # the order was changed + except ValueError: # removing non-orderable items is okay pass def idsInOrder(self, onlyOrderables=False): - """ see interfaces.py """ + """see interfaces.py""" ordered = list(self.order) ordered_set = set(ordered) if not onlyOrderables: @@ -65,9 +66,8 @@ def idsInOrder(self, onlyOrderables=False): ordered.append(id) return ordered - def moveObjectsByDelta(self, ids, delta, subset_ids=None, - suppress_events=False): - """ see interfaces.py """ + def moveObjectsByDelta(self, ids, delta, subset_ids=None, suppress_events=False): + """see interfaces.py""" min_position = 0 if isinstance(ids, str): ids = [ids] @@ -75,7 +75,7 @@ def moveObjectsByDelta(self, ids, delta, subset_ids=None, subset_ids = self.idsInOrder(onlyOrderables=True) elif not isinstance(subset_ids, list): subset_ids = list(subset_ids) - if delta > 0: # unify moving direction + if delta > 0: # unify moving direction ids = reversed(ids) subset_ids.reverse() counter = 0 @@ -106,38 +106,39 @@ def moveObjectsByDelta(self, ids, delta, subset_ids=None, except KeyError: raise ValueError('No object with id "%s" exists.' % id) if idx > 0: - self.context._p_changed = True # the order was changed + self.context._p_changed = True # the order was changed if not suppress_events: notifyContainerModified(self.context) return counter def moveObjectsUp(self, ids, delta=1, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, -delta, subset_ids) def moveObjectsDown(self, ids, delta=1, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, delta, subset_ids) def moveObjectsToTop(self, ids, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, -len(self.order), subset_ids) def moveObjectsToBottom(self, ids, subset_ids=None): - """ see interfaces.py """ + """see interfaces.py""" return self.moveObjectsByDelta(ids, len(self.order), subset_ids) def moveObjectToPosition(self, id, position, suppress_events=False): - """ see interfaces.py """ + """see interfaces.py""" old_position = self.getObjectPosition(id) if old_position is not None: delta = position - old_position if delta: - return self.moveObjectsByDelta(id, delta, - suppress_events=suppress_events) + return self.moveObjectsByDelta( + id, delta, suppress_events=suppress_events + ) def orderObjects(self, key=None, reverse=None): - """ see interfaces.py """ + """see interfaces.py""" if key is None: if not reverse: return -1 @@ -145,17 +146,19 @@ def orderObjects(self, key=None, reverse=None): # Simply reverse the current ordering. self.order.reverse() else: + def keyfn(id): attr = getattr(self.context._getOb(id), key) if callable(attr): return attr() return attr + self.order = sorted(self.order, key=keyfn, reverse=bool(reverse)) - self.context._p_changed = True # the order was changed + self.context._p_changed = True # the order was changed return -1 def getObjectPosition(self, id): - """ see interfaces.py """ + """see interfaces.py""" try: # using `index` here might not be that efficient for very large # lists, but the idea behind this adapter is to use it when the diff --git a/src/plone/folder/testing.py b/src/plone/folder/testing.py index 4afd1ac..9927242 100644 --- a/src/plone/folder/testing.py +++ b/src/plone/folder/testing.py @@ -7,7 +7,6 @@ class PloneFolderLayer(PloneSandboxLayer): - defaultBases = (PLONE_FIXTURE,) def setUpZope(self, app, configurationContext): @@ -17,11 +16,9 @@ def setUpZope(self, app, configurationContext): PLONEFOLDER_FIXTURE = PloneFolderLayer() PLONEFOLDER_INTEGRATION_TESTING = IntegrationTesting( - bases=(PLONEFOLDER_FIXTURE,), - name='PloneFolderLayer:IntegrationTesting' + bases=(PLONEFOLDER_FIXTURE,), name="PloneFolderLayer:IntegrationTesting" ) PLONEFOLDER_FUNCTIONAL_TESTING = FunctionalTesting( - bases=(PLONEFOLDER_FIXTURE,), - name='PloneFolderLayer:FunctionalTesting' + bases=(PLONEFOLDER_FIXTURE,), name="PloneFolderLayer:FunctionalTesting" ) diff --git a/src/plone/folder/tests/benchmarks.py b/src/plone/folder/tests/benchmarks.py index 9ae703d..a788f58 100644 --- a/src/plone/folder/tests/benchmarks.py +++ b/src/plone/folder/tests/benchmarks.py @@ -12,20 +12,20 @@ class BenchmarkTests(TestCase): - layer = PloneFolderLayer def testDeleteSpeed(self): folder = OrderedBTreeFolderBase("f1") for idx in range(100000): - id = 'foo-%s' % idx - folder[id] = DummyObject(id, 'bar') + id = "foo-%s" % idx + folder[id] = DummyObject(id, "bar") last = reversed(folder.keys()[-100:]) @timecall def delete(): for id in last: del folder[id] + delete() diff --git a/src/plone/folder/tests/test_dict_interface.py b/src/plone/folder/tests/test_dict_interface.py index d71a7a7..489604e 100644 --- a/src/plone/folder/tests/test_dict_interface.py +++ b/src/plone/folder/tests/test_dict_interface.py @@ -7,38 +7,38 @@ class DictInterfaceTests(unittest.TestCase): - """ tests for dict style interface """ + """tests for dict style interface""" layer = PLONEFOLDER_INTEGRATION_TESTING def test_getitem(self): folder = OrderedBTreeFolderBase("f1") - foo = DummyObject('foo') - folder._setOb('foo', foo) - self.assertEqual(folder['foo'], foo) - self.assertEqual(folder.__getitem__('foo'), foo) - self.assertRaises(KeyError, folder.__getitem__, 'bar') + foo = DummyObject("foo") + folder._setOb("foo", foo) + self.assertEqual(folder["foo"], foo) + self.assertEqual(folder.__getitem__("foo"), foo) + self.assertRaises(KeyError, folder.__getitem__, "bar") def test_setitem(self): folder = OrderedBTreeFolderBase("f1") - foo = DummyObject('foo') - folder['foo'] = foo - self.assertEqual(folder._getOb('foo'), foo) + foo = DummyObject("foo") + folder["foo"] = foo + self.assertEqual(folder._getOb("foo"), foo) def test_contains(self): folder = OrderedBTreeFolderBase("f1") - folder._setOb('foo', DummyObject('foo')) - folder._setOb('bar', DummyObject('bar')) - self.assertTrue('foo' in folder) - self.assertTrue('bar' in folder) + folder._setOb("foo", DummyObject("foo")) + folder._setOb("bar", DummyObject("bar")) + self.assertTrue("foo" in folder) + self.assertTrue("bar" in folder) def test_delitem(self): folder = OrderedBTreeFolderBase("f1") - folder._setOb('foo', DummyObject('foo')) - folder._setOb('bar', DummyObject('bar')) + folder._setOb("foo", DummyObject("foo")) + folder._setOb("bar", DummyObject("bar")) self.assertEqual(len(folder.objectIds()), 2) - del folder['foo'] - del folder['bar'] + del folder["foo"] + del folder["bar"] self.assertEqual(len(folder.objectIds()), 0) def test_len_empty_folder(self): @@ -47,40 +47,40 @@ def test_len_empty_folder(self): def test_len_one_child(self): folder = OrderedBTreeFolderBase("f1") - folder['child'] = DummyObject('child') + folder["child"] = DummyObject("child") self.assertEqual(len(folder), 1) def test_to_verify_ticket_9120(self): folder = OrderedBTreeFolderBase("f1") - folder['ob1'] = ob1 = DummyObject('ob1') - folder['ob2'] = DummyObject('ob2') - folder['ob3'] = DummyObject('ob3') - folder['ob4'] = ob4 = DummyObject('ob4') - del folder['ob2'] - del folder['ob3'] - self.assertEqual(folder.keys(), ['ob1', 'ob4']) + folder["ob1"] = ob1 = DummyObject("ob1") + folder["ob2"] = DummyObject("ob2") + folder["ob3"] = DummyObject("ob3") + folder["ob4"] = ob4 = DummyObject("ob4") + del folder["ob2"] + del folder["ob3"] + self.assertEqual(folder.keys(), ["ob1", "ob4"]) self.assertEqual(list(map(aq_base, folder.values())), [ob1, ob4]) self.assertEqual([key in folder for key in folder], [True, True]) class RelatedToDictInterfaceTests(unittest.TestCase): - """ various tests which are related to the dict-like interface """ + """various tests which are related to the dict-like interface""" layer = PLONEFOLDER_INTEGRATION_TESTING def create(self): folder = OrderedBTreeFolderBase("f1") - folder._setOb('o1', DummyObject('o1', 'mt1')) - folder._setOb('o2', DummyObject('o2', 'mt2')) - folder._setOb('o3', DummyObject('o3', 'mt1')) - folder._setOb('o4', DummyObject('o4', 'mt2')) + folder._setOb("o1", DummyObject("o1", "mt1")) + folder._setOb("o2", DummyObject("o2", "mt2")) + folder._setOb("o3", DummyObject("o3", "mt1")) + folder._setOb("o4", DummyObject("o4", "mt2")) return folder def testObjectIdsWithSpec(self): folder = self.create() - self.assertEqual(['o1', 'o3'], folder.objectIds(spec='mt1')) - self.assertEqual(['o2', 'o4'], folder.objectIds(spec='mt2')) - folder.moveObjectsToTop(['o3']) - folder.moveObjectsDown(['o2']) - self.assertEqual(['o3', 'o1'], folder.objectIds(spec='mt1')) - self.assertEqual(['o4', 'o2'], folder.objectIds(spec='mt2')) + self.assertEqual(["o1", "o3"], folder.objectIds(spec="mt1")) + self.assertEqual(["o2", "o4"], folder.objectIds(spec="mt2")) + folder.moveObjectsToTop(["o3"]) + folder.moveObjectsDown(["o2"]) + self.assertEqual(["o3", "o1"], folder.objectIds(spec="mt1")) + self.assertEqual(["o4", "o2"], folder.objectIds(spec="mt2")) diff --git a/src/plone/folder/tests/test_integration.py b/src/plone/folder/tests/test_integration.py index 70ed18a..d4b3371 100644 --- a/src/plone/folder/tests/test_integration.py +++ b/src/plone/folder/tests/test_integration.py @@ -11,23 +11,22 @@ @implementer(IOrderable) class DummyFolder(OrderedBTreeFolderBase, Implicit): - """ we need to mix in acquisition """ + """we need to mix in acquisition""" - meta_type = 'DummyFolder' + meta_type = "DummyFolder" class IntegrationTests(unittest.TestCase): - layer = PLONEFOLDER_FUNCTIONAL_TESTING def testExportDoesntIncludeParent(self): - self.app = self.layer['app'] - self.app._setOb('foo', DummyFolder('foo')) + self.app = self.layer["app"] + self.app._setOb("foo", DummyFolder("foo")) foo = self.app.foo - foo['bar'] = DummyFolder('bar') - savepoint(optimistic=True) # savepoint assigns oids + foo["bar"] = DummyFolder("bar") + savepoint(optimistic=True) # savepoint assigns oids # now let's export to a buffer and check the objects... exp = BytesIO() self.app._p_jar.exportFile(foo.bar._p_oid, exp) - self.assertTrue(b'bar' in exp.getvalue()) - self.assertFalse(b'foo' in exp.getvalue()) + self.assertTrue(b"bar" in exp.getvalue()) + self.assertFalse(b"foo" in exp.getvalue()) diff --git a/src/plone/folder/tests/test_ordering_adapters.py b/src/plone/folder/tests/test_ordering_adapters.py index c12d7f7..6a4b174 100644 --- a/src/plone/folder/tests/test_ordering_adapters.py +++ b/src/plone/folder/tests/test_ordering_adapters.py @@ -8,7 +8,7 @@ class OrderingAdapterTests(unittest.TestCase): - """ tests regarding available ordering adapters """ + """tests regarding available ordering adapters""" layer = PLONEFOLDER_INTEGRATION_TESTING @@ -18,21 +18,21 @@ def testDefaultAdapter(self): def testUnorderedOrdering(self): folder = OrderedBTreeFolderBase() - folder._ordering = 'unordered' + folder._ordering = "unordered" self.assertTrue(isinstance(folder.getOrdering(), UnorderedOrdering)) def testUnknownOrdering(self): folder = OrderedBTreeFolderBase() - folder._ordering = 'foo' + folder._ordering = "foo" self.assertTrue(isinstance(folder.getOrdering(), DefaultOrdering)) def testSetOrdering(self): folder = OrderedBTreeFolderBase() - folder.setOrdering('unordered') + folder.setOrdering("unordered") self.assertTrue(isinstance(folder.getOrdering(), UnorderedOrdering)) folder.setOrdering() self.assertTrue(isinstance(folder.getOrdering(), DefaultOrdering)) def testSetUnknownOrdering(self): folder = OrderedBTreeFolderBase() - self.assertRaises(ComponentLookupError, folder.setOrdering, 'foo') + self.assertRaises(ComponentLookupError, folder.setOrdering, "foo") diff --git a/src/plone/folder/tests/test_ordersupport.py b/src/plone/folder/tests/test_ordersupport.py index 8a7208f..05f7ff5 100644 --- a/src/plone/folder/tests/test_ordersupport.py +++ b/src/plone/folder/tests/test_ordersupport.py @@ -16,16 +16,16 @@ def getId(self): class OFSOrderSupportTests(unittest.TestCase): - """ tests borrowed from OFS.tests.testOrderSupport """ + """tests borrowed from OFS.tests.testOrderSupport""" layer = PLONEFOLDER_INTEGRATION_TESTING def create(self): - folder = TestFolder('f1') - folder['o1'] = DummyObject('o1', 'mt1') - folder['o2'] = DummyObject('o2', 'mt2') - folder['o3'] = DummyObject('o3', 'mt1') - folder['o4'] = DummyObject('o4', 'mt2') + folder = TestFolder("f1") + folder["o1"] = DummyObject("o1", "mt1") + folder["o2"] = DummyObject("o2", "mt2") + folder["o3"] = DummyObject("o3", "mt1") + folder["o4"] = DummyObject("o4", "mt2") return folder # Test for ordering of basic methods @@ -39,38 +39,24 @@ def test_objectIdsOrdered(self): def test_objectValuesOrdered(self): folder = self.create() self.assertEqual( - ["o1", "o2", "o3", "o4"], - [x.id for x in folder.objectValues()] + ["o1", "o2", "o3", "o4"], [x.id for x in folder.objectValues()] ) folder.moveObjectsUp(("o2",), 1) self.assertEqual( - ["o2", "o1", "o3", "o4"], - [x.id for x in folder.objectValues()] + ["o2", "o1", "o3", "o4"], [x.id for x in folder.objectValues()] ) def test_objectItemsOrdered(self): folder = self.create() - self.assertEqual( - ["o1", "o2", "o3", "o4"], - [x for x, y in folder.objectItems()] - ) + self.assertEqual(["o1", "o2", "o3", "o4"], [x for x, y in folder.objectItems()]) folder.moveObjectsUp(("o2",), 1) - self.assertEqual( - ["o2", "o1", "o3", "o4"], - [x for x, y in folder.objectItems()] - ) + self.assertEqual(["o2", "o1", "o3", "o4"], [x for x, y in folder.objectItems()]) def test_iterkeys(self): folder = self.create() - self.assertEqual( - ["o1", "o2", "o3", "o4"], - [x for x in folder.keys()] - ) + self.assertEqual(["o1", "o2", "o3", "o4"], [x for x in folder.keys()]) folder.moveObjectsUp(("o2",), 1) - self.assertEqual( - ["o2", "o1", "o3", "o4"], - [x for x in folder.keys()] - ) + self.assertEqual(["o2", "o1", "o3", "o4"], [x for x in folder.keys()]) def test_iter(self): folder = self.create() @@ -80,11 +66,11 @@ def test_iter(self): def test_getitem(self): ordering = IOrdering(self.create()) - self.assertEqual(ordering[1], 'o2') - self.assertEqual(ordering[-1], 'o4') - self.assertEqual(ordering[1:2], ['o2']) - self.assertEqual(ordering[1:-1], ['o2', 'o3']) - self.assertEqual(ordering[1:], ['o2', 'o3', 'o4']) + self.assertEqual(ordering[1], "o2") + self.assertEqual(ordering[-1], "o4") + self.assertEqual(ordering[1:2], ["o2"]) + self.assertEqual(ordering[1:-1], ["o2", "o3"]) + self.assertEqual(ordering[1:], ["o2", "o3", "o4"]) # Tests borrowed from OFS.tests.testsOrderSupport @@ -92,271 +78,279 @@ def runTableTests(self, methodname, table): for args, order, rval in table: f = self.create() method = getattr(f, methodname) - if rval == 'ValueError': + if rval == "ValueError": self.assertRaises(ValueError, method, *args) else: self.assertEqual(method(*args), rval) self.assertEqual(f.objectIds(), order) def test_moveObjectsUp(self): - self.runTableTests('moveObjectsUp', - ( ( ( 'o4', 1 ), ['o1', 'o2', 'o4', 'o3'], 1 ) - , ( ( 'o4', 2 ), ['o1', 'o4', 'o2', 'o3'], 1 ) - , ( ( ('o1', 'o3'), 1 ), ['o1', 'o3', 'o2', 'o4'], 1 ) - , ( ( ('o1', 'o3'), 9 ), ['o1', 'o3', 'o2', 'o4'], 1 ) - , ( ( ('o2', 'o3'), 1 ), ['o2', 'o3', 'o1', 'o4'], 2 ) - , ( ( ('o2', 'o3'), 1, ('o1', 'o2', 'o3', 'o4') ), - ['o2', 'o3', 'o1', 'o4'], 2 ) - , ( ( ('o2', 'o3'), 1, ('o2', 'o3', 'o4') ), - ['o1', 'o2', 'o3', 'o4'], 0 ) - , ( ( ('n2', 'o3'), 1 ), ['o1', 'o3', 'o2', 'o4'], 1) - , ( ( ('o3', 'o1'), 1 ), ['o1', 'o3', 'o2', 'o4'], 1 ) - ) - ) + self.runTableTests( + "moveObjectsUp", + ( + (("o4", 1), ["o1", "o2", "o4", "o3"], 1), + (("o4", 2), ["o1", "o4", "o2", "o3"], 1), + ((("o1", "o3"), 1), ["o1", "o3", "o2", "o4"], 1), + ((("o1", "o3"), 9), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"), 1), ["o2", "o3", "o1", "o4"], 2), + ( + (("o2", "o3"), 1, ("o1", "o2", "o3", "o4")), + ["o2", "o3", "o1", "o4"], + 2, + ), + ((("o2", "o3"), 1, ("o2", "o3", "o4")), ["o1", "o2", "o3", "o4"], 0), + ((("n2", "o3"), 1), ["o1", "o3", "o2", "o4"], 1), + ((("o3", "o1"), 1), ["o1", "o3", "o2", "o4"], 1), + ), + ) def test_moveObjectsDown(self): - self.runTableTests('moveObjectsDown', - ( ( ( 'o1', 1 ), ['o2', 'o1', 'o3', 'o4'], 1 ) - , ( ( 'o1', 2 ), ['o2', 'o3', 'o1', 'o4'], 1 ) - , ( ( ('o2', 'o4'), 1 ), ['o1', 'o3', 'o2', 'o4'], 1 ) - , ( ( ('o2', 'o4'), 9 ), ['o1', 'o3', 'o2', 'o4'], 1 ) - , ( ( ('o2', 'o3'), 1 ), ['o1', 'o4', 'o2', 'o3'], 2 ) - , ( ( ('o2', 'o3'), 1, ('o1', 'o2', 'o3', 'o4') ), - ['o1', 'o4', 'o2', 'o3'], 2 ) - , ( ( ('o2', 'o3'), 1, ('o1', 'o2', 'o3') ), - ['o1', 'o2', 'o3', 'o4'], 0 ) - , ( ( ('n2', 'o3'), 1 ), ['o1', 'o2', 'o4', 'o3'], 1) - , ( ( ('o4', 'o2'), 1 ), ['o1', 'o3', 'o2', 'o4'], 1 ) - ) - ) + self.runTableTests( + "moveObjectsDown", + ( + (("o1", 1), ["o2", "o1", "o3", "o4"], 1), + (("o1", 2), ["o2", "o3", "o1", "o4"], 1), + ((("o2", "o4"), 1), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o4"), 9), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"), 1), ["o1", "o4", "o2", "o3"], 2), + ( + (("o2", "o3"), 1, ("o1", "o2", "o3", "o4")), + ["o1", "o4", "o2", "o3"], + 2, + ), + ((("o2", "o3"), 1, ("o1", "o2", "o3")), ["o1", "o2", "o3", "o4"], 0), + ((("n2", "o3"), 1), ["o1", "o2", "o4", "o3"], 1), + ((("o4", "o2"), 1), ["o1", "o3", "o2", "o4"], 1), + ), + ) def test_moveObjectsToTop(self): - self.runTableTests('moveObjectsToTop', - ( ( ( 'o4', ), ['o4', 'o1', 'o2', 'o3'], 1 ) - , ( ( ('o1', 'o3'), ), ['o1', 'o3', 'o2', 'o4'], 1 ) - , ( ( ('o2', 'o3'), ), ['o2', 'o3', 'o1', 'o4'], 2 ) - , ( ( ('o2', 'o3'), ('o1', 'o2', 'o3', 'o4') ), - ['o2', 'o3', 'o1', 'o4'], 2 ) - , ( ( ('o2', 'o3'), ('o2', 'o3', 'o4') ), - ['o1', 'o2', 'o3', 'o4'], 0 ) - , ( ( ('n2', 'o3'), ), ['o3', 'o1', 'o2', 'o4'], 1) - , ( ( ('o3', 'o1'), ), ['o3', 'o1', 'o2', 'o4'], 1 ) - ) - ) + self.runTableTests( + "moveObjectsToTop", + ( + (("o4",), ["o4", "o1", "o2", "o3"], 1), + ((("o1", "o3"),), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"),), ["o2", "o3", "o1", "o4"], 2), + ((("o2", "o3"), ("o1", "o2", "o3", "o4")), ["o2", "o3", "o1", "o4"], 2), + ((("o2", "o3"), ("o2", "o3", "o4")), ["o1", "o2", "o3", "o4"], 0), + ((("n2", "o3"),), ["o3", "o1", "o2", "o4"], 1), + ((("o3", "o1"),), ["o3", "o1", "o2", "o4"], 1), + ), + ) def test_moveObjectsToBottom(self): - self.runTableTests('moveObjectsToBottom', - ( ( ( 'o1', ), ['o2', 'o3', 'o4', 'o1'], 1 ) - , ( ( ('o2', 'o4'), ), ['o1', 'o3', 'o2', 'o4'], 1 ) - , ( ( ('o2', 'o3'), ), ['o1', 'o4', 'o2', 'o3'], 2 ) - , ( ( ('o2', 'o3'), ('o1', 'o2', 'o3', 'o4') ), - ['o1', 'o4', 'o2', 'o3'], 2 ) - , ( ( ('o2', 'o3'), ('o1', 'o2', 'o3') ), - ['o1', 'o2', 'o3', 'o4'], 0 ) - , ( ( ('n2', 'o3'), ), ['o1', 'o2', 'o4', 'o3'], 1) - , ( ( ('o4', 'o2'), ), ['o1', 'o3', 'o4', 'o2'], 1 ) - ) - ) + self.runTableTests( + "moveObjectsToBottom", + ( + (("o1",), ["o2", "o3", "o4", "o1"], 1), + ((("o2", "o4"),), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"),), ["o1", "o4", "o2", "o3"], 2), + ((("o2", "o3"), ("o1", "o2", "o3", "o4")), ["o1", "o4", "o2", "o3"], 2), + ((("o2", "o3"), ("o1", "o2", "o3")), ["o1", "o2", "o3", "o4"], 0), + ((("n2", "o3"),), ["o1", "o2", "o4", "o3"], 1), + ((("o4", "o2"),), ["o1", "o3", "o4", "o2"], 1), + ), + ) def test_orderObjects(self): - self.runTableTests('orderObjects', - ( ( ( 'id', 'id' ), ['o4', 'o3', 'o2', 'o1'], -1) - , ( ( 'meta_type', '' ), ['o1', 'o3', 'o2', 'o4'], -1) - # for the next line the sort order is different from the - # original test in OFS, since the current implementation - # keeps the original order as much as possible, i.e. minimize - # exchange operations within the list; this is correct as - # far as the test goes, since it didn't specify a secondary - # sort key... - , ( ( 'meta_type', 'n' ), ['o2', 'o4', 'o1', 'o3'], -1) - ) - ) + self.runTableTests( + "orderObjects", + ( + (("id", "id"), ["o4", "o3", "o2", "o1"], -1), + (("meta_type", ""), ["o1", "o3", "o2", "o4"], -1) + # for the next line the sort order is different from the + # original test in OFS, since the current implementation + # keeps the original order as much as possible, i.e. minimize + # exchange operations within the list; this is correct as + # far as the test goes, since it didn't specify a secondary + # sort key... + , + (("meta_type", "n"), ["o2", "o4", "o1", "o3"], -1), + ), + ) def test_getObjectPosition(self): - self.runTableTests('getObjectPosition', - ( ( ( 'o2', ), ['o1', 'o2', 'o3', 'o4'], 1) - , ( ( 'o4', ), ['o1', 'o2', 'o3', 'o4'], 3) - , ( ( 'n2', ), ['o1', 'o2', 'o3', 'o4'], 'ValueError') - ) - ) + self.runTableTests( + "getObjectPosition", + ( + (("o2",), ["o1", "o2", "o3", "o4"], 1), + (("o4",), ["o1", "o2", "o3", "o4"], 3), + (("n2",), ["o1", "o2", "o3", "o4"], "ValueError"), + ), + ) def test_moveObjectToPosition(self): - self.runTableTests('moveObjectToPosition', - ( ( ( 'o2', 2 ), ['o1', 'o3', 'o2', 'o4'], 1) - , ( ( 'o4', 2 ), ['o1', 'o2', 'o4', 'o3'], 1) - , ( ( 'n2', 2 ), ['o1', 'o2', 'o3', 'o4'], 'ValueError') - ) - ) + self.runTableTests( + "moveObjectToPosition", + ( + (("o2", 2), ["o1", "o3", "o2", "o4"], 1), + (("o4", 2), ["o1", "o2", "o4", "o3"], 1), + (("n2", 2), ["o1", "o2", "o3", "o4"], "ValueError"), + ), + ) def test_getObjectPosition_error_message(self): folder = self.create() try: - folder.getObjectPosition('n4') + folder.getObjectPosition("n4") self.assertFail() except ValueError as err: - self.assertEqual( - str(err), 'No object with id "n4" exists in "f1".') + self.assertEqual(str(err), 'No object with id "n4" exists in "f1".') class PloneOrderSupportTests(unittest.TestCase): - """ tests borrowed from Products.CMFPlone.tests.testOrderSupport """ + """tests borrowed from Products.CMFPlone.tests.testOrderSupport""" layer = PLONEFOLDER_INTEGRATION_TESTING def setUp(self): self.folder = OrderedBTreeFolderBase("f1") - self.folder['foo'] = DummyObject('foo', 'mt1') - self.folder['bar'] = DummyObject('bar', 'mt1') - self.folder['baz'] = DummyObject('baz', 'mt1') + self.folder["foo"] = DummyObject("foo", "mt1") + self.folder["bar"] = DummyObject("bar", "mt1") + self.folder["baz"] = DummyObject("baz", "mt1") def testGetObjectPosition(self): - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('bar'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("bar"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testMoveObject(self): - self.folder.moveObjectToPosition('foo', 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.folder.moveObjectToPosition("foo", 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testMoveObjectToSamePos(self): - self.folder.moveObjectToPosition('bar', 1) - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('bar'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.folder.moveObjectToPosition("bar", 1) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("bar"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testMoveObjectToFirstPos(self): - self.folder.moveObjectToPosition('bar', 0) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.folder.moveObjectToPosition("bar", 0) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testMoveObjectToLastPos(self): - self.folder.moveObjectToPosition('bar', 2) - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.moveObjectToPosition("bar", 2) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testMoveObjectOutLowerBounds(self): # Pos will be normalized to 0 - self.folder.moveObjectToPosition('bar', -1) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.folder.moveObjectToPosition("bar", -1) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testMoveObjectOutUpperBounds(self): # Pos will be normalized to 2 - self.folder.moveObjectToPosition('bar', 3) - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.moveObjectToPosition("bar", 3) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testMoveObjectsUp(self): - self.folder.moveObjectsUp(['bar']) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.folder.moveObjectsUp(["bar"]) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testMoveObjectsDown(self): - self.folder.moveObjectsDown(['bar']) - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.moveObjectsDown(["bar"]) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testMoveObjectsToTop(self): - self.folder.moveObjectsToTop(['bar']) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.folder.moveObjectsToTop(["bar"]) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testMoveObjectsToBottom(self): - self.folder.moveObjectsToBottom(['bar']) - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.moveObjectsToBottom(["bar"]) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testMoveTwoObjectsUp(self): - self.folder.moveObjectsUp(['bar', 'baz']) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('foo'), 2) + self.folder.moveObjectsUp(["bar", "baz"]) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("foo"), 2) def testMoveTwoObjectsDown(self): - self.folder.moveObjectsDown(['foo', 'bar']) - self.assertEqual(self.folder.getObjectPosition('baz'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.moveObjectsDown(["foo", "bar"]) + self.assertEqual(self.folder.getObjectPosition("baz"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testMoveTwoObjectsToTop(self): - self.folder.moveObjectsToTop(['bar', 'baz']) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('foo'), 2) + self.folder.moveObjectsToTop(["bar", "baz"]) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("foo"), 2) def testMoveTwoObjectsToBottom(self): - self.folder.moveObjectsToBottom(['foo', 'bar']) - self.assertEqual(self.folder.getObjectPosition('baz'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.moveObjectsToBottom(["foo", "bar"]) + self.assertEqual(self.folder.getObjectPosition("baz"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testOrderObjects(self): - self.folder.orderObjects('id') - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('foo'), 2) + self.folder.orderObjects("id") + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("foo"), 2) def testOrderObjectsReverse(self): - self.folder.orderObjects('id', reverse=True) - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.orderObjects("id", reverse=True) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testOrderObjectsByMethod(self): - self.folder.orderObjects('dummy_method') - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('foo'), 2) + self.folder.orderObjects("dummy_method") + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("foo"), 2) def testOrderObjectsOnlyReverse(self): self.folder.orderObjects(reverse=True) - self.assertEqual(self.folder.getObjectPosition('baz'), 0) - self.assertEqual(self.folder.getObjectPosition('bar'), 1) - self.assertEqual(self.folder.getObjectPosition('foo'), 2) + self.assertEqual(self.folder.getObjectPosition("baz"), 0) + self.assertEqual(self.folder.getObjectPosition("bar"), 1) + self.assertEqual(self.folder.getObjectPosition("foo"), 2) def testSubsetIds(self): - self.folder.moveObjectsByDelta(['baz'], -1, ['foo', 'bar', 'baz']) - self.assertEqual(self.folder.getObjectPosition('foo'), 0) - self.assertEqual(self.folder.getObjectPosition('baz'), 1) - self.assertEqual(self.folder.getObjectPosition('bar'), 2) + self.folder.moveObjectsByDelta(["baz"], -1, ["foo", "bar", "baz"]) + self.assertEqual(self.folder.getObjectPosition("foo"), 0) + self.assertEqual(self.folder.getObjectPosition("baz"), 1) + self.assertEqual(self.folder.getObjectPosition("bar"), 2) def testSkipObjectsNotInSubsetIds(self): - self.folder.moveObjectsByDelta(['baz'], -1, ['foo', 'baz']) - self.assertEqual(self.folder.getObjectPosition('baz'), 0) - self.assertEqual(self.folder.getObjectPosition('bar'), 1) # no move - self.assertEqual(self.folder.getObjectPosition('foo'), 2) + self.folder.moveObjectsByDelta(["baz"], -1, ["foo", "baz"]) + self.assertEqual(self.folder.getObjectPosition("baz"), 0) + self.assertEqual(self.folder.getObjectPosition("bar"), 1) # no move + self.assertEqual(self.folder.getObjectPosition("foo"), 2) def testIgnoreNonObjects(self): # Fix for (http://dev.plone.org/plone/ticket/3959) non # contentish objects cause errors, we should just ignore them - self.folder.moveObjectsByDelta(['bar', 'blah'], -1) - self.assertEqual(self.folder.getObjectPosition('bar'), 0) - self.assertEqual(self.folder.getObjectPosition('foo'), 1) - self.assertEqual(self.folder.getObjectPosition('baz'), 2) + self.folder.moveObjectsByDelta(["bar", "blah"], -1) + self.assertEqual(self.folder.getObjectPosition("bar"), 0) + self.assertEqual(self.folder.getObjectPosition("foo"), 1) + self.assertEqual(self.folder.getObjectPosition("baz"), 2) def testNotifyRemoved(self): ordering = self.folder.getOrdering() - self.assertEqual( - ordering.idsInOrder(), - ['foo', 'bar', 'baz'] - ) + self.assertEqual(ordering.idsInOrder(), ["foo", "bar", "baz"]) # make sure notifyRemoved with non-existent id does not throw error - ordering.notifyRemoved('foobar') + ordering.notifyRemoved("foobar") # normal - ordering.notifyRemoved('foo') - self.assertEqual( - ordering.idsInOrder(), - ['bar', 'baz'] - ) + ordering.notifyRemoved("foo") + self.assertEqual(ordering.idsInOrder(), ["bar", "baz"]) diff --git a/src/plone/folder/tests/test_partialordering.py b/src/plone/folder/tests/test_partialordering.py index d3a28e0..eca9544 100644 --- a/src/plone/folder/tests/test_partialordering.py +++ b/src/plone/folder/tests/test_partialordering.py @@ -13,21 +13,21 @@ class PartialOrderingTests(unittest.TestCase): - """ tests regarding order-support for only items marked orderable """ + """tests regarding order-support for only items marked orderable""" layer = PLONEFOLDER_INTEGRATION_TESTING def create(self): container = OrderedBTreeFolderBase() - container.setOrdering('partial') - container['o1'] = Orderable('o1', 'mt1') - container['o2'] = Orderable('o2', 'mt2') - container['c1'] = Chaoticle('c1', 'mt3') - container['o3'] = Orderable('o3', 'mt1') - container['c2'] = Chaoticle('c2', 'mt2') - container['c3'] = Chaoticle('c3', 'mt1') - container['o4'] = Orderable('o4', 'mt2') - self.unordered = ['c1', 'c2', 'c3'] + container.setOrdering("partial") + container["o1"] = Orderable("o1", "mt1") + container["o2"] = Orderable("o2", "mt2") + container["c1"] = Chaoticle("c1", "mt3") + container["o3"] = Orderable("o3", "mt1") + container["c2"] = Chaoticle("c2", "mt2") + container["c3"] = Chaoticle("c3", "mt1") + container["o4"] = Orderable("o4", "mt2") + self.unordered = ["c1", "c2", "c3"] ordering = container.getOrdering() return container, ordering @@ -38,43 +38,29 @@ def testAdapter(self): def testNotifyAdded(self): container, ordering = self.create() self.assertEqual( - ordering.idsInOrder(), - ['o1', 'o2', 'o3', 'o4'] + self.unordered + ordering.idsInOrder(), ["o1", "o2", "o3", "o4"] + self.unordered ) - container['o5'] = Orderable('o5') + container["o5"] = Orderable("o5") self.assertEqual( - ordering.idsInOrder(), - ['o1', 'o2', 'o3', 'o4', 'o5'] + self.unordered + ordering.idsInOrder(), ["o1", "o2", "o3", "o4", "o5"] + self.unordered ) self.assertEqual( - set(container.objectIds()), - {'o1', 'o2', 'o3', 'o4', 'o5', 'c1', 'c2', 'c3'} + set(container.objectIds()), {"o1", "o2", "o3", "o4", "o5", "c1", "c2", "c3"} ) def testNotifyRemoved(self): container, ordering = self.create() self.assertEqual( - ordering.idsInOrder(), - ['o1', 'o2', 'o3', 'o4'] + self.unordered + ordering.idsInOrder(), ["o1", "o2", "o3", "o4"] + self.unordered ) - container._delOb('o3') + container._delOb("o3") + self.assertEqual(ordering.idsInOrder(), ["o1", "o2", "o4"] + self.unordered) self.assertEqual( - ordering.idsInOrder(), - ['o1', 'o2', 'o4'] + self.unordered - ) - self.assertEqual( - set(container.objectIds()), - {'o1', 'o2', 'o4', 'c1', 'c2', 'c3'} - ) - container._delOb('o1') - self.assertEqual( - ordering.idsInOrder(), - ['o2', 'o4'] + self.unordered - ) - self.assertEqual( - set(container.objectIds()), - {'o2', 'o4', 'c1', 'c2', 'c3'} + set(container.objectIds()), {"o1", "o2", "o4", "c1", "c2", "c3"} ) + container._delOb("o1") + self.assertEqual(ordering.idsInOrder(), ["o2", "o4"] + self.unordered) + self.assertEqual(set(container.objectIds()), {"o2", "o4", "c1", "c2", "c3"}) def runTableTests(self, action, tests): for args, order, rval in tests: @@ -86,132 +72,175 @@ def runTableTests(self, action, tests): else: self.assertEqual(method(*args), rval) self.assertEqual(ordering.idsInOrder(), order + self.unordered) - self.assertEqual(set(container.objectIds()), ids) # all here? + self.assertEqual(set(container.objectIds()), ids) # all here? def testMoveObjectsByDelta(self): - self.runTableTests('moveObjectsByDelta', ( - (('o1', 1), ['o2', 'o1', 'o3', 'o4'], 1), - (('o1', 2), ['o2', 'o3', 'o1', 'o4'], 1), - ((('o2', 'o4'), 1), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o2', 'o4'), 9), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o2', 'o3'), 1), ['o1', 'o4', 'o2', 'o3'], 2), - ((('o2', 'o3'), 1, ('o1', 'o2', 'o3', 'o4')), ['o1', 'o4', 'o2', 'o3'], 2), - ((('o2', 'o3'), 1, ('o1', 'o2', 'o3')), ['o1', 'o2', 'o3', 'o4'], 0), - ((('c1', 'o1'), 2), ['o2', 'o3', 'o1', 'o4'], 1), - ((('c1', 'o3'), 1), ['o1', 'o2', 'o4', 'o3'], 1), - ((('n2', 'o2'), 1), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o4', 'o2'), 1), ['o1', 'o3', 'o2', 'o4'], 1), - )) + self.runTableTests( + "moveObjectsByDelta", + ( + (("o1", 1), ["o2", "o1", "o3", "o4"], 1), + (("o1", 2), ["o2", "o3", "o1", "o4"], 1), + ((("o2", "o4"), 1), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o4"), 9), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"), 1), ["o1", "o4", "o2", "o3"], 2), + ( + (("o2", "o3"), 1, ("o1", "o2", "o3", "o4")), + ["o1", "o4", "o2", "o3"], + 2, + ), + ((("o2", "o3"), 1, ("o1", "o2", "o3")), ["o1", "o2", "o3", "o4"], 0), + ((("c1", "o1"), 2), ["o2", "o3", "o1", "o4"], 1), + ((("c1", "o3"), 1), ["o1", "o2", "o4", "o3"], 1), + ((("n2", "o2"), 1), ["o1", "o3", "o2", "o4"], 1), + ((("o4", "o2"), 1), ["o1", "o3", "o2", "o4"], 1), + ), + ) def testMoveObjectsDown(self): - self.runTableTests('moveObjectsDown', ( - (('o1',), ['o2', 'o1', 'o3', 'o4'], 1), - (('o1', 2), ['o2', 'o3', 'o1', 'o4'], 1), - ((('o2', 'o4'),), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o2', 'o4'), 9), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o2', 'o3'),), ['o1', 'o4', 'o2', 'o3'], 2), - ((('o2', 'o3'), 1, ('o1', 'o2', 'o3', 'o4')), ['o1', 'o4', 'o2', 'o3'], 2), - ((('o2', 'o3'), 1, ('o1', 'o2', 'o3')), ['o1', 'o2', 'o3', 'o4'], 0), - ((('c1', 'o1'), 2), ['o2', 'o3', 'o1', 'o4'], 1), - ((('c1', 'o3'),), ['o1', 'o2', 'o4', 'o3'], 1), - ((('n2', 'o2'),), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o4', 'o2'),), ['o1', 'o3', 'o2', 'o4'], 1), - )) + self.runTableTests( + "moveObjectsDown", + ( + (("o1",), ["o2", "o1", "o3", "o4"], 1), + (("o1", 2), ["o2", "o3", "o1", "o4"], 1), + ((("o2", "o4"),), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o4"), 9), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"),), ["o1", "o4", "o2", "o3"], 2), + ( + (("o2", "o3"), 1, ("o1", "o2", "o3", "o4")), + ["o1", "o4", "o2", "o3"], + 2, + ), + ((("o2", "o3"), 1, ("o1", "o2", "o3")), ["o1", "o2", "o3", "o4"], 0), + ((("c1", "o1"), 2), ["o2", "o3", "o1", "o4"], 1), + ((("c1", "o3"),), ["o1", "o2", "o4", "o3"], 1), + ((("n2", "o2"),), ["o1", "o3", "o2", "o4"], 1), + ((("o4", "o2"),), ["o1", "o3", "o2", "o4"], 1), + ), + ) def testMoveObjectsUp(self): - self.runTableTests('moveObjectsUp', ( - (('o4',), ['o1', 'o2', 'o4', 'o3'], 1), - (('o4', 1), ['o1', 'o2', 'o4', 'o3'], 1), - (('o4', 2), ['o1', 'o4', 'o2', 'o3'], 1), - ((('o1', 'o3'), 1), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o1', 'o3'), 9), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o2', 'o3'), 1), ['o2', 'o3', 'o1', 'o4'], 2), - ((('o2', 'o3'), 1, ('o1', 'o2', 'o3', 'o4')), ['o2', 'o3', 'o1', 'o4'], 2), - ((('o2', 'o3'), 1, ('o2', 'o3', 'o4')), ['o1', 'o2', 'o3', 'o4'], 0), - ((('c1', 'o4'), 2), ['o1', 'o4', 'o2', 'o3'], 1), - ((('c1', 'o3'),), ['o1', 'o3', 'o2', 'o4'], 1), - ((('n2', 'o3'), 1), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o3', 'o1'), 1), ['o1', 'o3', 'o2', 'o4'], 1), - )) + self.runTableTests( + "moveObjectsUp", + ( + (("o4",), ["o1", "o2", "o4", "o3"], 1), + (("o4", 1), ["o1", "o2", "o4", "o3"], 1), + (("o4", 2), ["o1", "o4", "o2", "o3"], 1), + ((("o1", "o3"), 1), ["o1", "o3", "o2", "o4"], 1), + ((("o1", "o3"), 9), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"), 1), ["o2", "o3", "o1", "o4"], 2), + ( + (("o2", "o3"), 1, ("o1", "o2", "o3", "o4")), + ["o2", "o3", "o1", "o4"], + 2, + ), + ((("o2", "o3"), 1, ("o2", "o3", "o4")), ["o1", "o2", "o3", "o4"], 0), + ((("c1", "o4"), 2), ["o1", "o4", "o2", "o3"], 1), + ((("c1", "o3"),), ["o1", "o3", "o2", "o4"], 1), + ((("n2", "o3"), 1), ["o1", "o3", "o2", "o4"], 1), + ((("o3", "o1"), 1), ["o1", "o3", "o2", "o4"], 1), + ), + ) def testMoveObjectsToTop(self): - self.runTableTests('moveObjectsToTop', ( - (('o4',), ['o4', 'o1', 'o2', 'o3'], 1), - ((('o1', 'o3'),), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o2', 'o3'),), ['o2', 'o3', 'o1', 'o4'], 2), - ((('o2', 'o3'), ('o1', 'o2', 'o3', 'o4')), ['o2', 'o3', 'o1', 'o4'], 2), - ((('o2', 'o3'), ('o2', 'o3', 'o4')), ['o1', 'o2', 'o3', 'o4'], 0), - ((('c1', 'o4'),), ['o4', 'o1', 'o2', 'o3'], 1), - ((('c1', 'o3'),), ['o3', 'o1', 'o2', 'o4'], 1), - ((('n2', 'o3'),), ['o3', 'o1', 'o2', 'o4'], 1), - ((('o3', 'o1'),), ['o3', 'o1', 'o2', 'o4'], 1), - )) + self.runTableTests( + "moveObjectsToTop", + ( + (("o4",), ["o4", "o1", "o2", "o3"], 1), + ((("o1", "o3"),), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"),), ["o2", "o3", "o1", "o4"], 2), + ((("o2", "o3"), ("o1", "o2", "o3", "o4")), ["o2", "o3", "o1", "o4"], 2), + ((("o2", "o3"), ("o2", "o3", "o4")), ["o1", "o2", "o3", "o4"], 0), + ((("c1", "o4"),), ["o4", "o1", "o2", "o3"], 1), + ((("c1", "o3"),), ["o3", "o1", "o2", "o4"], 1), + ((("n2", "o3"),), ["o3", "o1", "o2", "o4"], 1), + ((("o3", "o1"),), ["o3", "o1", "o2", "o4"], 1), + ), + ) def testMoveObjectsToBottom(self): - self.runTableTests('moveObjectsToBottom', ( - (('o1',), ['o2', 'o3', 'o4', 'o1'], 1), - ((('o2', 'o4'),), ['o1', 'o3', 'o2', 'o4'], 1), - ((('o2', 'o3'),), ['o1', 'o4', 'o2', 'o3'], 2), - ((('o2', 'o3'), ('o1', 'o2', 'o3', 'o4')), ['o1', 'o4', 'o2', 'o3'], 2), - ((('o2', 'o3'), ('o1', 'o2', 'o3')), ['o1', 'o2', 'o3', 'o4'], 0), - ((('c1', 'o1'),), ['o2', 'o3', 'o4', 'o1'], 1), - ((('c1', 'o2'),), ['o1', 'o3', 'o4', 'o2'], 1), - ((('n2', 'o3'),), ['o1', 'o2', 'o4', 'o3'], 1), - ((('o4', 'o2'),), ['o1', 'o3', 'o4', 'o2'], 1), - )) + self.runTableTests( + "moveObjectsToBottom", + ( + (("o1",), ["o2", "o3", "o4", "o1"], 1), + ((("o2", "o4"),), ["o1", "o3", "o2", "o4"], 1), + ((("o2", "o3"),), ["o1", "o4", "o2", "o3"], 2), + ((("o2", "o3"), ("o1", "o2", "o3", "o4")), ["o1", "o4", "o2", "o3"], 2), + ((("o2", "o3"), ("o1", "o2", "o3")), ["o1", "o2", "o3", "o4"], 0), + ((("c1", "o1"),), ["o2", "o3", "o4", "o1"], 1), + ((("c1", "o2"),), ["o1", "o3", "o4", "o2"], 1), + ((("n2", "o3"),), ["o1", "o2", "o4", "o3"], 1), + ((("o4", "o2"),), ["o1", "o3", "o4", "o2"], 1), + ), + ) def testMoveObjectToPosition(self): - self.runTableTests('moveObjectToPosition', ( - (('o2', 2), ['o1', 'o3', 'o2', 'o4'], 1), - (('o4', 2), ['o1', 'o2', 'o4', 'o3'], 1), - (('c1', 2), ['o1', 'o2', 'o3', 'o4'], None), # existent, but non-orderable - (('n2', 2), ['o1', 'o2', 'o3', 'o4'], ValueError), - )) + self.runTableTests( + "moveObjectToPosition", + ( + (("o2", 2), ["o1", "o3", "o2", "o4"], 1), + (("o4", 2), ["o1", "o2", "o4", "o3"], 1), + ( + ("c1", 2), + ["o1", "o2", "o3", "o4"], + None, + ), # existent, but non-orderable + (("n2", 2), ["o1", "o2", "o3", "o4"], ValueError), + ), + ) def testOrderObjects(self): - self.runTableTests('orderObjects', ( - (('id', 'id'), ['o4', 'o3', 'o2', 'o1'], -1), - (('meta_type', ''), ['o1', 'o3', 'o2', 'o4'], -1), - # for the next line the sort order is different from the - # original test in OFS, since the current implementation - # keeps the original order as much as possible, i.e. minimize - # exchange operations within the list; this is correct as - # far as the test goes, since it didn't specify a secondary - # sort key... - (('meta_type', 'n'), ['o2', 'o4', 'o1', 'o3'], -1), - )) + self.runTableTests( + "orderObjects", + ( + (("id", "id"), ["o4", "o3", "o2", "o1"], -1), + (("meta_type", ""), ["o1", "o3", "o2", "o4"], -1), + # for the next line the sort order is different from the + # original test in OFS, since the current implementation + # keeps the original order as much as possible, i.e. minimize + # exchange operations within the list; this is correct as + # far as the test goes, since it didn't specify a secondary + # sort key... + (("meta_type", "n"), ["o2", "o4", "o1", "o3"], -1), + ), + ) def testGetObjectPosition(self): - self.runTableTests('getObjectPosition', ( - (('o2',), ['o1', 'o2', 'o3', 'o4'], 1), - (('o4',), ['o1', 'o2', 'o3', 'o4'], 3), - (('n2',), ['o1', 'o2', 'o3', 'o4'], ValueError), - (('c2',), ['o1', 'o2', 'o3', 'o4'], None), # existent, but non-orderable - )) + self.runTableTests( + "getObjectPosition", + ( + (("o2",), ["o1", "o2", "o3", "o4"], 1), + (("o4",), ["o1", "o2", "o3", "o4"], 3), + (("n2",), ["o1", "o2", "o3", "o4"], ValueError), + ( + ("c2",), + ["o1", "o2", "o3", "o4"], + None, + ), # existent, but non-orderable + ), + ) @implementer(IOrderable) class DummyFolder(OrderedBTreeFolderBase, Implicit): - """ we need to mix in acquisition """ + """we need to mix in acquisition""" - meta_type = 'DummyFolder' - _ordering = 'partial' + meta_type = "DummyFolder" + _ordering = "partial" def dummy_method(self): return self.id class PartialOrderingIntegrationTests(unittest.TestCase): - layer = PLONEFOLDER_FUNCTIONAL_TESTING def setUp(self): - self.app = self.layer['app'] + self.app = self.layer["app"] context = self.app - context._setOb('foo', DummyFolder('foo')) # not pythonic in 2.10 :( - context.foo['bar1'] = DummyFolder('bar1') - context.foo['bar2'] = DummyFolder('bar2') - context.foo['bar3'] = DummyFolder('bar3') + context._setOb("foo", DummyFolder("foo")) # not pythonic in 2.10 :( + context.foo["bar1"] = DummyFolder("bar1") + context.foo["bar2"] = DummyFolder("bar2") + context.foo["bar3"] = DummyFolder("bar3") savepoint(optimistic=True) self.assertEqual(self.registered, []) @@ -221,36 +250,38 @@ def registered(self): def testAddObjectChangesOrderInfo(self): foo = self.app.foo - foo['bar23'] = DummyFolder('bar23') - self.assertEqual(foo.objectIds(), ['bar1', 'bar2', 'bar3', 'bar23']) - self.assertTrue(foo in self.registered, 'not registered?') + foo["bar23"] = DummyFolder("bar23") + self.assertEqual(foo.objectIds(), ["bar1", "bar2", "bar3", "bar23"]) + self.assertTrue(foo in self.registered, "not registered?") def testRemoveObjectChangesOrderInfo(self): foo = self.app.foo - foo._delOb('bar2',) - self.assertEqual(foo.objectIds(), ['bar1', 'bar3']) - self.assertTrue(foo in self.registered, 'not registered?') + foo._delOb( + "bar2", + ) + self.assertEqual(foo.objectIds(), ["bar1", "bar3"]) + self.assertTrue(foo in self.registered, "not registered?") def testMoveObjectChangesOrderInfo(self): foo = self.app.foo - foo.moveObjectsUp(('bar2',)) - self.assertEqual(foo.objectIds(), ['bar2', 'bar1', 'bar3']) - self.assertTrue(foo in self.registered, 'not registered?') + foo.moveObjectsUp(("bar2",)) + self.assertEqual(foo.objectIds(), ["bar2", "bar1", "bar3"]) + self.assertTrue(foo in self.registered, "not registered?") def testOrderObjectsChangesOrderInfo(self): foo = self.app.foo - foo.orderObjects('id', reverse=True) - self.assertEqual(foo.objectIds(), ['bar3', 'bar2', 'bar1']) - self.assertTrue(foo in self.registered, 'not registered?') + foo.orderObjects("id", reverse=True) + self.assertEqual(foo.objectIds(), ["bar3", "bar2", "bar1"]) + self.assertTrue(foo in self.registered, "not registered?") # Reverse the current ordering. foo.orderObjects(reverse=True) - self.assertEqual(foo.objectIds(), ['bar1', 'bar2', 'bar3']) + self.assertEqual(foo.objectIds(), ["bar1", "bar2", "bar3"]) def testOrderObjectsByMethodChangesOrderInfo(self): foo = self.app.foo - foo.orderObjects('dummy_method', reverse=True) - self.assertEqual(foo.objectIds(), ['bar3', 'bar2', 'bar1']) - self.assertTrue(foo in self.registered, 'not registered?') + foo.orderObjects("dummy_method", reverse=True) + self.assertEqual(foo.objectIds(), ["bar3", "bar2", "bar1"]) + self.assertTrue(foo in self.registered, "not registered?") # Reverse the current ordering. foo.orderObjects(reverse=True) - self.assertEqual(foo.objectIds(), ['bar1', 'bar2', 'bar3']) + self.assertEqual(foo.objectIds(), ["bar1", "bar2", "bar3"]) diff --git a/src/plone/folder/tests/test_unorderedordering.py b/src/plone/folder/tests/test_unorderedordering.py index be922b2..f780870 100644 --- a/src/plone/folder/tests/test_unorderedordering.py +++ b/src/plone/folder/tests/test_unorderedordering.py @@ -7,17 +7,17 @@ class UnorderedOrderingTests(unittest.TestCase): - """ tests regarding order-support for folders with unordered ordering """ + """tests regarding order-support for folders with unordered ordering""" layer = PLONEFOLDER_INTEGRATION_TESTING def create(self): container = OrderedBTreeFolderBase() - container._ordering = 'unordered' - container._setOb('o1', DummyObject('o1', 'mt1')) - container._setOb('o2', DummyObject('o2', 'mt2')) - container._setOb('o3', DummyObject('o3', 'mt1')) - container._setOb('o4', DummyObject('o4', 'mt2')) + container._ordering = "unordered" + container._setOb("o1", DummyObject("o1", "mt1")) + container._setOb("o2", DummyObject("o2", "mt2")) + container._setOb("o3", DummyObject("o3", "mt1")) + container._setOb("o4", DummyObject("o4", "mt2")) return container def testAdapter(self): @@ -27,28 +27,16 @@ def testAdapter(self): def testNotifyAdded(self): container = self.create() - self.assertEqual( - set(container.objectIds()), - {'o1', 'o2', 'o3', 'o4'} - ) - container._setOb('o5', DummyObject('o5', 'mt1')) - self.assertEqual( - set(container.objectIds()), - {'o1', 'o2', 'o3', 'o4', 'o5'} - ) + self.assertEqual(set(container.objectIds()), {"o1", "o2", "o3", "o4"}) + container._setOb("o5", DummyObject("o5", "mt1")) + self.assertEqual(set(container.objectIds()), {"o1", "o2", "o3", "o4", "o5"}) def testNotifyRemoved(self): container = self.create() - self.assertEqual( - set(container.objectIds()), - {'o1', 'o2', 'o3', 'o4'} - ) - container._delOb('o3') - self.assertEqual( - set(container.objectIds()), - {'o1', 'o2', 'o4'} - ) + self.assertEqual(set(container.objectIds()), {"o1", "o2", "o3", "o4"}) + container._delOb("o3") + self.assertEqual(set(container.objectIds()), {"o1", "o2", "o4"}) def testGetObjectPosition(self): container = self.create() - self.assertEqual(container.getObjectPosition('o2'), None) + self.assertEqual(container.getObjectPosition("o2"), None) diff --git a/src/plone/folder/tests/test_webdav.py b/src/plone/folder/tests/test_webdav.py index 7f2cb18..338b628 100644 --- a/src/plone/folder/tests/test_webdav.py +++ b/src/plone/folder/tests/test_webdav.py @@ -16,12 +16,11 @@ class TestRequestContainer(Explicit): - REQUEST = TestRequest() class WebDAVTests(unittest.TestCase): - """ tests regarding support for WebDAV NullResources """ + """tests regarding support for WebDAV NullResources""" layer = PLONEFOLDER_INTEGRATION_TESTING @@ -30,28 +29,28 @@ def test_getitem_not_dav_request(self): folder = CMFOrderedBTreeFolderBase("f1").__of__(root) root.REQUEST.maybe_webdav_client = False - root.REQUEST._environ['REQUEST_METHOD'] = 'GET' + root.REQUEST._environ["REQUEST_METHOD"] = "GET" - foo = DummyObject('foo') - folder['foo'] = foo + foo = DummyObject("foo") + folder["foo"] = foo - self.assertEqual(folder['foo'], foo) + self.assertEqual(folder["foo"], foo) try: - folder['bar'] + folder["bar"] self.fail() except KeyError: pass - @unittest.skipUnless(HAS_WEBDAV, 'ZServer is optional') + @unittest.skipUnless(HAS_WEBDAV, "ZServer is optional") def test_getitem_dav_request(self): root = TestRequestContainer() folder = CMFOrderedBTreeFolderBase("f1").__of__(root) root.REQUEST.maybe_webdav_client = True - root.REQUEST._environ['REQUEST_METHOD'] = 'PUT' + root.REQUEST._environ["REQUEST_METHOD"] = "PUT" - foo = DummyObject('foo') - folder['foo'] = foo + foo = DummyObject("foo") + folder["foo"] = foo - self.assertEqual(folder['foo'], foo) - self.assertTrue(isinstance(folder['bar'], NullResource)) + self.assertEqual(folder["foo"], foo) + self.assertTrue(isinstance(folder["bar"], NullResource)) diff --git a/src/plone/folder/tests/utils.py b/src/plone/folder/tests/utils.py index d81e2e9..aa1e79f 100644 --- a/src/plone/folder/tests/utils.py +++ b/src/plone/folder/tests/utils.py @@ -3,7 +3,6 @@ class DummyObject: - def __init__(self, id, meta_type=None): self.id = id self.meta_type = meta_type @@ -20,8 +19,8 @@ def dummy_method(self): @implementer(IOrderable) class Orderable(DummyObject): - """ orderable mock object """ + """orderable mock object""" class Chaoticle(DummyObject): - """ non-orderable mock object; this does not implement `IOrderable` """ + """non-orderable mock object; this does not implement `IOrderable`""" diff --git a/src/plone/folder/unordered.py b/src/plone/folder/unordered.py index ea82a74..751443b 100644 --- a/src/plone/folder/unordered.py +++ b/src/plone/folder/unordered.py @@ -8,7 +8,7 @@ @implementer(IOrdering) @adapter(IOrderableFolder) class UnorderedOrdering: - """ This implementation provides no ordering. """ + """This implementation provides no ordering.""" def __init__(self, context): self.context = context