[PEAK] proper unit testing

R. David Murray rdmurray at bitdance.com
Thu Nov 4 17:56:41 EST 2004

So far I've been getting along with using integration tests run
from my peak runIni script.  Now I'm trying to write proper
unit tests to speed up my test cycle.   I think I've managed to get
a configuration root created and an configuration file loaded into
it.  At least, the first error message about being unable to find
a configuration key is gone now.  However, it seems to be having
trouble finding one of the config keys that is the same file as the
configuration key it is now finding.  The one it can't find is
my LinkRef to the database, from the [Named Services] section.

Hmm.  I guess I'm going to have to post the code (*frown*).  And
yeah, I know the TIMESTAMP thing is gnarly, fixing that is one of
the reasons I want to write these unit test (*grin*).

[Load Settings From]
file = config.fileNearModule('fcgbilling', 'fcgbilling.ini')

[Named Services]
fcgbilling.db = naming.LinkRef('sqlite:/home/rdmurray/proj/fcgbilling/tests/data/testdb')

datadir = config.fileNearModule('fcgbilling.tests', "data")

[Import on Demand]
datetime = "datetime"

TIMESTAMP = lambda descr,value: value and value!='None' and datetime.datetime(*(map(int, value.replace("-", " ").replace(":", " ").replace(".", " ").split()))) or None
BOOLEAN = lambda descr, value: value=='True' and True or False

[Named Services]
fcgbilling.db = naming.LinkRef('sqlite:/home/rdmurray/proj/fcgbilling/data/db')

dbdd = config.fileNearModule('fcgbilling', 'SQLSchema')
datadir = "/home/rdmurray/proj/fcgbilling/data"

from peak.api import config, binding

allSuites = [

def test_suite():
    from peak.util.imports import importSuite
    return importSuite(allSuites)

# shared, default config root for testing
_root = None

def testRoot():

    global _root

    if _root is None:
        from peak.api import config
        _root = binding.Configurable(config.makeRoot())
            config.packageFile(__name__, 'tests.ini'))

    return _root

from unittest import TestCase, makeSuite, TestSuite
from peak.api import *
from fcgbilling.model import *
from fcgbilling.tests import testRoot
from fcgbilling.storage import AccountDM

class TestAccountDM(TestCase):

    def setUp(self):
        self.root = testRoot()
        self.a = AccountDM()

    def checkSomething(self):
        a = self.a
        a.id = '1'
        a.username = 'frank'
        o = self.a['1']
        self.assertEQ(o.id, '1')
        self.assertEQ(o.username, 'frank')

TestClasses = (

def test_suite():
    s = []
    for t in TestClasses:
    return TestSuite(s)

The error that all this gives me is:

NameNotFound: config.MultiKey(<class 'peak.binding.interfaces.IComponentFactory'>, PropertyName('fcgbilling.db')) [resolvedObj=<peak.config.config_components.ConfigurationRoot object at 0x864682c>]

Feel free to point at anthing I'm doing wrong (or just the hard way) aside from
the issue causing the problem, too.  My understanding of how PEAK fits
together is seemingly still in its infancy....


More information about the PEAK mailing list