On Aug 12, 5:12 pm, "Edward K. Ream" <[email protected]> wrote:

> Within a script, I could do something like:
>
> p2 = g.findNodeAnywhere(c,'Common unit test code')
> p3 = g.findNodeInTree(c,p2,'class Hello')
> exec(p3.b+'\n')
>
> Now the definition of class Hello is available to my script or unit
> test(!)

Naturally, I wanted to shorten this :-)

The best I can do at present is:

exec(g.findTestScript(c,'@common leoRst test code'))

where g.findTestScript is::

def findTestScript(c,h,where=None):
    if where:
        p = g.findNodeAnywhere(c,where)
        if p:
            p = g.findNodeInTree(c,p,h)
    else:
        p = g.findNodeAnywhere(c,h)

    if p:
        return g.getScript(c,p) # Takes care with ending newline.
    else:
        return None

This is pretty good.  In particular, calling g.getScript means that
@others and section references are valid in the found node! That is,
the script can potentially include the entire tree.

I would also like to eliminate the call to exec in the unit test.
That is, I would like to do the exec within findTestScrip.  If I can
do so, I would change the name to something like g.addTestCode.

The problem is that exec adds the definitions in the *local* context,
and that context is the context of findTestScript, not the caller.
This problem should be solvable...

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to