[Zope3-checkins] CVS: Zope3/src/zope/app/cache/tests - test_annotationcacheable.py:1.14 test_cachename.py:1.9 test_caching.py:1.15

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Mar 10 14:41:34 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/cache/tests
In directory cvs.zope.org:/tmp/cvs-serv2886/src/zope/app/cache/tests

Modified Files:
	test_annotationcacheable.py test_cachename.py test_caching.py 
Log Message:


Removed the caching service. It was not providing much value anyways, so it was
easy.



Also, I updated the views in a way that SQL Script's chace support would work
again.



There is still much to do:



- zope.app.cache.caching does not have a formally defined API (interface)



- The CacheName field should be a vocabulary field.



- Views need to be updated to current form.


=== Zope3/src/zope/app/cache/tests/test_annotationcacheable.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/cache/tests/test_annotationcacheable.py:1.13	Mon Mar  1 05:57:36 2004
+++ Zope3/src/zope/app/cache/tests/test_annotationcacheable.py	Wed Mar 10 14:41:02 2004
@@ -15,23 +15,22 @@
 
 $Id$
 """
-from unittest import TestCase, TestSuite, main, makeSuite
+import unittest
+from zope.interface import implements
+
 from zope.app.tests import ztapi
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.interfaces.annotation import IAttributeAnnotatable
+from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
 from zope.app.attributeannotations import AttributeAnnotations
 from zope.app.cache.annotationcacheable import AnnotationCacheable
-from zope.app.cache.interfaces import ICachingService
-from zope.component.service import serviceManager as sm
-from zope.app.interfaces.services.service import ISimpleService
-from zope.interface import implements
+from zope.app.cache.interfaces import ICache
 
 class ObjectStub:
     implements(IAttributeAnnotatable)
 
 
 class CacheStub:
+    implements(ICache)
     def __init__(self):
         self.invalidated = []
 
@@ -39,25 +38,11 @@
         self.invalidated.append(obj)
 
 
-class CachingServiceStub:
-    implements(ICachingService, ISimpleService)
-
-    def __init__(self):
-        self.caches = {}
-
-    def getCache(self, name):
-        return self.caches[name]
-
-
-class TestAnnotationCacheable(PlacelessSetup, TestCase):
+class TestAnnotationCacheable(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         super(TestAnnotationCacheable, self).setUp()
-        ztapi.provideAdapter(
-            IAttributeAnnotatable, IAnnotations,
-            AttributeAnnotations)
-        self.service = CachingServiceStub()
-        sm.defineService('Caching', ICachingService)
-        sm.provideService('Caching', self.service)
+        ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
+                             AttributeAnnotations)
 
     def testNormal(self):
         ob = ObjectStub()
@@ -72,8 +57,10 @@
     def testInvalidate(self):
         # Test that setting a different cache ID invalidates the old cached
         # value
-        self.service.caches['cache1'] = cache1 = CacheStub()
-        self.service.caches['cache2'] = cache2 = CacheStub()
+        cache1 = CacheStub()
+        ztapi.provideUtility(ICache, cache1, "cache1")
+        cache2 = CacheStub()
+        ztapi.provideUtility(ICache, cache2, "cache2")
         ob = ObjectStub()
         adapter = AnnotationCacheable(ob)
         adapter.setCacheId('cache1')
@@ -88,10 +75,9 @@
 
 
 def test_suite():
-    suite = TestSuite()
-    suite.addTest(makeSuite(TestAnnotationCacheable))
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(TestAnnotationCacheable))
     return suite
 
-
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')


=== Zope3/src/zope/app/cache/tests/test_cachename.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/cache/tests/test_cachename.py:1.8	Mon Mar  1 05:57:36 2004
+++ Zope3/src/zope/app/cache/tests/test_cachename.py	Wed Mar 10 14:41:02 2004
@@ -20,22 +20,15 @@
 import unittest
 from zope.interface import implements
 
-from zope.app.cache.interfaces import CacheName
-from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.tests import setup
-from zope.app.interfaces.services.service import ILocalService
+from zope.app.cache.interfaces import CacheName, ICache
+from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.interfaces.annotation import IAttributeAnnotatable
+from zope.app.services.utility import LocalUtilityService
 
-__metaclass__ = type
-
-class CachingServiceStub:
-
+class CacheStub(object):
     __name__ = __parent__ = None
-
-    implements(ILocalService, IAttributeAnnotatable)
-
-    def getAvailableCaches(self):
-        return 'foo', 'bar', 'baz'
+    implements(ICache, IAttributeAnnotatable)
 
     # IAttributeAnnotatable is implemented so that there will be an
     # IDependable adapter available.
@@ -45,7 +38,10 @@
     def setUp(self):
         PlacefulSetup.setUp(self, folders=True)
         sm = self.makeSite()
-        setup.addService(sm, 'Caching', CachingServiceStub())
+        setup.addService(sm, 'Utilities', LocalUtilityService())
+        setup.addUtility(sm, 'bar', ICache, CacheStub())
+        setup.addUtility(sm, 'baz', ICache, CacheStub())
+        setup.addUtility(sm, 'foo', ICache, CacheStub())
 
     def test(self):
         field = CacheName().bind(self.rootFolder)


=== Zope3/src/zope/app/cache/tests/test_caching.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/cache/tests/test_caching.py:1.14	Sat Mar  6 11:50:17 2004
+++ Zope3/src/zope/app/cache/tests/test_caching.py	Wed Mar 10 14:41:02 2004
@@ -15,68 +15,46 @@
 
 $Id$
 """
-
-from unittest import TestCase, TestSuite, main, makeSuite
-from zope.component import getService
+import unittest
 from zope.interface import implements
-from zope.component.service import serviceManager as sm
 
-from zope.app.tests import ztapi
-from zope.app.cache.interfaces import ICacheable, ICachingService
-from zope.app.cache.caching import getCacheForObj
-from zope.app.cache.annotationcacheable import AnnotationCacheable
-from zope.app.interfaces.annotation import IAnnotatable
-from zope.app.interfaces.annotation import IAnnotations
+from zope.app.tests import ztapi, setup
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.interfaces.annotation import IAnnotatable, IAnnotations
 from zope.app.interfaces.annotation import IAttributeAnnotatable
 from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.app.interfaces.services.service import ISimpleService
+from zope.app.cache.interfaces import ICacheable, ICache
+from zope.app.cache.caching import getCacheForObject
+from zope.app.cache.annotationcacheable import AnnotationCacheable
 
 class ObjectStub:
     implements(IAttributeAnnotatable)
 
 class CacheStub:
-    pass
-
-class CachingServiceStub:
+    implements(ICache)
 
-    implements(ICachingService, ISimpleService)
-
-    def __init__(self):
-        self.caches = {}
-
-    def getCache(self, name):
-        return self.caches[name]
-
-class Test(PlacelessSetup, TestCase):
+class Test(PlacelessSetup, unittest.TestCase):
 
     def setUp(self):
         super(Test, self).setUp()
-        ztapi.provideAdapter(
-            IAttributeAnnotatable, IAnnotations,
-            AttributeAnnotations)
-        ztapi.provideAdapter(
-            IAnnotatable, ICacheable,
-            AnnotationCacheable)
-        self.service = CachingServiceStub()
-        sm.defineService('Caching', ICachingService)
-        sm.provideService('Caching', self.service)
+        ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
+                             AttributeAnnotations)
+        ztapi.provideAdapter(IAnnotatable, ICacheable,
+                             AnnotationCacheable)
+        self._cache = CacheStub()
+        ztapi.provideUtility(ICache, self._cache, "my_cache")
 
     def testGetCacheForObj(self):
-        self.service.caches['my_cache'] = my_cache = CacheStub()
-
         obj = ObjectStub()
-        self.assertEquals(getCacheForObj(obj), None)
-
+        self.assertEquals(getCacheForObject(obj), None)
         ICacheable(obj).setCacheId("my_cache")
-
-        self.assertEquals(getCacheForObj(obj), my_cache)
+        self.assertEquals(getCacheForObject(obj), self._cache)
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(Test),
+    return unittest.TestSuite((
+        unittest.makeSuite(Test),
         ))
 
 if __name__=='__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list