diff genshi/tests/filters.py @ 261:da3137c427a2 stable-0.3.x

Ported [321:323] to 0.3.x stable branch.
author cmlenz
date Fri, 22 Sep 2006 12:07:23 +0000
parents 84168828b074
children d91cbdeb75e9
line wrap: on
line diff
--- a/genshi/tests/filters.py
+++ b/genshi/tests/filters.py
@@ -12,11 +12,15 @@
 # history and logs, available at http://genshi.edgewall.org/log/.
 
 import doctest
+import os
+import shutil
+import tempfile
 import unittest
 
 from genshi.core import Stream
 from genshi.input import HTML, ParseError
 from genshi.filters import HTMLSanitizer
+from genshi.template import TemplateLoader
 
 
 class HTMLSanitizerTestCase(unittest.TestCase):
@@ -116,9 +120,44 @@
         self.assertEquals(u'<img/>', unicode(html | HTMLSanitizer()))
 
 
+class IncludeFilterTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.dirname = tempfile.mkdtemp(suffix='markup_test')
+
+    def tearDown(self):
+        shutil.rmtree(self.dirname)
+
+    def test_select_inluded_elements(self):
+        file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w')
+        try:
+            file1.write("""<li>$item</li>""")
+        finally:
+            file1.close()
+
+        file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w')
+        try:
+            file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"
+                                 xmlns:py="http://genshi.edgewall.org/">
+              <ul py:match="ul">${select('li')}</ul>
+              <ul py:with="items=(1, 2, 3)">
+                <xi:include href="tmpl1.html" py:for="item in items" />
+              </ul>
+            </html>""")
+        finally:
+            file2.close()
+
+        loader = TemplateLoader([self.dirname])
+        tmpl = loader.load('tmpl2.html')
+        self.assertEqual("""<html>
+              <ul><li>1</li><li>2</li><li>3</li></ul>
+            </html>""", tmpl.generate().render())
+
+
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(HTMLSanitizerTestCase, 'test'))
+    suite.addTest(unittest.makeSuite(IncludeFilterTestCase, 'test'))
     return suite
 
 if __name__ == '__main__':
Copyright (C) 2012-2017 Edgewall Software