[ZPT] unit testing new expression

Evan Simpson evan@zope.com
Mon, 01 Oct 2001 12:39:11 -0400


Dethe Elza wrote:

> 1) Are there examples of unit tests for expressions?  The tests/ 
> directory has some examples of compiling expressions, but there didn't 
> appear to be full test suites.  Are there more tests available, perhaps 
> in CVS?  If so, where is the CVS located for ZPT?  I didn't see it 
> mentioned on the wiki.


The test suite for PageTemplates is very weak.  This would be a great place 
for community contributions ;-)

On cvs.zope.org, the parts of ZPT are at Packages/TAL, Packages/ZTUtils, and 
  Products/PageTemplates.  Under the newly rationalized CVS arrangement, 
anything that goes in lib/python is under Packages/, and all Products are 
under Products/.


> 2) What do I need to do to make the namespaces of the PageTemplate 
> available to the expression when it is called?  This is what I'm having 
> trouble testing, so the two questions are intimately related.

When a compiled TALES expression object is called, a single Context object 
is passed to it.  This has several namespaces as attributes.  'vars' is the 
complete namespace, while 'local_vars' and 'global_vars' are dictionaries of 
local and global names.  You can also use the Context object's 'evaluate' 
method to evaluate other expressions.

Cheers,

Evan @ Zope