summaryrefslogtreecommitdiff
path: root/grc/tests/test_block_templates.py
diff options
context:
space:
mode:
authorSebastian Koslowski <sebastian.koslowski@gmail.com>2016-05-03 17:13:08 +0200
committerJohnathan Corgan <johnathan@corganlabs.com>2017-06-29 09:16:49 -0700
commit7f7fa2f91467fdb2b11312be8562e7b51fdeb199 (patch)
tree24268bac15b9920d2a15ddbb45eaf3b9b03718a1 /grc/tests/test_block_templates.py
parent44cae388881821942e691a4d69a923bbd8d347db (diff)
grc: added yaml/mako support
Includes basic converter from XML/Cheetah to YAML/Mako based block format.
Diffstat (limited to 'grc/tests/test_block_templates.py')
-rw-r--r--grc/tests/test_block_templates.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/grc/tests/test_block_templates.py b/grc/tests/test_block_templates.py
new file mode 100644
index 0000000000..df9ab37550
--- /dev/null
+++ b/grc/tests/test_block_templates.py
@@ -0,0 +1,45 @@
+import pytest
+
+from grc.core.blocks._templates import MakoTemplates
+from grc.core.errors import TemplateError
+
+
+class Block(object):
+ namespace_templates = {}
+
+ templates = MakoTemplates(None)
+
+ def __init__(self, **kwargs):
+ self.namespace_templates.update(kwargs)
+
+
+def test_simple():
+ t = MakoTemplates(_bind_to=Block(num='123'), test='abc${num}')
+ assert t['test'] == 'abc${num}'
+ assert t.render('test') == 'abc123'
+ assert 'abc${num}' in t._template_cache
+
+
+def test_instance():
+ block = Block(num='123')
+ block.templates['test'] = 'abc${num}'
+ assert block.templates.render('test') == 'abc123'
+ assert block.templates is block.__dict__['templates']
+
+
+def test_list():
+ templates = ['abc${num}', '${2 * num}c']
+ t = MakoTemplates(_bind_to=Block(num='123'), test=templates)
+ assert t['test'] == templates
+ assert t.render('test') == ['abc123', '123123c']
+ assert set(templates) == set(t._template_cache.keys())
+
+
+def test_parse_error():
+ with pytest.raises(TemplateError):
+ MakoTemplates(_bind_to=Block(num='123'), test='abc${num NOT CLOSING').render('test')
+
+
+def test_parse_error2():
+ with pytest.raises(TemplateError):
+ MakoTemplates(_bind_to=Block(num='123'), test='abc${ WRONG_VAR }').render('test')