Author: jmorliaguet
Date: Tue Nov 22 12:39:57 2005
New Revision: 1918

Added:
   cpsskins/branches/jmo-perspectives/relations/storage.py   (contents, props 
changed)
Removed:
   cpsskins/branches/jmo-perspectives/storage/relations.py
Modified:
   cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
   cpsskins/branches/jmo-perspectives/browser/tree/slot.py
   cpsskins/branches/jmo-perspectives/configure.zcml
   cpsskins/branches/jmo-perspectives/doc/local-portlets.txt
   cpsskins/branches/jmo-perspectives/relations/configure.zcml
   cpsskins/branches/jmo-perspectives/relations/interfaces.py
   cpsskins/branches/jmo-perspectives/relations/tool.py
   cpsskins/branches/jmo-perspectives/storage/configure.zcml
   cpsskins/branches/jmo-perspectives/tests/test_relations.py
   cpsskins/branches/jmo-perspectives/tests/test_storages.py
   cpsskins/branches/jmo-perspectives/thememanager.py
Log:

- moved the relations storage to the 'relations' package



Modified: cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/rendering/engine.py      
(original)
+++ cpsskins/branches/jmo-perspectives/browser/rendering/engine.py      Tue Nov 
22 12:39:57 2005
@@ -34,7 +34,7 @@
 from cpsskins.configuration.interfaces import IRegistry
 from cpsskins.elements.interfaces import (
     IType, INodeTraverser, INode, IElement, ILeaf, ISlot, IDisplayable)
-from cpsskins.storage.relations import IRelationStorage
+from cpsskins.relations.interfaces import IRelationStorage
 from cpsskins.utils import getThemeManager, getContexts
 
 INFO = logging.INFO

Modified: cpsskins/branches/jmo-perspectives/browser/tree/slot.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/tree/slot.py     (original)
+++ cpsskins/branches/jmo-perspectives/browser/tree/slot.py     Tue Nov 22 
12:39:57 2005
@@ -31,7 +31,7 @@
 from cpsskins.relations.tool import RelationTool
 from cpsskins.utils import getThemeManager
 from cpsskins.storage.portlets import IPortletStorage
-from cpsskins.storage.relations import IRelationStorage
+from cpsskins.relations.interfaces import IRelationStorage
 from cpsskins.browser.tree.interfaces import (
     INodeAdding, INodeRemoving, INodeOrdering, INodeMoving, INodeDuplicating
     )

Modified: cpsskins/branches/jmo-perspectives/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/configure.zcml   (original)
+++ cpsskins/branches/jmo-perspectives/configure.zcml   Tue Nov 22 12:39:57 2005
@@ -82,6 +82,8 @@
 
   <include package=".model" />
 
+  <include package=".storage" />
+
   <include package=".relations" />
 
   <include package=".engines" />
@@ -90,8 +92,6 @@
 
   <include package=".configuration" />
 
-  <include package=".storage" />
-
   <include package=".profiles" />
 
 </configure>

Modified: cpsskins/branches/jmo-perspectives/doc/local-portlets.txt
==============================================================================
--- cpsskins/branches/jmo-perspectives/doc/local-portlets.txt   (original)
+++ cpsskins/branches/jmo-perspectives/doc/local-portlets.txt   Tue Nov 22 
12:39:57 2005
@@ -34,7 +34,7 @@
 
 and add them to the storage:
 
-    >>> from cpsskins.storage.relations import RelationStorage
+    >>> from cpsskins.relations.storage import RelationStorage
     >>> storage = RelationStorage()
 
     >>> storage['some_id'] = relation

Modified: cpsskins/branches/jmo-perspectives/relations/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/relations/configure.zcml (original)
+++ cpsskins/branches/jmo-perspectives/relations/configure.zcml Tue Nov 22 
12:39:57 2005
@@ -1,5 +1,6 @@
 <configure
-    xmlns="http://namespaces.zope.org/zope";>
+    xmlns="http://namespaces.zope.org/zope";
+    xmlns:cpsskins="http://namespaces.zope.org/cpsskins";>
 
   <content class=".Relation">
 
@@ -60,4 +61,14 @@
 
   </content>
 
+  <!-- Relation storage -->
+
+  <cpsskins:storage
+      id="relations"
+      title="Relation storage"
+      description="A relation storage contains relations between objects"
+      factory="cpsskins.relations.storage.RelationStorage"
+      interface="cpsskins.relations.interfaces.IRelationStorage"
+  />
+
 </configure>

Modified: cpsskins/branches/jmo-perspectives/relations/interfaces.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/relations/interfaces.py  (original)
+++ cpsskins/branches/jmo-perspectives/relations/interfaces.py  Tue Nov 22 
12:39:57 2005
@@ -17,8 +17,11 @@
 """
 __docformat__ = "reStructuredText"
 
+from zope.app.container.constraints import contains
 from zope.interface import Interface
 
+from cpsskins.storage.interfaces import IStorage
+
 # Relations
 class IRelatable(Interface):
     """A relatable element can be connected to other relatable elements."""
@@ -75,6 +78,31 @@
     def third():
         """The third relate"""
 
+class IRelationStorage(IStorage):
+
+    contains(IRelation)
+
+    def search(predicate, first, second, third):
+        """ """
+
+    def list():
+        """ """
+
+    def clear():
+        """ """
+
+    def getFirsts():
+        """ """
+
+    def getSeconds():
+        """ """
+
+    def getThirds():
+        """ """
+
+    def __delitem__(item):
+        """ """
+
 # Tool
 class IRelationTool(Interface):
     """Relation tool."""

Added: cpsskins/branches/jmo-perspectives/relations/storage.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/relations/storage.py     Tue Nov 22 
12:39:57 2005
@@ -0,0 +1,390 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import logging
+
+from pprint import pprint
+from BTrees.OOBTree import OOBTree
+
+from zope.app import zapi
+from zope.app.container.btree import BTreeContainer
+from zope.app.container.interfaces import INameChooser
+from zope.app.location.traversing import LocationPhysicallyLocatable
+from zope.interface import implements
+from zope.proxy import isProxy
+from zope.security.proxy import removeSecurityProxy
+
+from cpsskins.relations import Predicate, CompoundPredicate
+from cpsskins.relations.interfaces import (
+    IRelation, IRelatable, IPredicate, IProxyPredicate, IRelationStorage)
+from cpsskins.storage import Storage
+
+DEBUG = logging.DEBUG
+logger = logging.getLogger()
+
+# Wildcards are used to index the relates of a relation.
+WILDCARDS = {
+    1: (
+         ('',),
+       ),
+    2: (
+         ('', ''),
+         ('*', ''), ('', '*'),
+       ),
+    3: (
+         ('', '', ''),
+         ('*', '', ''), ('', '*', ''), ('', '', '*'),
+         ('*', '*', ''), ('', '*', '*'), ('*', '', '*'),
+       ),
+    }
+
+class RelationStorage(Storage):
+    """A BTree-based relation container with a relation indexer.
+
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(IRelationStorage, RelationStorage)
+    True
+
+    >>> storage = RelationStorage()
+    >>> from cpsskins.relations import TestRelate as Relate, \
+        Predicate, MonadicRelation, DyadicRelation, TriadicRelation
+    >>> from cpsskins.relations.interfaces import IRelatable
+
+    >>> first = Relate('this')
+    >>> second = Relate('that')
+    >>> predicate = Predicate('_ depends on _')
+    >>> r = DyadicRelation(predicate, first, second)
+
+    >>> r
+    <Dyadic relation: 'this depends on that'>
+
+    >>> list(storage._relates.keys())
+    []
+
+    We add a relation to the storage
+    >>> storage['dependency'] = r
+
+    The relates are indexed:
+    in the 'dependency' relation 'this' is a first and 'that' is a second:
+    >>> items = list(storage._relates.items())
+    >>> ('*,that', [u'dependency']) in items
+    True
+    >>> ('this,*', [u'dependency']) in items
+    True
+    >>> ('this,that', [u'dependency']) in items
+    True
+
+
+    Indexation
+    ----------
+    Let us clear and rebuild the index.
+    >>> storage._clearIndexes()
+    >>> list(storage._relates.items())
+    []
+    >>> storage.reindex()
+
+    The index is now rebuilt
+    >>> items = list(storage._relates.items())
+    >>> ('*,that', [u'dependency']) in items
+    True
+    >>> ('this,*', [u'dependency']) in items
+    True
+    >>> ('this,that', [u'dependency']) in items
+    True
+
+
+    Queries
+    --------------
+    During a search the predicate must be specified:
+    >>> storage.search()
+    Traceback (most recent call last):
+    ...
+    ValueError: Must specify a predicate in the query.
+
+    At least one relate must be specified:
+    >>> storage.search(predicate=predicate)
+    Traceback (most recent call last):
+    ...
+    ValueError: At least one relate must be specified in the query
+
+    If we do a search on the relates, we get a list of relations in which the
+    relate in involved:
+    >>> storage.search(predicate=predicate, first=first)
+    [u'dependency']
+    >>> storage.search(predicate=predicate, second=second)
+    [u'dependency']
+
+    Each relate has a role in the relation; "a depends on b" is not the same
+    as "b depends on a"
+    >>> storage.search(predicate=predicate, first=second)
+    []
+    >>> storage.search(predicate=predicate, second=first)
+    []
+
+    To get the list of all relations in the storage use:
+    >>> storage.list()
+    [u'dependency']
+
+    To get the list of relates matching a given query use:
+    >>> firsts = storage.getFirsts(predicate=predicate, first=first)
+    >>> [str(e) for e in firsts]
+    ['this']
+
+    >>> seconds = storage.getSeconds(predicate=predicate, first=first)
+    >>> [str(e) for e in seconds]
+    ['that']
+
+    Finally we destroy the relation:
+    >>> del storage['dependency']
+
+    The indexes get cleared and the keys get removed:
+    >>> list(storage._relates.keys())
+    []
+
+    >>> list(storage.items())
+    []
+
+
+    Compound predicates
+    -------------------
+    The storage can be searched using compound predicates.
+    A compound predicate is a collection of predicates written as a tuple.
+
+    For instance:
+    >>> is_black = '_ is black'
+    >>> is_white = '_ is white'
+
+    >>> is_black_or_white = is_black, is_white
+    >>> CP = CompoundPredicate(is_black_or_white)
+    >>> CP
+    <Compound Predicate: '_ is black OR _ is white'>
+
+    >>> a = Relate('snow')
+    >>> b = Relate('ebony')
+    >>> a_is_white = MonadicRelation(Predicate(is_white), a)
+    >>> b_is_black = MonadicRelation(Predicate(is_black), b)
+    >>> storage['some_white'] = a_is_white
+    >>> storage['some_black'] = b_is_black
+
+    The relations matching '_ is white' are:
+    >>> pprint([repr(storage[r]) for r in storage.list(Predicate(is_white))])
+    ["<Monadic relation: 'snow is white'>"]
+
+    The relations matching '_ is black' are:
+    >>> pprint([repr(storage[r]) for r in storage.list(Predicate(is_black))])
+    ["<Monadic relation: 'ebony is black'>"]
+
+    Relations matching the compound ('_ is black', '_is white') are:
+    >>> res = storage.list(CompoundPredicate(is_black_or_white))
+    >>> pprint([repr(storage[r]) for r in res])
+    ["<Monadic relation: 'ebony is black'>", "<Monadic relation: 'snow is 
white'>"]
+
+    Finally, we clear the storage:
+    >>> list(storage.keys())
+    [u'some_black', u'some_white']
+
+    >>> storage.clear()
+
+    >>> list(storage.keys())
+    []
+
+    """
+    implements(IRelationStorage)
+
+    __btree__setitem__ = BTreeContainer.__setitem__
+    __btree__delitem__ = BTreeContainer.__delitem__
+
+    def __init__(self, **kw):
+        BTreeContainer.__init__(self)
+        self._relates = OOBTree()
+
+    def __setitem__(self, key, object):
+        if not IRelation.providedBy(object):
+            raise ValueError, "Only objects implementing IRelation are allowed"
+        self.__btree__setitem__(key, object)
+        self._indexRelates(relation=object, id=key)
+        self._p_changed = True
+
+    def __delitem__(self, key):
+        self.__btree__delitem__(key)
+        # Unregister the relation from the relates catalog.
+        self._unindexRelates(key)
+        self._p_changed = True
+
+    def add(self, relation):
+        """Choose a name and add the relation to the store.
+        """
+        chooser = INameChooser(self)
+        name = str(relation).replace('_', '').replace(' ', '')
+        relation_name = chooser.chooseName(name, relation)
+        self[relation_name] = relation
+        logger.log(DEBUG,
+            "Added a relation '%s'; '%s'" % (relation_name, repr(relation))
+            )
+
+    def remove(self, ids=[]):
+        """Remove relations for the storage.
+        """
+        if isinstance(ids, basestring):
+            ids = [ids]
+        for id in ids:
+            if id not in self:
+                raise KeyError, "No such relation (%s) in the storage." % id
+            del self[id]
+        logger.log(DEBUG, "Removed the relations with ids: '%s'" % ids)
+
+    # Relation index
+    def reindex(self):
+        """Reindex the relations.
+        """
+        self._clearIndexes()
+        for relation in list(self.values()):
+            id = zapi.name(LocationPhysicallyLocatable(relation))
+            self._indexRelates(relation, id)
+        self._p_changed = True
+
+    def _indexRelates(self, relation, id):
+        """Index the relation in the relates catalog.
+        relations are refered to by their id (their name in the container)
+        """
+        id = unicode(id)
+        relates = self._relates
+        for r in self._analyse(relation):
+            key = self._computeKey(r)
+            try:
+                relates[key].append(id)
+            except KeyError:
+                relates[key] = [id]
+
+    def _unindexRelates(self, id):
+        """Remove all references to the relation in the relates catalog.
+        """
+        for k, v in list(self._relates.items()):
+            if id not in v:
+                continue
+            self._relates[k].remove(id)
+            if self._relates[k]:
+                continue
+            del self._relates[k]
+
+    def _analyse(self, relation):
+        relations = []
+        arity = len(relation)
+
+        def f(v, w):
+            if w == '*':
+                return '*'
+            return str(IRelatable(v))
+
+        for w in WILDCARDS[arity]:
+            relations.append(
+                tuple([f(relation[i], w[i]) for i in range(arity)])
+            )
+        return relations
+
+    def _computeKey(self, relates):
+        """Build a key for doing index lookups.
+        e.g. ('a', 'b', None) will be converted into ('a', 'b', '*')
+        """
+        def f(v):
+            if v is None:
+                return '*'
+            return str(IRelatable(v, v))
+        return ','.join([f(r) for r in relates])
+
+    def _lookup(self, relates):
+        """Do a lookup among the indexed relates.
+        """
+        return self._relates.get(self._computeKey(relates), [])
+
+    def _clearIndexes(self):
+        for k in list(self._relates.keys()):
+            del self._relates[k]
+
+    # storage search
+    def search(self, predicate=None, first=None, second=None, third=None):
+        """Search the storage.
+
+        - at least one relate (first, second, or third) must be specified.
+
+        - the predicate can be a compound predicate.
+
+        - predicates can be proxy predicates that refer to other predicates.
+
+        """
+
+        if predicate is None:
+            raise ValueError, "Must specify a predicate in the query."
+
+        if isProxy(predicate):
+            predicate = removeSecurityProxy(predicate)
+
+        if not IPredicate.providedBy(predicate):
+            raise TypeError("This type of predicate is not supported.")
+
+        if IProxyPredicate.providedBy(predicate):
+            predicate = predicate()
+
+        arity = len(predicate)
+        relates = (first, second, third)[:arity]
+
+        if relates == (None, None, None)[:arity]:
+            raise ValueError, \
+                "At least one relate must be specified in the query"
+
+        result = self._lookup(relates)
+        return [r for r in result if str(self.get(r)) in predicate]
+
+    def _getRelate(self, position, **kw):
+        relates = []
+        for id in self.search(**kw):
+            r = self.get(id)[position-1]
+            if r in relates:
+                continue
+            relates.append(r)
+        return relates
+
+    def getFirsts(self, **kw):
+        return self._getRelate(1, **kw)
+
+    def getSeconds(self, **kw):
+        return self._getRelate(2, **kw)
+
+    def getThirds(self, **kw):
+        return self._getRelate(3, **kw)
+
+    def list(self, predicate=None):
+        """Return the list of relations in the storage.
+        A predicate or a compound predicate can be specified as a filter.
+        This method is not optimized for doing queries.
+        """
+        if predicate is None:
+            return list(self)
+
+        if not IPredicate.providedBy(predicate):
+            raise TypeError, "This type of predicate is not supported."
+
+        return [r for r in self if str(self.get(r)) in predicate]
+
+    def clear(self):
+        """Remove all relations from the storage.
+        """
+        for k in list(self.keys()):
+            del self[k]
+

Modified: cpsskins/branches/jmo-perspectives/relations/tool.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/relations/tool.py        (original)
+++ cpsskins/branches/jmo-perspectives/relations/tool.py        Tue Nov 22 
12:39:57 2005
@@ -19,8 +19,7 @@
 
 from zope.interface import implements
 
-from cpsskins.relations.interfaces import IRelationTool
-from cpsskins.storage.relations import IRelationStorage
+from cpsskins.relations.interfaces import IRelationTool, IRelationStorage
 from cpsskins.utils import getThemeManager
 
 class RelationTool(object):

Modified: cpsskins/branches/jmo-perspectives/storage/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/storage/configure.zcml   (original)
+++ cpsskins/branches/jmo-perspectives/storage/configure.zcml   Tue Nov 22 
12:39:57 2005
@@ -6,16 +6,6 @@
     i18n_domain="cpsskins"
     >
 
-  <!-- Relation storage -->
-
-  <cpsskins:storage
-      id="relations"
-      title="Relation storage"
-      description="A relation storage contains relations between objects"
-      factory=".relations.RelationStorage"
-      interface=".relations.IRelationStorage"
-  />
-
   <!-- Portlet storage -->
 
   <cpsskins:storage

Modified: cpsskins/branches/jmo-perspectives/tests/test_relations.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/tests/test_relations.py  (original)
+++ cpsskins/branches/jmo-perspectives/tests/test_relations.py  Tue Nov 22 
12:39:57 2005
@@ -20,11 +20,188 @@
 import unittest
 
 from zope.testing.doctestunit import DocTestSuite
+from zope.component.tests.placelesssetup import PlacelessSetup
+
+from cpsskins.relations import Predicate, TestRelate as Relate
+from cpsskins.relations import MonadicRelation as Monad
+from cpsskins.relations import DyadicRelation as Dyad, TriadicRelation as Triad
+
+class TestRelationStorage(PlacelessSetup, unittest.TestCase):
+    def makeTestObject(self):
+        return RelationStorage()
+
+    def setUp(self):
+        self.storage = RelationStorage()
+
+    def test_one_monad_one_predicate(self):
+
+        A = Relate('a')
+        P = Predicate('_ is red')
+        monad = Monad(P, A)
+
+        self.storage['r1'] = monad
+
+        result = self.storage.search(predicate=P, first=A)
+        self.assertEqual(result, [u'r1'])
+
+    def test_two_monads_one_predicate(self):
+
+        A1 = Relate('a1')
+        A2 = Relate('a2')
+        P = Predicate('_ is red')
+        monad1 = Monad(P, A1)
+        monad2 = Monad(P, A2)
+
+        self.storage['r1'] = monad1
+        self.storage['r2'] = monad2
+
+        result = self.storage.search(predicate=P, first=A1)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P, first=A2)
+        self.assertEqual(result, [u'r2'])
+
+    def test_one_dyad_one_predicate(self):
+
+        A = Relate('a')
+        B = Relate('b')
+        P = Predicate('_ is _')
+        dyad = Dyad(P, A, B)
+
+        self.storage['r1'] = dyad
+
+        result = self.storage.search(predicate=P, first=A, second=B)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P, first=A)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P, second=B)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P, second=A)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P, first=B)
+        self.assertEqual(result, [])
+
+    def test_two_dyads_one_predicate(self):
+
+        A = Relate('a')
+        B1 = Relate('b1')
+        B2 = Relate('b2')
+        P = Predicate('_ is _')
+        dyad1 = Dyad(P, A, B1)
+        dyad2 = Dyad(P, A, B2)
+
+        self.storage['r1'] = dyad1
+        self.storage['r2'] = dyad2
+
+        result = self.storage.search(predicate=P, first=A, second=B1)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P, first=A, second=B2)
+        self.assertEqual(result, [u'r2'])
+
+        result = self.storage.search(predicate=P, first=A)
+        self.assertEqual(result, [u'r1', u'r2'])
+
+        result = self.storage.search(predicate=P, second=A)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P, second=B1)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P, second=B2)
+        self.assertEqual(result, [u'r2'])
+
+    def test_two_dyads_two_predicates(self):
+
+        A = Relate('a')
+        B1 = Relate('b1')
+        B2 = Relate('b2')
+        P1 = Predicate('_ is _')
+        P2 = Predicate('_ has _')
+        dyad1 = Dyad(P1, A, B1)
+        dyad2 = Dyad(P2, A, B2)
+
+        self.storage['r1'] = dyad1
+        self.storage['r2'] = dyad2
+
+        result = self.storage.search(predicate=P1, first=A, second=B1)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P1, first=A, second=B2)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P1, first=A)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P1, second=A)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P1, second=B1)
+        self.assertEqual(result, [u'r1'])
+
+        result = self.storage.search(predicate=P2, second=B2)
+        self.assertEqual(result, [u'r2'])
+
+    def test_one_triad_one_predicate(self):
+
+        A = Relate('a')
+        B = Relate('b')
+        C = Relate('c')
+        P = Predicate('_ gives _ to _')
+        triad = Triad(P, A, B, C)
+
+        self.storage['r'] = triad
+
+        result = self.storage.search(predicate=P, first=A)
+        self.assertEqual(result, [u'r'])
+
+        result = self.storage.search(predicate=P, second=B)
+        self.assertEqual(result, [u'r'])
+
+        result = self.storage.search(predicate=P, third=C)
+        self.assertEqual(result, [u'r'])
+
+        result = self.storage.search(predicate=P, first=A, second=B)
+        self.assertEqual(result, [u'r'])
+
+        result = self.storage.search(predicate=P, second=B, third=C)
+        self.assertEqual(result, [u'r'])
+
+        result = self.storage.search(predicate=P, first=A, third=C)
+        self.assertEqual(result, [u'r'])
+
+        result = self.storage.search(predicate=P, first=A, second=B, third=C)
+        self.assertEqual(result, [u'r'])
+
+        result = self.storage.search(predicate=P, second=A)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P, third=A)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P, first=C)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P, second=C)
+        self.assertEqual(result, [])
+
+        result = self.storage.search(predicate=P, third=B)
+        self.assertEqual(result, [])
+
+    def tearDown(self):
+        self.storage.clear()
 
 def test_suite():
     return unittest.TestSuite((
         DocTestSuite('cpsskins.relations'),
+        DocTestSuite('cpsskins.relations.storage'),
+        unittest.makeSuite(TestRelationStorage),
         ))
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
+

Modified: cpsskins/branches/jmo-perspectives/tests/test_storages.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/tests/test_storages.py   (original)
+++ cpsskins/branches/jmo-perspectives/tests/test_storages.py   Tue Nov 22 
12:39:57 2005
@@ -20,15 +20,10 @@
 import unittest
 
 from zope.testing.doctestunit import DocTestSuite
-from zope.component.tests.placelesssetup import PlacelessSetup
 
-from cpsskins.relations import Predicate, TestRelate as Relate
-from cpsskins.relations import MonadicRelation as Monad
-from cpsskins.relations import DyadicRelation as Dyad, TriadicRelation as Triad
 from cpsskins.storage.displays import DisplayStorage
 from cpsskins.storage.formats import FormatStorage
 from cpsskins.storage.portlets import PortletStorage
-from cpsskins.storage.relations import RelationStorage
 
 class TestPortletStorage:
     def makeTestObject(self):
@@ -42,173 +37,6 @@
     def makeTestObject(self):
         return DisplayStorage()
 
-class TestRelationStorage(PlacelessSetup, unittest.TestCase):
-    def makeTestObject(self):
-        return RelationStorage()
-
-    def setUp(self):
-        self.storage = RelationStorage()
-
-    def test_one_monad_one_predicate(self):
-
-        A = Relate('a')
-        P = Predicate('_ is red')
-        monad = Monad(P, A)
-
-        self.storage['r1'] = monad
-
-        result = self.storage.search(predicate=P, first=A)
-        self.assertEqual(result, [u'r1'])
-
-    def test_two_monads_one_predicate(self):
-
-        A1 = Relate('a1')
-        A2 = Relate('a2')
-        P = Predicate('_ is red')
-        monad1 = Monad(P, A1)
-        monad2 = Monad(P, A2)
-
-        self.storage['r1'] = monad1
-        self.storage['r2'] = monad2
-
-        result = self.storage.search(predicate=P, first=A1)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P, first=A2)
-        self.assertEqual(result, [u'r2'])
-
-    def test_one_dyad_one_predicate(self):
-
-        A = Relate('a')
-        B = Relate('b')
-        P = Predicate('_ is _')
-        dyad = Dyad(P, A, B)
-
-        self.storage['r1'] = dyad
-
-        result = self.storage.search(predicate=P, first=A, second=B)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P, first=A)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P, second=B)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P, second=A)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P, first=B)
-        self.assertEqual(result, [])
-
-    def test_two_dyads_one_predicate(self):
-
-        A = Relate('a')
-        B1 = Relate('b1')
-        B2 = Relate('b2')
-        P = Predicate('_ is _')
-        dyad1 = Dyad(P, A, B1)
-        dyad2 = Dyad(P, A, B2)
-
-        self.storage['r1'] = dyad1
-        self.storage['r2'] = dyad2
-
-        result = self.storage.search(predicate=P, first=A, second=B1)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P, first=A, second=B2)
-        self.assertEqual(result, [u'r2'])
-
-        result = self.storage.search(predicate=P, first=A)
-        self.assertEqual(result, [u'r1', u'r2'])
-
-        result = self.storage.search(predicate=P, second=A)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P, second=B1)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P, second=B2)
-        self.assertEqual(result, [u'r2'])
-
-    def test_two_dyads_two_predicates(self):
-
-        A = Relate('a')
-        B1 = Relate('b1')
-        B2 = Relate('b2')
-        P1 = Predicate('_ is _')
-        P2 = Predicate('_ has _')
-        dyad1 = Dyad(P1, A, B1)
-        dyad2 = Dyad(P2, A, B2)
-
-        self.storage['r1'] = dyad1
-        self.storage['r2'] = dyad2
-
-        result = self.storage.search(predicate=P1, first=A, second=B1)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P1, first=A, second=B2)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P1, first=A)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P1, second=A)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P1, second=B1)
-        self.assertEqual(result, [u'r1'])
-
-        result = self.storage.search(predicate=P2, second=B2)
-        self.assertEqual(result, [u'r2'])
-
-    def test_one_triad_one_predicate(self):
-
-        A = Relate('a')
-        B = Relate('b')
-        C = Relate('c')
-        P = Predicate('_ gives _ to _')
-        triad = Triad(P, A, B, C)
-
-        self.storage['r'] = triad
-
-        result = self.storage.search(predicate=P, first=A)
-        self.assertEqual(result, [u'r'])
-
-        result = self.storage.search(predicate=P, second=B)
-        self.assertEqual(result, [u'r'])
-
-        result = self.storage.search(predicate=P, third=C)
-        self.assertEqual(result, [u'r'])
-
-        result = self.storage.search(predicate=P, first=A, second=B)
-        self.assertEqual(result, [u'r'])
-
-        result = self.storage.search(predicate=P, second=B, third=C)
-        self.assertEqual(result, [u'r'])
-
-        result = self.storage.search(predicate=P, first=A, third=C)
-        self.assertEqual(result, [u'r'])
-
-        result = self.storage.search(predicate=P, first=A, second=B, third=C)
-        self.assertEqual(result, [u'r'])
-
-        result = self.storage.search(predicate=P, second=A)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P, third=A)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P, first=C)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P, second=C)
-        self.assertEqual(result, [])
-
-        result = self.storage.search(predicate=P, third=B)
-        self.assertEqual(result, [])
-
-
     def tearDown(self):
         self.storage.clear()
 
@@ -216,11 +44,9 @@
 def test_suite():
     return unittest.TestSuite((
         DocTestSuite('cpsskins.storage'),
-        DocTestSuite('cpsskins.storage.relations'),
         unittest.makeSuite(TestPortletStorage),
         unittest.makeSuite(TestDisplayStorage),
         unittest.makeSuite(TestFormatStorage),
-        unittest.makeSuite(TestRelationStorage),
         ))
 
 if __name__ == '__main__':

Modified: cpsskins/branches/jmo-perspectives/thememanager.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/thememanager.py  (original)
+++ cpsskins/branches/jmo-perspectives/thememanager.py  Tue Nov 22 12:39:57 2005
@@ -35,7 +35,7 @@
 from cpsskins.ontology import isDefault, hasFormat, hasDisplay
 from cpsskins.relations import MonadicRelation
 from cpsskins.relations.tool import RelationTool
-from cpsskins.storage.relations import IRelationStorage
+from cpsskins.relations.interfaces import IRelationStorage
 
 def added(object, event):
     object.registerUtilities()
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to