[z3-checkins] r33347 - in z3/deliverance/branches/packaged/deliverance: . test-data

cabraham at codespeak.net cabraham at codespeak.net
Mon Oct 16 18:51:30 CEST 2006


Author: cabraham
Date: Mon Oct 16 18:51:26 2006
New Revision: 33347

Modified:
   z3/deliverance/branches/packaged/deliverance/interpreter.py
   z3/deliverance/branches/packaged/deliverance/test-data/test_append.xml
   z3/deliverance/branches/packaged/deliverance/test-data/test_appendorreplace.xml
   z3/deliverance/branches/packaged/deliverance/test-data/test_copy.xml
   z3/deliverance/branches/packaged/deliverance/test-data/test_prepend.xml
   z3/deliverance/branches/packaged/deliverance/test-data/test_replace.xml
   z3/deliverance/branches/packaged/deliverance/tests.py
   z3/deliverance/branches/packaged/deliverance/xslt.py
Log:
Added nocontent='ignore' to xslt version; extended the tests to test for this attribute; fixed a few bugs

Modified: z3/deliverance/branches/packaged/deliverance/interpreter.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/interpreter.py	(original)
+++ z3/deliverance/branches/packaged/deliverance/interpreter.py	Mon Oct 16 18:51:26 2006
@@ -189,7 +189,7 @@
         content_els = copy.deepcopy(content.xpath(rule.attrib[self.RULE_CONTENT_KEY]))
 
         if len(content_els) == 0:
-            if rule.attrib.get(self.NOCONTENT_KEY) == 'ignore':
+            if rule.attrib.get(self.NOCONTENT_KEY) != 'ignore':
                 self.add_to_body_start(theme, self.format_error("no content matched", rule))            
             return       
 

Modified: z3/deliverance/branches/packaged/deliverance/test-data/test_append.xml
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/test-data/test_append.xml	(original)
+++ z3/deliverance/branches/packaged/deliverance/test-data/test_append.xml	Mon Oct 16 18:51:26 2006
@@ -116,6 +116,35 @@
   </output> 
 </deliverance-test>
 
+<!-- tests append command ignores an error when no content is found
+and nocontent='ignore' flag is set -->
+<deliverance-test>
+  <rules xmlns="http://www.plone.org/deliverance">
+    <append theme=".//div[@id='foo']" content="//div[@id='bar']" nocontent='ignore' />
+  </rules>
+
+  <theme base="http://example.com"> 
+    <html><head><title>Blah</title></head><body><div></div><div id="foo">Dummy Content<p>HI!</p></div>
+    </body></html>
+  </theme>
+
+  <content> 
+    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
+  </content>
+  
+  <output>
+<html>
+  <head>
+    <title>Blah</title>
+  </head>
+  <body>
+    <div/>
+    <div id="foo">Dummy Content<p>HI!</p></div>
+  </body>
+</html>
+  </output> 
+</deliverance-test>
+
 
 <!-- tests append command successfully appends the contents of a div tag with all contents of body tag, 
 including unelemented text --> 

Modified: z3/deliverance/branches/packaged/deliverance/test-data/test_appendorreplace.xml
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/test-data/test_appendorreplace.xml	(original)
+++ z3/deliverance/branches/packaged/deliverance/test-data/test_appendorreplace.xml	Mon Oct 16 18:51:26 2006
@@ -198,8 +198,6 @@
 </deliverance-test>
 
 
-
-
 <!-- tests append-or-replace command generates an error when no content is found -->
 <deliverance-test>
   <rules xmlns="http://www.plone.org/deliverance">
@@ -230,5 +228,35 @@
   </output> 
 </deliverance-test>
 
+<!-- tests append-or-replace command ignores error when no content is found 
+and nocontent='ignore' flag is set-->
+<deliverance-test>
+  <rules xmlns="http://www.plone.org/deliverance">
+    <append-or-replace theme=".//div[@id='foo']" content="//span[@id='bar']" nocontent='ignore' />
+  </rules>
+
+  <theme base="http://example.com"> 
+    <html><head><title>Blah</title></head><body><div></div><div id="foo"><span>Dummy Content</span><p>HI!</p></div>
+    </body></html>
+  </theme>
+
+  <content> 
+    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
+  </content>
+  
+  <output>
+<html>
+  <head>
+    <title>Blah</title>
+  </head>
+  <body>
+    <div/>
+    <div id="foo"><span>Dummy Content</span><p>HI!</p></div>
+  </body>
+</html>
+  </output> 
+</deliverance-test>
+
+
 </deliverance-test-suite>
 

Modified: z3/deliverance/branches/packaged/deliverance/test-data/test_copy.xml
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/test-data/test_copy.xml	(original)
+++ z3/deliverance/branches/packaged/deliverance/test-data/test_copy.xml	Mon Oct 16 18:51:26 2006
@@ -154,5 +154,34 @@
   </output> 
 </deliverance-test>
 
+<!-- tests copy command ignores error when no content is found 
+and nocontent='ignore' is set-->
+<deliverance-test>
+  <rules xmlns="http://www.plone.org/deliverance">
+    <copy theme=".//div[@id='foo']" content="//div[@id='bar']" nocontent='ignore'/>
+  </rules>
+
+  <theme base="http://example.com"> 
+    <html><head><title>Blah</title></head><body><div></div><div id="foo">Dummy Content<p>HI!</p></div>
+    </body></html>
+  </theme>
+
+  <content> 
+    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
+  </content>
+  
+  <output>
+<html>
+  <head>
+    <title>Blah</title>
+  </head>
+  <body>
+    <div/>
+    <div id="foo">Dummy Content<p>HI!</p></div>
+  </body>
+</html>
+  </output> 
+</deliverance-test>
+
 
 </deliverance-test-suite>

Modified: z3/deliverance/branches/packaged/deliverance/test-data/test_prepend.xml
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/test-data/test_prepend.xml	(original)
+++ z3/deliverance/branches/packaged/deliverance/test-data/test_prepend.xml	Mon Oct 16 18:51:26 2006
@@ -139,4 +139,34 @@
   </output> 
 </deliverance-test>
 
+
+<!-- tests prepend command ignores error when no content is found 
+and nocontent='ignore' is set-->
+<deliverance-test>
+  <rules xmlns="http://www.plone.org/deliverance">
+    <prepend theme=".//div[@id='foo']" content="//div[@id='bar']" nocontent='ignore' />
+  </rules>
+
+  <theme base="http://example.com"> 
+    <html><head><title>Blah</title></head><body><div></div><div id="foo">Dummy Content<p>HI!</p></div>
+    </body></html>
+  </theme>
+
+  <content> 
+    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
+  </content>
+  
+  <output>
+<html>
+  <head>
+    <title>Blah</title>
+  </head>
+  <body>
+    <div/>
+    <div id="foo">Dummy Content<p>HI!</p></div>
+  </body>
+</html>
+  </output> 
+</deliverance-test>
+
 </deliverance-test-suite>

Modified: z3/deliverance/branches/packaged/deliverance/test-data/test_replace.xml
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/test-data/test_replace.xml	(original)
+++ z3/deliverance/branches/packaged/deliverance/test-data/test_replace.xml	Mon Oct 16 18:51:26 2006
@@ -183,5 +183,35 @@
   </output> 
 </deliverance-test>
 
+<!-- tests replace command ignores error when no content is found 
+and nocontent='ignore' is set-->
+<deliverance-test>
+  <rules xmlns="http://www.plone.org/deliverance">
+    <replace theme=".//div[@id='foo']" content="//div[@id='bar']" nocontent='ignore' />
+  </rules>
+
+  <theme base="http://example.com"> 
+    <html><head><title>Blah</title></head><body><div></div><div id="foo">Dummy Content<p>HI!</p></div>
+    </body></html>
+  </theme>
+
+  <content> 
+    <html><body>leading text <br/> more <p>inside p </p>trailing text</body> tail of body</html>
+  </content>
+  
+  <output>
+<html>
+  <head>
+    <title>Blah</title>
+  </head>
+  <body>
+    <div/>
+    <div id="foo">Dummy Content<p>HI!</p></div>
+  </body>
+</html>
+  </output> 
+</deliverance-test>
+
+
 </deliverance-test-suite>
 

Modified: z3/deliverance/branches/packaged/deliverance/tests.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/tests.py	(original)
+++ z3/deliverance/branches/packaged/deliverance/tests.py	Mon Oct 16 18:51:26 2006
@@ -8,8 +8,9 @@
 
 class DeliveranceTestCase:
 
-    def __init__(self, rules, theme, theme_uri, content, output):
+    def __init__(self, rules, rules_uri, theme, theme_uri, content, output):
         self.rules = rules
+        self.rules_uri = rules_uri
         self.theme = theme
         self.theme_uri = theme_uri
         self.content = content
@@ -19,7 +20,7 @@
         renderer = Renderer(
             theme=self.theme,
             theme_uri=self.theme_uri,
-            rules=self.rules)
+            rule=self.rules, rule_uri=self.rules_uri)
         actual = renderer.render(self.content)
         reporter = []
         result = xml_compare(actual, self.output, reporter.append)
@@ -82,6 +83,7 @@
 
         case = DeliveranceTestCase(
             rules=rules,
+            rules_uri = fn, # not sure about this
             theme=themebody,
             theme_uri=el.find('theme').attrib['base'],
             content=contentbody,

Modified: z3/deliverance/branches/packaged/deliverance/xslt.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/xslt.py	(original)
+++ z3/deliverance/branches/packaged/deliverance/xslt.py	Mon Oct 16 18:51:26 2006
@@ -28,22 +28,24 @@
     content at render time
     """
 
-    def __init__(self,theme,theme_uri,rules,reference_resolver=None):
+    def __init__(self,theme,theme_uri,rule, rule_uri, reference_resolver=None):
         theme_copy = copy.deepcopy(theme)
+        self.rules = rule
+        self.rules_uri = rule_uri
 
         self.fixup_links(theme_copy,theme_uri)
         self.xsl_escape_comments(theme_copy)
 
         if reference_resolver:
-            xinclude.include(rules,loader=reference_resolver)
+            xinclude.include(self.rules, self.rules_uri, loader=reference_resolver)
 
-        debug = rules.get("debug", None)
+        debug = self.rules.get("debug", None)
         if debug and debug.lower() == "true":
             self.debug = True
         else:
             self.debug = False
 
-        self.apply_rules(rules,theme_copy)
+        self.apply_rules(self.rules,theme_copy)
         xslt_wrapper = etree.XML(xslt_wrapper_skel)
         insertion_point = xslt_wrapper.xpath("//xsl:transform/xsl:template[@match='/']",
                                              nsmap)[0]
@@ -214,8 +216,12 @@
         """
         adds a node to the body of theme which produces an error 
         message if no content is matched by a rule given 
-        during the transformation 
+        during the transformation; no message is produced
+        if nocontent='ignore' attribute is set
         """
+        if rule.get(self.NOCONTENT_KEY) == 'ignore':
+            return
+
         err = self.format_error("no content matched", rule)
         if err:
             conditional = etree.Element("{%s}if" % nsmap["xsl"])


More information about the z3-checkins mailing list