[TIP] I need a DataSet fixture that points into its own table

Phlip phlip2005 at gmail.com
Tue Dec 21 09:03:04 PST 2010


This is a basic tree configuration:

class TreeData(fixture.DataSet):

    class branch:
        tag = 'branch'

    class leaf_one:
        tag = 'leaf_one'
        owner = TreeData.branch

    class leaf_two:
        tag = 'leaf_two'
        owner = TreeData.branch

Python doesn't like that because (unlike real languages) TreeData doesn't
appear in the lookup namespace until it's fully defined.

The work-around is to build a different suite for each tier of the tree:

class TreeData(fixture.DataSet):
    class branch:
        tag = 'branch'

class TreeLeafData(fixture.DataSet):
    class leaf_one:
        tag = 'leaf_one'
        owner = TreeData.branch

    class leaf_two:
        tag = 'leaf_two'
        owner = TreeData.branch

That's really tacky - is there a simpler fix?

(On a related note, how do I supply the tag='my name' automatically, from
the class name just above it?)

-- 
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20101221/6a63f862/attachment.html>


More information about the testing-in-python mailing list