SVN: r25658 - trunk/quixote/test
David Binger <dbinger-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Mon, 22 Nov 2004 11:22:22 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: dbinger
Date: 2004-11-22 09:16:20 -0500 (Mon, 22 Nov 2004)
New Revision: 25658
Added:
trunk/quixote/test/utest_ptl.py
Log:
Add a unit test for the ptl compiler.
Added: trunk/quixote/test/utest_ptl.py
===================================================================
--- trunk/quixote/test/utest_ptl.py 2004-11-19 23:14:39 UTC (rev 25657)
+++ trunk/quixote/test/utest_ptl.py 2004-11-22 14:16:20 UTC (rev 25658)
@@ -0,0 +1,59 @@
+#!/www/python/bin/python
+from sancho.utest import UTest
+from quixote.ptl_compile import compile_template
+from cStringIO import StringIO
+from quixote.html import TemplateIO, htmltext
+
+def run_ptl(*source):
+ """
+ Compile the given lines of source code using the ptl compiler
+ and run the resulting compiled code.
+ """
+ # When the ptl compiler compiles a module, it places _q_TemplateIO
+ # and _q_htmltext into the globals of the module. Here, we don't
+ # have a module, but we provide these same globals for eval.
+ eval(compile_template(StringIO('\n'.join(source)), 'test'),
+ dict(_q_TemplateIO=TemplateIO, _q_htmltext=htmltext))
+
+class Test (UTest):
+
+ def check_html(self):
+ run_ptl(
+ 'from quixote.html import htmltext',
+ 'def f [html] (a):',
+ ' "&"',
+ ' a',
+ 'assert type(f(1)) == htmltext',
+ 'assert f("") == "&"',
+ 'assert f("&") == "&&"',
+ 'assert f(htmltext("&")) == "&&"')
+
+ def check_plain(self):
+ run_ptl(
+ 'from quixote.html import htmltext',
+ 'def f [plain] (a):',
+ ' "&"',
+ ' a',
+ 'assert type(f(1)) == str',
+ 'assert f("") == "&"',
+ 'assert f("&") == "&&"',
+ 'assert f(htmltext("&")) == "&&"',
+ 'assert type(f(htmltext("&"))) == str')
+
+ def check_syntax(self):
+ run_ptl('def f(a):\n a')
+ try:
+ run_ptl('def f [] (a):\n a')
+ assert 0
+ except SyntaxError, e:
+ assert e.lineno == 1
+ try:
+ run_ptl('def f [HTML] (a):\n a')
+ assert 0
+ except SyntaxError, e:
+ assert e.lineno == 1
+
+
+if __name__ == "__main__":
+ Test()
+
Property changes on: trunk/quixote/test/utest_ptl.py
___________________________________________________________________
Name: svn:keywords
+ "HeadURL Id"