[Zope-Checkins] CVS: Zope3/lib/python/Persistence/tests - _pmtest.py:1.1 testModule.py:1.1

Jeremy Hylton jeremy@zope.com
Fri, 21 Jun 2002 15:06:48 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence/tests
In directory cvs.zope.org:/tmp/cvs-serv9075/tests

Added Files:
	_pmtest.py testModule.py 
Log Message:
Minimally functional persistent modules.


=== Added File Zope3/lib/python/Persistence/tests/_pmtest.py ===
"""A simple module"""

# XXX why aren't modules pickleable?
# import os
# from xml import sax

a = 1
b = 2
c = 3

def f(x):
    return a * x ** 2 + b * x + c



=== Added File Zope3/lib/python/Persistence/tests/testModule.py ===
import os
import unittest

from ZODB.MappingStorage import DB

from Persistence.Module import PersistentModuleImporter
from Persistence import tests

class TestModule(unittest.TestCase):

    def setUp(self):
        self.db = DB()
        self.root = self.db.open().root()
        self.importer = PersistentModuleImporter(self.root, verbose=1)
        self.importer.install()
        _dir, _file = os.path.split(tests.__file__)
        self._pmtest = os.path.join(_dir, "_pmtest.py")

    def tearDown(self):
        self.importer.uninstall()

    def testModule(self):
        self.importer.module_from_file("pmtest", self._pmtest)
        get_transaction().commit()
        import pmtest
        pmtest._p_deactivate()
        assert pmtest.a == 1
        pmtest.f(4)

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