[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Caching/RAMCache/tests - __init__.py:1.1 test_RAMCache.py:1.1

Albertas Agejevas alga@codeworks.lt
Thu, 31 Oct 2002 11:01:41 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Caching/RAMCache/tests
In directory cvs.zope.org:/tmp/cvs-serv24574/RAMCache/tests

Added Files:
	__init__.py test_RAMCache.py 
Log Message:
A port of RAMCacheManager to Zope3.

The current architecture is very much based on the Zope2 RAMCacheManager,
so it might use some refactoring in the future.  For instance, two
different caching interfaces can be derived: one for the data (which does
not care for request) and one for the views (which treats request data in
some special way). The current implementation should work both ways.


=== Added File Zope3/lib/python/Zope/App/Caching/RAMCache/tests/__init__.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
# 
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: __init__.py,v 1.1 2002/10/31 16:01:40 alga Exp $
"""


=== Added File Zope3/lib/python/Zope/App/Caching/RAMCache/tests/test_RAMCache.py === (414/514 lines abridged)
#############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Unit tests for RAM Cache.

$Id: test_RAMCache.py,v 1.1 2002/10/31 16:01:40 alga Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Caching.tests.testICache import BaseICacheTest
from Zope.App.tests.PlacelessSetup import PlacelessSetup
from Zope.App.Traversing.IPhysicallyLocatable import IPhysicallyLocatable
from Zope.ContextWrapper import Wrapper
from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
from Interface.Verify import verifyClass, verifyObject
from time import time


#############################################################################
# If your tests change any global registries, then uncomment the
# following import and include CleanUp as a base class of your
# test. It provides a setUp and tearDown that clear global data that
# has registered with the test cleanup framework.  If your class has
# its own setUp or tearDown, make sure you call the CleanUp setUp and
# tearDown from them, or the benefits of using CleanUp will be lost.
# Don't use CleanUp based tests outside the Zope package.

# from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup

class Request:
    def __init__(self, dict=None):
        if dict is None:
            dict = {'foo': 1, 'bar': 2, 'baz': 3}
        self._dict = dict
    def __getitem__(self, key):
        return self._dict[key]

class Locatable:
    __implements__ = IPhysicallyLocatable


[-=- -=- -=- 414 lines omitted -=- -=- -=-]

        s = Storage(maxEntries=3)
        object = 'object'
        object2 = 'object2'
        key1 = ('view1', (), ('answer', 42))
        key2 = ('view2', (), ('answer', 42))
        key3 = ('view3', (), ('answer', 42))
        value = 'yes'
        timestamp = time()
        s._data = {object:  {key1: [value, 1, 10],
                             key2: [value, 2, 5],
                             key3: [value, 3, 2]},
                   object2: {key1: [value, 4, 2],
                             key2: [value, 5, 1],
                             key3: [value, 6, 1]}}

        cleared = {object:  {key1: [value, 1, 0],
                             key2: [value, 2, 0],
                             key3: [value, 3, 0]},
                   object2: {key1: [value, 4, 0],
                             key2: [value, 5, 0],
                             key3: [value, 6, 0]}}

        s._clearAccessCounters()
        self.assertEqual(s._data, cleared, "access counters not cleared")


class TestModule(TestCase):

    def test_locking(self):
        from Zope.App.Caching.RAMCache.RAMCache import writelock
        writelock.acquire()
        try:
            self.failUnless(writelock.locked(), "locks don't work")
        finally:
            writelock.release()
    
#############################################################################

class Test(TestCase):
    pass

def test_suite():
    return TestSuite((
        makeSuite(TestRAMCache),
        makeSuite(TestStorage),
        makeSuite(TestModule),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')