Skip to content

Commit

Permalink
Merge remote-tracking branch 'BreakawayConsulting/issue-135-default-d…
Browse files Browse the repository at this point in the history
…elimiters' into issue-135

This is the initial patch for issue #135 from @bennoleslie.
  • Loading branch information
cjerdonek committed Oct 20, 2012
2 parents 34ca106 + d0c65dd commit b8859ff
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pystache/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import re

from pystache.defaults import DELIMITERS
from pystache import defaults
from pystache.parsed import ParsedTemplate


Expand Down Expand Up @@ -228,7 +228,7 @@ class _Parser(object):

def __init__(self, delimiters=None):
if delimiters is None:
delimiters = DELIMITERS
delimiters = defaults.DELIMITERS

self._delimiters = delimiters

Expand Down
60 changes: 60 additions & 0 deletions pystache/tests/test_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import unittest

import pystache
import pystache.defaults

from pystache.tests.common import AssertStringMixin


class TestDefaults(unittest.TestCase, AssertStringMixin):
"""Set of tests to ensure that the user can override defaults."""

def setUp(self):
"""save all the defaults."""
defaults = [
'DECODE_ERRORS', 'DELIMITERS',
'FILE_ENCODING', 'MISSING_TAGS',
'SEARCH_DIRS', 'STRING_ENCODING',
'TAG_ESCAPE', 'TEMPLATE_EXTENSION'
]
self.saved = {}
for e in defaults:
self.saved[e] = getattr(pystache.defaults, e)

def tearDown(self):
for key, value in self.saved.items():
setattr(pystache.defaults, key, value)

def test_tag_escape(self):
"""Test that TAG_ESCAPE default takes effect."""
template = u"{{foo}}"
context = {'foo': '<'}
actual = pystache.render(template, context)
self.assertString(actual, u"&lt;")

pystache.defaults.TAG_ESCAPE = lambda u: u
actual = pystache.render(template, context)
self.assertString(actual, u"<")

def test_delimiters(self):
"""Test that DELIMITERS default takes effect."""
template = u"[[foo]]{{foo}}"
context = {'foo': 'FOO'}
actual = pystache.render(template, context)
self.assertString(actual, u"[[foo]]FOO")

pystache.defaults.DELIMITERS = ('[[', ']]')
actual = pystache.render(template, context)
self.assertString(actual, u"FOO{{foo}}")

def test_missing_tags(self):
"""Test that MISSING_TAGS default take effect."""
template = u"{{foo}}"
context = {}
actual = pystache.render(template, context)
self.assertString(actual, u"")

pystache.defaults.MISSING_TAGS = 'strict'

self.assertRaises(pystache.context.KeyNotFoundError,
pystache.render, template, context)

0 comments on commit b8859ff

Please sign in to comment.