diff markup/tests/template.py @ 166:d43f50402cf2 trunk

Better error reporting for errors in directive expressions, and when `py:otherwise`/`py:when` are used outside a `py:choose` directive. Thanks to Christian Boos for the initial patch.
author cmlenz
date Thu, 17 Aug 2006 14:53:28 +0000
parents 54a4be707664
children ff4f0d89eef7
line wrap: on
line diff
--- a/markup/tests/template.py
+++ b/markup/tests/template.py
@@ -124,6 +124,26 @@
             <span>foo</span>
         </doc>""", str(tmpl.generate()))
 
+    def test_when_outside_choose(self):
+        """
+        Verify that a `when` directive outside of a `choose` directive is
+        reported as an error.
+        """
+        tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
+          <div py:when="xy" />
+        </doc>""")
+        self.assertRaises(TemplateSyntaxError, str, tmpl.generate())
+
+    def test_when_outside_choose(self):
+        """
+        Verify that an `otherwise` directive outside of a `choose` directive is
+        reported as an error.
+        """
+        tmpl = Template("""<doc xmlns:py="http://markup.edgewall.org/">
+          <div py:otherwise="" />
+        </doc>""")
+        self.assertRaises(TemplateSyntaxError, str, tmpl.generate())
+
     def test_as_element(self):
         """
         Verify that the directive can also be used as an element.
Copyright (C) 2012-2017 Edgewall Software