changeset 37:37557b8fb925 trunk

Moved some of the tests for the strip directive to a new unittest test case to not clutter up the documentation.
author cmlenz
date Sun, 02 Jul 2006 23:10:27 +0000
parents ed370ebfa794
children ee669cb9cccc
files markup/path.py markup/template.py markup/tests/template.py
diffstat 3 files changed, 29 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/markup/path.py
+++ b/markup/path.py
@@ -99,10 +99,10 @@
         
         >>> from markup.input import XML
         >>> xml = XML('<root><elem><child>Text</child></elem></root>')
+
         >>> print Path('child').select(xml)
         <child>Text</child>
         
-        >>> xpath = Path('child')
         >>> print Path('child/text()').select(xml)
         Text
         
--- a/markup/template.py
+++ b/markup/template.py
@@ -470,26 +470,7 @@
       <b>foo</b>
     </div>
     
-    On the other hand, when the attribute evaluates to `False`, the element is
-    not stripped:
-    
-    >>> tmpl = Template('''<div xmlns:py="http://purl.org/kid/ns#">
-    ...   <div py:strip="False"><b>foo</b></div>
-    ... </div>''')
-    >>> print tmpl.generate()
-    <div>
-      <div><b>foo</b></div>
-    </div>
-    
-    Leaving the attribute value empty is equivalent to a truth value:
-    
-    >>> tmpl = Template('''<div xmlns:py="http://purl.org/kid/ns#">
-    ...   <div py:strip=""><b>foo</b></div>
-    ... </div>''')
-    >>> print tmpl.generate()
-    <div>
-      <b>foo</b>
-    </div>
+    Leaving the attribute value empty is equivalent to a truth value.
     
     This directive is particulary interesting for named template functions or
     match templates that do not generate a top-level element:
--- a/markup/tests/template.py
+++ b/markup/tests/template.py
@@ -28,12 +28,12 @@
         Verify that a match template can produce the same kind of element that
         it matched without entering an infinite recursion.
         """
-        tmpl = Template('''<doc xmlns:py="http://purl.org/kid/ns#">
+        tmpl = Template("""<doc xmlns:py="http://purl.org/kid/ns#">
           <elem py:match="elem">
             <div class="elem">${select('*/text()')}</div>
           </elem>
           <elem>Hey Joe</elem>
-        </doc>''')
+        </doc>""")
         self.assertEqual("""<doc>
           <elem>
             <div class="elem">Hey Joe</div>
@@ -45,7 +45,7 @@
         Match directives are applied recursively, meaning that they are also
         applied to any content they may have produced themselves:
         """
-        tmpl = Template('''<doc xmlns:py="http://purl.org/kid/ns#">
+        tmpl = Template("""<doc xmlns:py="http://purl.org/kid/ns#">
           <elem py:match="elem">
             <div class="elem">
               ${select('*/*')}
@@ -56,7 +56,7 @@
               <elem/>
             </subelem>
           </elem>
-        </doc>''')
+        </doc>""")
         self.assertEqual("""<doc>
           <elem>
             <div class="elem">
@@ -76,7 +76,7 @@
         themselves output the element they match, avoiding recursion is even
         more complex, but should work.
         """
-        tmpl = Template('''<html xmlns:py="http://purl.org/kid/ns#">
+        tmpl = Template("""<html xmlns:py="http://purl.org/kid/ns#">
           <body py:match="body">
             <div id="header"/>
             ${select('*/*')}
@@ -88,7 +88,7 @@
           <body>
             <h1>Foo</h1>
           </body>
-        </html>''')
+        </html>""")
         self.assertEqual("""<html>
           <body>
             <div id="header"/><h1>Foo</h1>
@@ -97,6 +97,26 @@
         </html>""", str(tmpl.generate()))
 
 
+class StripDirectiveTestCase(unittest.TestCase):
+    """Tests for the `py:strip` template directive."""
+
+    def test_strip_false(self):
+        tmpl = Template("""<div xmlns:py="http://purl.org/kid/ns#">
+          <div py:strip="False"><b>foo</b></div>
+        </div>""")
+        self.assertEqual("""<div>
+          <div><b>foo</b></div>
+        </div>""", str(tmpl.generate()))
+
+    def test_strip_empty(self):
+        tmpl = Template("""<div xmlns:py="http://purl.org/kid/ns#">
+          <div py:strip=""><b>foo</b></div>
+        </div>""")
+        self.assertEqual("""<div>
+          <b>foo</b>
+        </div>""", str(tmpl.generate()))
+
+
 class TemplateTestCase(unittest.TestCase):
     """Tests for basic template processing, expression evaluation and error
     reporting.
@@ -186,6 +206,7 @@
     suite.addTest(doctest.DocTestSuite(Template.__module__))
     suite.addTest(unittest.makeSuite(TemplateTestCase, 'test'))
     suite.addTest(unittest.makeSuite(MatchDirectiveTestCase, 'test'))
+    suite.addTest(unittest.makeSuite(StripDirectiveTestCase, 'test'))
     return suite
 
 if __name__ == '__main__':
Copyright (C) 2012-2017 Edgewall Software