Mercurial > genshi > genshi-test
comparison markup/tests/template.py @ 104:e9259920db05
Added `py:with` directive based on Jonas' patch in #17.
author | cmlenz |
---|---|
date | Thu, 27 Jul 2006 09:22:17 +0000 |
parents | 242610137d1f |
children | df44110ca91d |
comparison
equal
deleted
inserted
replaced
103:70ec95c8d1ea | 104:e9259920db05 |
---|---|
412 self.assertEqual("""<div> | 412 self.assertEqual("""<div> |
413 <b>foo</b> | 413 <b>foo</b> |
414 </div>""", str(tmpl.generate())) | 414 </div>""", str(tmpl.generate())) |
415 | 415 |
416 | 416 |
417 class WithDirectiveTestCase(unittest.TestCase): | |
418 """Tests for the `py:with` template directive.""" | |
419 | |
420 def test_shadowing(self): | |
421 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> | |
422 ${x} | |
423 <span py:with="x = x * 2" py:replace="x"/> | |
424 ${x} | |
425 </div>""") | |
426 self.assertEqual("""<div> | |
427 42 | |
428 84 | |
429 42 | |
430 </div>""", str(tmpl.generate(Context(x=42)))) | |
431 | |
432 def test_as_element(self): | |
433 tmpl = Template("""<div xmlns:py="http://markup.edgewall.org/"> | |
434 <py:with vars="x = x * 2">${x}</py:with> | |
435 </div>""") | |
436 self.assertEqual("""<div> | |
437 84 | |
438 </div>""", str(tmpl.generate(Context(x=42)))) | |
439 | |
440 | |
417 class TemplateTestCase(unittest.TestCase): | 441 class TemplateTestCase(unittest.TestCase): |
418 """Tests for basic template processing, expression evaluation and error | 442 """Tests for basic template processing, expression evaluation and error |
419 reporting. | 443 reporting. |
420 """ | 444 """ |
421 | 445 |
576 suite.addTest(unittest.makeSuite(DefDirectiveTestCase, 'test')) | 600 suite.addTest(unittest.makeSuite(DefDirectiveTestCase, 'test')) |
577 suite.addTest(unittest.makeSuite(ForDirectiveTestCase, 'test')) | 601 suite.addTest(unittest.makeSuite(ForDirectiveTestCase, 'test')) |
578 suite.addTest(unittest.makeSuite(IfDirectiveTestCase, 'test')) | 602 suite.addTest(unittest.makeSuite(IfDirectiveTestCase, 'test')) |
579 suite.addTest(unittest.makeSuite(MatchDirectiveTestCase, 'test')) | 603 suite.addTest(unittest.makeSuite(MatchDirectiveTestCase, 'test')) |
580 suite.addTest(unittest.makeSuite(StripDirectiveTestCase, 'test')) | 604 suite.addTest(unittest.makeSuite(StripDirectiveTestCase, 'test')) |
605 suite.addTest(unittest.makeSuite(WithDirectiveTestCase, 'test')) | |
581 return suite | 606 return suite |
582 | 607 |
583 if __name__ == '__main__': | 608 if __name__ == '__main__': |
584 unittest.main(defaultTest='suite') | 609 unittest.main(defaultTest='suite') |