]> Devi Nivas Git - chevron.git/commitdiff
Removed custom exception in favor of a builtin
authornoah morrison <noah@morrison.ph>
Sat, 22 Nov 2014 23:18:17 +0000 (18:18 -0500)
committernoah morrison <noah@morrison.ph>
Sat, 22 Nov 2014 23:18:17 +0000 (18:18 -0500)
chevron/__init__.py
chevron/tokenizer.py
test_spec.py

index 14c6ea87f300132dd8dbd023fa5eaaddc41d7adb..0d4ad77ece0af5544f4d44df79e8397f9fd901ad 100644 (file)
@@ -1,5 +1,4 @@
 from .main import main, cli_main
 from .renderer import render
-from .tokenizer import UnclosedSection
 
-__all__ = ['main', 'render', 'UnclosedSection', 'cli_main']
+__all__ = ['main', 'render', 'cli_main']
index 3b3abd162ec41965bc2073916935ca18d56e9f0d..af3997b3c45c8ec3623185a7a2fde154c02c3f4d 100644 (file)
@@ -1,11 +1,6 @@
 #!/usr/bin/python
 
 
-class UnclosedSection(Exception):
-    """Raised when you have unbalanced section tags"""
-    pass
-
-
 def tokenize(template, def_ldel='{{', def_rdel='}}'):
     """Tokenize a mustache template
 
@@ -117,7 +112,8 @@ def tokenize(template, def_ldel='{{', def_rdel='}}'):
             last_section = open_sections.pop()
             if tag_key != last_section:
                 # Otherwise we need to complain
-                raise UnclosedSection()
+                raise SyntaxError("End tag does not match ."
+                                  "the currently opened section")
 
         # Check right side if we might be a standalone
         if is_standalone and tag_type not in ['variable', 'no escape']:
@@ -149,4 +145,4 @@ def tokenize(template, def_ldel='{{', def_rdel='}}'):
     # If there are any open sections when we're done
     if open_sections:
         # Then we need to complain
-        raise UnclosedSection()
+        raise SyntaxError("End of file while a section was open")
index 8754f6b81e7b4aa661b1609a1491bd7b443796ea..778762582e763ec2fef68a5a27c15b07d663ea59 100755 (executable)
@@ -60,10 +60,8 @@ class ExpandedCoverage(unittest.TestCase):
             'template': '{{# section }} end of file'
         }
 
-        self.assertRaises(chevron.tokenizer.UnclosedSection,
-                          chevron.render, **test1)
-        self.assertRaises(chevron.tokenizer.UnclosedSection,
-                          chevron.render, **test2)
+        self.assertRaises(SyntaxError, chevron.render, **test1)
+        self.assertRaises(SyntaxError, chevron.render, **test2)
 
     def test_unicode_basic(self):
         args = {