[Zodb-checkins] CVS: ZODB3/Persistence/tests - __init__.py:1.1.6.1 testPersistent.py:1.1.2.1

Jeremy Hylton jeremy at zope.com
Thu Jul 3 14:25:22 EDT 2003


Update of /cvs-repository/ZODB3/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv19607/Persistence/tests

Added Files:
      Tag: zodb33-devel-branch
	__init__.py testPersistent.py 
Log Message:
Start a test module for Persistent, and convert attribute access to
_p_oid and _p_jar to use getsets.



=== Added File ZODB3/Persistence/tests/__init__.py ===
# package


=== Added File ZODB3/Persistence/tests/testPersistent.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
import unittest

from Persistence import Persistent
from Persistence.cPickleCache import PickleCache
from ZODB.utils import p64

class Jar(object):
    """Testing stub for _p_jar attribute."""

    def __init__(self):
        self.cache = PickleCache(self)
        self.oid = 1

    def add(self, obj):
        obj._p_oid = p64(self.oid)
        self.oid += 1
        obj._p_jar = self
        self.cache[obj._p_oid] = obj

    def close(self):
        self.cache.clear()

    # the following methods must be implemented to be a jar

    def setklassstate(self):
        pass

class P(Persistent):
    pass

class PersistenceTest(unittest.TestCase):

    def setUp(self):
        self.jar = Jar()

    def tearDown(self):
        self.jar.close()

    def testOidAndJarAttrs(self):
        obj = P()
        self.assertEqual(obj._p_oid, None)
        obj._p_oid = 12
        self.assertEqual(obj._p_oid, 12)
        del obj._p_oid

        self.jar.add(obj)

        # Can't change oid of cache object.
        def deloid():
            del obj._p_oid
        self.assertRaises(ValueError, deloid)
        def setoid():
            obj._p_oid = 12
        self.assertRaises(ValueError, setoid)

        def deloid():
            del obj._p_jar
        self.assertRaises(ValueError, deloid)
        def setoid():
            obj._p_jar = 12
        self.assertRaises(ValueError, setoid)
        
        

def test_suite():
    return unittest.makeSuite(PersistenceTest)




More information about the Zodb-checkins mailing list