| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | import unittest |
|---|
| 4 | |
|---|
| 5 | from genshi.template import MarkupTemplate |
|---|
| 6 | |
|---|
| 7 | tmpl_data = """<div xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/"> |
|---|
| 8 | REPLACEME |
|---|
| 9 | </div>""" |
|---|
| 10 | |
|---|
| 11 | simple_replace = """<py:if test="True" py:strip=""> |
|---|
| 12 | var x = 'bar'; |
|---|
| 13 | </py:if>""" |
|---|
| 14 | |
|---|
| 15 | replace_and_variable = """<py:if test="True" py:strip=""> |
|---|
| 16 | var x = '$d'; |
|---|
| 17 | </py:if>""" |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | class TestPyStripWithPyIf(unittest.TestCase): |
|---|
| 22 | def test_pystrip_and_pyif(self): |
|---|
| 23 | def generate(replacement_string): |
|---|
| 24 | data = tmpl_data.replace('REPLACEME', replacement_string) |
|---|
| 25 | tmpl = MarkupTemplate(data) |
|---|
| 26 | return tmpl.generate(d="bar").render('xhtml', doctype='xhtml') |
|---|
| 27 | |
|---|
| 28 | simple_output = generate(simple_replace) |
|---|
| 29 | wrong_output = generate(replace_and_variable) |
|---|
| 30 | self.assertEquals(simple_output, wrong_output) |
|---|
| 31 | |
|---|
| 32 | |
|---|