Attachment 'test_html_out.diff'

Download

   1 diff -r 26da1af34568 MoinMoin/converter2/_tests/test_html_out.py
   2 --- a/MoinMoin/converter2/_tests/test_html_out.py	Mon Jun 28 15:44:25 2010 +0200
   3 +++ b/MoinMoin/converter2/_tests/test_html_out.py	Wed Jun 30 15:24:17 2010 +0200
   4 @@ -8,7 +8,17 @@
   5  import py.test
   6  import re
   7  
   8 +try:
   9 +    from lxml import etree
  10 +except:
  11 +    py.test.skip("lxml module required to run test for html_in converter.")
  12 +
  13  from MoinMoin.converter2.html_out import *
  14 +from emeraldtree.tree import *
  15 +from MoinMoin import log
  16 +logging = log.getLogger(__name__)
  17 +import StringIO
  18  
  19  
  20  class Base(object):
  21 @@ -36,10 +46,12 @@
  22          tree.write(file, namespaces=self.output_namespaces, **options)
  23          return self.output_re.sub(u'', file.getvalue())
  24  
  25 -    def do(self, input, output, args={}):
  26 +    def do(self, input, xpath, args={}):
  27          out = self.conv(self.handle_input(input), **args)
  28 -        assert self.handle_output(out) == output
  29 -
  30 +        string_to_parse = self.handle_output(out)
  31 +        logging.debug("After the HTML_OUT conversion : %s" % string_to_parse)
  32 +        tree = etree.parse(StringIO.StringIO(string_to_parse))
  33 +        assert (tree.xpath(xpath))
  34  
  35  class TestConverter(Base):
  36      def setup_class(self):
  37 @@ -48,33 +60,33 @@
  38      def test_base(self):
  39          data = [
  40              ('<page:page><page:body><page:p>Test</page:p></page:body></page:page>',
  41 -                '<div><p>Test</p></div>'),
  42 +                '/div[p="Test"]'),
  43              ('<page:page><page:body><page:h>Test</page:h></page:body></page:page>',
  44 -                '<div><h1>Test</h1></div>'),
  45 +                '/div[h1="Test"]'),
  46              ('<page:page><page:body><page:h page:outline-level="2">Test</page:h></page:body></page:page>',
  47 -                '<div><h2>Test</h2></div>'),
  48 +                '/div[h2="Test"]'),
  49              ('<page:page><page:body><page:h page:outline-level="6">Test</page:h></page:body></page:page>',
  50 -                '<div><h6>Test</h6></div>'),
  51 +                '/div[h6="Test"]'),
  52              ('<page:page><page:body><page:h page:outline-level="7">Test</page:h></page:body></page:page>',
  53 -                '<div><h6>Test</h6></div>'),
  54 +                '/div[h6="Test"]'),
  55              ('<page:page><page:body><page:a xlink:href="uri:test">Test</page:a></page:body></page:page>',
  56 -                '<div><a href="uri:test">Test</a></div>'),
  57 +              '/div/a[text()="Test"][@href="uri:test"]'),
  58              ('<page:page><page:body><page:p>Test<page:line-break/>Test</page:p></page:body></page:page>',
  59 -                '<div><p>Test<br />Test</p></div>'),
  60 +                '/div/p/br'),
  61              ('<page:page><page:body><page:p>Test<page:span>Test</page:span></page:p></page:body></page:page>',
  62 -                '<div><p>Test<span>Test</span></p></div>'),
  63 +                '/div/p[text()="Test"]/span[text()="Test"]'),
  64              ('<page:page><page:body><page:p><page:emphasis>Test</page:emphasis></page:p></page:body></page:page>',
  65 -                '<div><p><em>Test</em></p></div>'),
  66 +                '/div/p[em="Test"]'),
  67              ('<page:page><page:body><page:p><page:strong>Test</page:strong></page:p></page:body></page:page>',
  68 -                '<div><p><strong>Test</strong></p></div>'),
  69 +                '/div/p[strong="Test"]'),
  70              ('<page:page><page:body><page:blockcode>Code</page:blockcode></page:body></page:page>',
  71 -                '<div><pre>Code</pre></div>'),
  72 +                '/div[pre="Code"]'),
  73              ('<page:page><page:body><page:p><page:code>Code</page:code></page:p></page:body></page:page>',
  74 -                '<div><p><tt>Code</tt></p></div>'),
  75 +                '/div/p[tt="Code"]'),
  76              ('<page:page><page:body><page:separator/></page:body></page:page>',
  77 -                '<div><hr /></div>'),
  78 +                '/div/hr'),
  79              ('<page:page><page:body><page:div><page:p>Text</page:p></page:div></page:body></page:page>',
  80 -                '<div><div><p>Text</p></div></div>'),
  81 +                '/div/div[p="Text"]'),
  82          ]
  83          for i in data:
  84              yield (self.do, ) + i
  85 @@ -82,9 +94,9 @@
  86      def test_body(self):
  87          data = [
  88              ('<page><body /></page>',
  89 -                '<div />'),
  90 +                '/div'),
  91              ('<page><body class="red" /></page>',
  92 -                '<div class="red" />'),
  93 +                '/div[@class="red"]'),
  94          ]
  95          for i in data:
  96              yield (self.do, ) + i
  97 @@ -92,7 +104,7 @@
  98      def test_html(self):
  99          data = [
 100              ('<html:div html:id="a" id="b"><html:p id="c">Test</html:p></html:div>',
 101 -                '<div id="a"><p id="c">Test</p></div>'),
 102 +                '/div[@id="a"]/p[@id="c"][text()="Test"]'),
 103          ]
 104          for i in data:
 105              yield (self.do, ) + i
 106 @@ -100,13 +112,31 @@
 107      def test_inline_part(self):
 108          data = [
 109              ('<page><body><p><inline-part><inline-body>Test</inline-body></inline-part></p></body></page>',
 110 -                '<div><p><span>Test</span></p></div>'),
 111 +                '/div/p[span="Test"]'),
 112              ('<page><body><p><inline-part alt="Alt" /></p></body></page>',
 113 -                '<div><p><span>Alt</span></p></div>'),
 114 +                '/div/p[span="Alt"]'),
 115              ('<page><body><p><inline-part><error /></inline-part></p></body></page>',
 116 -                '<div><p><span class="error">Error</span></p></div>'),
 117 +                '/div/p/span[@class="error"][text()="Error"]'),
 118              ('<page><body><p><inline-part><error>Text</error></inline-part></p></body></page>',
 119 -                '<div><p><span class="error">Text</span></p></div>'),
 120 +                '/div/p/span[@class="error"][text()="Text"]'),
 121 +        ]
 122 +        for i in data:
 123 +            yield (self.do, ) + i
 124 +
 125 +    def test_span(self):
 126 +        data = [
 127 +            ('<page><body><p><span baseline-shift="sub">sub</span>script</p></body></page>',
 128 +                '/div/p[text()="script"][sub="sub"]'),
 129 +            ('<page><body><p><span baseline-shift="super">super</span>script</p></body></page>',
 130 +                '/div/p[text()="script"][sup="super"]'),
 131 +            ('<page><body><p><span text-decoration="underline">underline</span></p></body></page>',
 132 +                '/div/p[ins="underline"]'),
 133 +            ('<page><body><p><span text-decoration="line-through">stroke</span></p></body></page>',
 134 +                '/div/p[del="stroke"]'),
 135 +            ('<page><body><p><span font-size="85%">small</span></p></body></page>',
 136 +                '/div/p[small="small"]'),
 137 +            ('<page><body><p><span font-size="120%">big</span></p></body></page>',
 138 +                '/div/p[big="big"]'),
 139          ]
 140          for i in data:
 141              yield (self.do, ) + i
 142 @@ -114,11 +144,19 @@
 143      def test_list(self):
 144          data = [
 145              ('<page><body><list item-label-generate="unordered"><list-item><list-item-body>Item</list-item-body></list-item></list></body></page>',
 146 -                '<div><ul><li>Item</li></ul></div>'),
 147 +                '/div/ul[li="Item"]'),
 148              ('<page><body><list item-label-generate="ordered"><list-item><list-item-body>Item</list-item-body></list-item></list></body></page>',
 149 -                '<div><ol><li>Item</li></ol></div>'),
 150 +                '/div/ol[li="Item"]'),
 151              ('<page><body><list><list-item><list-item-label>Label</list-item-label><list-item-body>Item</list-item-body></list-item></list></body></page>',
 152 -                '<div><dl><dt>Label</dt><dd>Item</dd></dl></div>'),
 153 +                '/div/dl[dt="Label"][dd="Item"]'),
 154 +            ('<page><body><list item-label-generate="ordered" list-style-type="upper-alpha"><list-item><list-item-body>Item</list-item-body></list-item></list></body></page>',
 155 +                '/div/ol[@type="A"][li="Item"]'),
 156 +            ('<page><body><list item-label-generate="ordered" list-style-type="lower-alpha"><list-item><list-item-body>Item</list-item-body></list-item></list></body></page>',
 157 +                '/div/ol[@type="a"][li="Item"]'),
 158 +            ('<page><body><list item-label-generate="ordered" list-style-type="upper-roman"><list-item><list-item-body>Item</list-item-body></list-item></list></body></page>',
 159 +                '/div/ol[@type="I"][li="Item"]'),
 160 +            ('<page><body><list item-label-generate="ordered" list-style-type="lower-roman"><list-item><list-item-body>Item</list-item-body></list-item></list></body></page>',
 161 +                '/div/ol[@type="i"][li="Item"]'),
 162          ]
 163          for i in data:
 164              yield (self.do, ) + i
 165 @@ -126,9 +164,9 @@
 166      def test_object(self):
 167          data = [
 168              ('<page><body><object xlink:href="href"/></body></page>',
 169 -                '<div><object data="href" /></div>'),
 170 +                '/div/object[@data="href"]'),
 171              ('<page><body><object xlink:href="href.png"/></body></page>',
 172 -                '<div><img src="href.png" /></div>'),
 173 +                '/div/img[@src="href.png"]'),
 174          ]
 175          for i in data:
 176              yield (self.do, ) + i
 177 @@ -136,13 +174,13 @@
 178      def test_part(self):
 179          data = [
 180              ('<page><body><part><body><p>Test</p></body></part></body></page>',
 181 -                '<div><div><p>Test</p></div></div>'),
 182 +                '/div/div[p="Test"]'),
 183              ('<page><body><part alt="Alt" /></body></page>',
 184 -                '<div><p>Alt</p></div>'),
 185 +                '/div[p="Alt"]'),
 186              ('<page><body><part><error /></part></body></page>',
 187 -                '<div><p class="error">Error</p></div>'),
 188 +                '/div/p[text()="Error"][@class="error"]'),
 189              ('<page><body><part><error>Error</error></part></body></page>',
 190 -                '<div><p class="error">Error</p></div>'),
 191 +                '/div/p[@class="error"][text()="Error"]'),
 192          ]
 193          for i in data:
 194              yield (self.do, ) + i
 195 @@ -150,9 +188,9 @@
 196      def test_style(self):
 197          data = [
 198              ('<page><body><p style="font-size: 1em">Text</p></body></page>',
 199 -                '<div><p style="font-size: 1em">Text</p></div>'),
 200 +              '/div/p[@style="font-size: 1em"][text()="Text"]'),
 201              ('<page><body><p style="color: black; font-size: 1em">Text</p></body></page>',
 202 -                '<div><p style="color: black; font-size: 1em">Text</p></div>'),
 203 +              '/div/p[@style="color: black; font-size: 1em"][text()="Text"]'),
 204          ]
 205          for i in data:
 206              yield (self.do, ) + i
 207 @@ -160,11 +198,11 @@
 208      def test_table(self):
 209          data = [
 210              ('<page><body><table><table-header><table-row><table-cell>Header</table-cell></table-row></table-header><table-footer><table-row><table-cell>Footer</table-cell></table-row></table-footer><table-body><table-row><table-cell>Cell</table-cell></table-row></table-body></table></body></page>',
 211 -                '<div><table><thead><tr><td>Header</td></tr></thead><tfoot><tr><td>Footer</td></tr></tfoot><tbody><tr><td>Cell</td></tr></tbody></table></div>'),
 212 +                '/div/table[thead/tr[td="Header"]][tfoot/tr[td="Footer"]][tbody/tr[td="Cell"]]'),
 213              ('<page><body><table><table-body><table-row><table-cell number-columns-spanned="2">Cell</table-cell></table-row></table-body></table></body></page>',
 214 -                '<div><table><tbody><tr><td colspan="2">Cell</td></tr></tbody></table></div>'),
 215 +                '/div/table/tbody/tr/td[@colspan="2"][text()="Cell"]'),
 216              ('<page><body><table><table-body><table-row><table-cell number-rows-spanned="2">Cell</table-cell></table-row></table-body></table></body></page>',
 217 -                '<div><table><tbody><tr><td rowspan="2">Cell</td></tr></tbody></table></div>'),
 218 +                '/div/table/tbody/tr/td[@rowspan="2"][text()="Cell"]'),
 219          ]
 220          for i in data:
 221              yield (self.do, ) + i
 222 @@ -177,7 +215,7 @@
 223      def test_note(self):
 224          data = [
 225              ('<page><body><p>Text<note note-class="footnote"><note-body>Note</note-body></note></p></body></page>',
 226 -                '<div><p>Text<sup id="note-1-ref"><a href="#note-1">1</a></sup></p><p id="note-1"><sup><a href="#note-1-ref">1</a></sup>Note</p></div>'),
 227 +                '/div[p[text()="Text"]/sup[@id="note-1-ref"]/a[@href="#note-1"][text()="1"]][p[@id="note-1"][text()="Note"]/sup/a[@href="#note-1-ref"][text()="1"]]'),
 228          ]
 229          for i in data:
 230              yield (self.do, ) + i

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-06-30 13:29:27, 2.3 KB) [[attachment:html_out.diff]]
  • [get | view] (2010-06-30 13:29:39, 12.1 KB) [[attachment:test_html_out.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.