| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | import unittest |
|---|
| 4 | import re |
|---|
| 5 | |
|---|
| 6 | from genshi.template import MarkupTemplate |
|---|
| 7 | |
|---|
| 8 | tmpl_data="""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 9 | <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/"> |
|---|
| 10 | |
|---|
| 11 | <py:match path="div[@id='content']/h1" once="True"> |
|---|
| 12 | <h1>Create New Foo</h1> |
|---|
| 13 | </py:match> |
|---|
| 14 | |
|---|
| 15 | <py:match path="body" once="true" buffer="false"><body> |
|---|
| 16 | ${select('*|text()')} |
|---|
| 17 | </body></py:match> |
|---|
| 18 | |
|---|
| 19 | <py:match path="body" once="true" buffer="false"><body> |
|---|
| 20 | <div id="main"> |
|---|
| 21 | ${select('*|text()')} |
|---|
| 22 | </div> |
|---|
| 23 | </body></py:match> |
|---|
| 24 | |
|---|
| 25 | <body> |
|---|
| 26 | <div id="content" class="ticket"> |
|---|
| 27 | <h1>Create New Ticket</h1> |
|---|
| 28 | </div> |
|---|
| 29 | </body> |
|---|
| 30 | </html>""" |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | class TestNoMatchWithSingleSlash(unittest.TestCase): |
|---|
| 34 | def test_no_match(self): |
|---|
| 35 | tmpl = MarkupTemplate(tmpl_data) |
|---|
| 36 | output = tmpl.generate().render('xhtml', doctype='xhtml') |
|---|
| 37 | print output |
|---|
| 38 | self.assertTrue("Create New Foo" in output) |
|---|
| 39 | |
|---|
| 40 | def test_match_with_double_slash(self): |
|---|
| 41 | # Not sure if this is the wanted behavior |
|---|
| 42 | tmpl = MarkupTemplate(tmpl_data.replace("]/h1", "]//h1")) |
|---|
| 43 | output = tmpl.generate().render('xhtml', doctype='xhtml') |
|---|
| 44 | self.assertTrue("Create New Foo" in output) |
|---|
| 45 | |
|---|
| 46 | |
|---|