Commits

Geoffrey Sneddon  committed a1d05a8

Change to running tests with c14n serialization of tree.

  • Participants
  • Parent commits b6d9351

Comments (0)

Files changed (57)

 import os
 import unittest
 
+import html5lib
+from html5lib import treebuilders, treewalkers
+from lxml import etree
+
 from anolislib import generator
 
 
 
         def testFunc(self, file_name=file_name):
             try:
+                output = StringIO.StringIO()
+                expected = StringIO.StringIO()
+                
                 # Get the input
                 input = open(file_name, "rb")
                 tree = generator.fromFile(input)
                 input.close()
-
+                
                 # Get the output
-                output = StringIO.StringIO()
-                generator.toFile(tree, output)
+                tree.write_c14n(output)
 
                 # Get the expected result
-                expected = open(file_name[:-9] + ".html", "rb")
+                expectedfp = open(file_name[:-9] + ".html", "rb")
+                builder = treebuilders.getTreeBuilder("lxml", etree)
+                try:
+                    parser = html5lib.HTMLParser(tree=builder, namespaceHTMLElements=False)
+                except TypeError:
+                    parser = html5lib.HTMLParser(tree=builder)
+                expectedTree = parser.parse(expectedfp)
+                expectedfp.close()
+                expectedTree.write_c14n(expected)
 
                 # Run the test
-                self.assertEquals(output.getvalue(), expected.read())
-
-                # Close the files
-                output.close()
-                expected.close()
+                self.assertEquals(output.getvalue(), expected.getvalue())
             except IOError, err:
                 self.fail(err)
 

File tests/basic/dfn-data-anolis-xref.html

-<!DOCTYPE html><head><meta charset=utf-8><p><dfn data-anolis-xref=foo id=foobar>foobar</dfn></p>
-<p><a href=#foobar>foo</a>
+<!DOCTYPE html>
+<p><dfn data-anolis-xref=foo id=foobar>foobar</dfn></p>
+<p><a href=#foobar>foo</a></p>

File tests/basic/dfn-data-anolis-xref.src.html

 <!doctype html>
 <p><dfn data-anolis-xref="foo">foobar</dfn></p>
-<p><span>foo</span></p>
+<p><span>foo</span></p>

File tests/basic/dfn-in-header.html

-<!DOCTYPE html><head><meta charset=utf-8><h1 id=the-foobar-magic>The <dfn>foobar</dfn> magic</h1>
-<p><a href=#the-foobar-magic>foobar</a>
+<!DOCTYPE html><head><h1 id=the-foobar-magic>The <dfn>foobar</dfn> magic</h1>
+<p><a href=#the-foobar-magic>foobar</a></p>

File tests/basic/dfn-in-header.src.html

 <!doctype html>
 <h1>The <dfn>foobar</dfn> magic</h1>
-<p><span>foobar</span></p>
+<p><span>foobar</span></p>

File tests/basic/dfn_nested_content.html

-<!DOCTYPE html><head><meta charset=utf-8><p><dfn id=foobar><span>foobar</span></dfn></p>
-<p><a href=#foobar>foobar</a>
+<!DOCTYPE html><head><p><dfn id=foobar><span>foobar</span></dfn></p>
+<p><a href=#foobar>foobar</a></p>

File tests/basic/dfn_nested_content.src.html

 <!doctype html>
 <p><dfn><span>foobar</span></dfn></p>
-<p><span>foobar</span></p>
+<p><span>foobar</span></p>

File tests/basic/dfn_predefined_id.html

-<!DOCTYPE html><head><meta charset=utf-8><p><dfn id=foo>foobar</dfn></p>
-<p><a href=#foo>foobar</a>
+<!DOCTYPE html><head><p><dfn id=foo>foobar</dfn></p>
+<p><a href=#foo>foobar</a></p>

File tests/basic/dfn_predefined_id.src.html

 <!doctype html>
 <p><dfn id="foo">foobar</dfn></p>
-<p><span>foobar</span></p>
+<p><span>foobar</span></p>

File tests/basic/dfn_title.html

-<!DOCTYPE html><head><meta charset=utf-8><p><dfn id=foo title=foo>foobar</dfn></p>
-<p><a href=#foo>foo</a>
+<!DOCTYPE html><head><p><dfn id=foo title=foo>foobar</dfn></p>
+<p><a href=#foo>foo</a></p>

File tests/basic/dfn_title.src.html

 <!doctype html>
 <p><dfn title="foo">foobar</dfn></p>
-<p><span>foo</span></p>
+<p><span>foo</span></p>

File tests/basic/dfn_whitespace.html

-<!DOCTYPE html><head><meta charset=utf-8><p><dfn id=foo-bar>foo
+<!DOCTYPE html><head><p><dfn id=foo-bar>foo
 bar</dfn></p>
-<p><a href=#foo-bar>foo bar</a>
+<p><a href=#foo-bar>foo bar</a></p>

File tests/basic/dfn_whitespace.src.html

 <!doctype html>
 <p><dfn>foo
 bar</dfn></p>
-<p><span>foo bar</span></p>
+<p><span>foo bar</span></p>

File tests/basic/html5-id-hypen.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
-<h2 id=generatedID><span class=secno>1 </span>-</h2>
+<!DOCTYPE html><head><h1>Foo</h1>
+<h2 id=generatedID><span class=secno>1 </span>-</h2>

File tests/basic/html5-id-hypen.src.html

 <!doctype html>
 <h1>Foo</h1>
-<h2>-</h2>
+<h2>-</h2>

File tests/basic/multi-num-pre-existing.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
-<h2 id=bar><span class=secno>1 </span>Bar</h2>
+<!DOCTYPE html><head><h1>Foo</h1>
+<h2 id=bar><span class=secno>1 </span>Bar</h2>

File tests/basic/multi-num-pre-existing.src.html

 <!doctype html>
 <h1>Foo</h1>
-<h2><span class="secno">0 </span><span class="secno">1 </span>Bar</h2>
+<h2><span class="secno">0 </span><span class="secno">1 </span>Bar</h2>

File tests/basic/num-pre-existing.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
-<h2 id=bar><span class=secno>1 </span>Bar</h2>
+<!DOCTYPE html><head><h1>Foo</h1>
+<h2 id=bar><span class=secno>1 </span>Bar</h2>

File tests/basic/num-pre-existing.src.html

 <!doctype html>
 <h1>Foo</h1>
-<h2><span class="secno">0 </span>Bar</h2>
+<h2><span class="secno">0 </span>Bar</h2>

File tests/basic/num-within-em.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
-<h2 id=bar><span class=secno>1 </span><em>Bar</em></h2>
+<!DOCTYPE html><head><h1>Foo</h1>
+<h2 id=bar><span class=secno>1 </span><em>Bar</em></h2>

File tests/basic/num-within-em.src.html

 <!doctype html>
 <h1>Foo</h1>
-<h2><em><span class="secno">0 </span>Bar</em></h2>
+<h2><em><span class="secno">0 </span>Bar</em></h2>

File tests/basic/toc-basic.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span>Bar</a></ol>
 <!--end-toc-->
-<h2 id=bar><span class=secno>1 </span>Bar</h2>
+<h2 id=bar><span class=secno>1 </span>Bar</h2>

File tests/basic/toc-basic.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2>Bar</h2>
+<h2>Bar</h2>

File tests/basic/toc-begin-end-content-garbage.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span>Bar</a></ol><!--end-toc-->
-<h2 id=bar><span class=secno>1 </span>Bar</h2>
+<h2 id=bar><span class=secno>1 </span>Bar</h2>

File tests/basic/toc-begin-end-content-garbage.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--begin-toc-->This is certainly pointless to have here, seeming it'll be eaten by the <kbd>spec-gen</kbd>, and so will this<!--end-toc-->
-<h2>Bar</h2>
+<h2>Bar</h2>

File tests/basic/toc-begin-end-content.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span>Bar</a></ol><!--end-toc-->
-<h2 id=bar><span class=secno>1 </span>Bar</h2>
+<h2 id=bar><span class=secno>1 </span>Bar</h2>

File tests/basic/toc-begin-end-content.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--begin-toc--><ol class=toc><li><a href=#bar><span>1. </span>Bar</a></ol><!--end-toc-->
-<h2>Bar</h2>
+<h2>Bar</h2>

File tests/basic/toc-begin-end.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span>Bar</a></ol><!--end-toc-->
-<h2 id=bar><span class=secno>1 </span>Bar</h2>
+<h2 id=bar><span class=secno>1 </span>Bar</h2>

File tests/basic/toc-begin-end.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--begin-toc--><!--end-toc-->
-<h2>Bar</h2>
+<h2>Bar</h2>

File tests/basic/toc-code.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span><code>Bar</code></a></ol>
 <!--end-toc-->
-<h2 id=bar><span class=secno>1 </span><code>Bar</code></h2>
+<h2 id=bar><span class=secno>1 </span><code>Bar</code></h2>

File tests/basic/toc-code.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2><code>Bar</code></h2>
+<h2><code>Bar</code></h2>

File tests/basic/toc-dfn-code.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span><code>Bar</code></a></ol>
 <!--end-toc-->
-<h2 id=bar><span class=secno>1 </span><dfn><code>Bar</code></dfn></h2>
+<h2 id=bar><span class=secno>1 </span><dfn><code>Bar</code></dfn></h2>

File tests/basic/toc-dfn-code.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2><dfn><code>Bar</code></dfn></h2>
+<h2><dfn><code>Bar</code></dfn></h2>

File tests/basic/toc-dfn-within-em.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span><em>Bar</em></a></ol>
 <!--end-toc-->
-<h2 id=bar><span class=secno>1 </span><em><dfn>Bar</dfn></em></h2>
+<h2 id=bar><span class=secno>1 </span><em><dfn>Bar</dfn></em></h2>

File tests/basic/toc-dfn-within-em.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2><em><dfn>Bar</dfn></em></h2>
+<h2><em><dfn>Bar</dfn></em></h2>

File tests/basic/toc-dfn.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span>Bar</a></ol>
 <!--end-toc-->
-<h2 id=bar><span class=secno>1 </span><dfn>Bar</dfn></h2>
+<h2 id=bar><span class=secno>1 </span><dfn>Bar</dfn></h2>

File tests/basic/toc-dfn.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2><dfn>Bar</dfn></h2>
+<h2><dfn>Bar</dfn></h2>

File tests/basic/toc-header-element-descendant-h1.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
             <h1><span class=secno>1 </span>Bar</h1>
         </div>
     </header>
-</section>
+</section>

File tests/basic/toc-header-element-descendant-h1.src.html

             <h1>Bar</h1>
         </div>
     </header>
-</section>
+</section>

File tests/basic/toc-header-element-h2.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
     <header id=bar>
         <h2><span class=secno>1 </span>Bar</h2>
     </header>
-</section>
+</section>

File tests/basic/toc-header-element-h2.src.html

     <header>
         <h2>Bar</h2>
     </header>
-</section>
+</section>

File tests/basic/toc-header-element.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
 	<header id=lol>
 		<h1 class="no-toc no-num">LOL</h1>
 	</header>
-</section>
+</section>

File tests/basic/toc-header-element.src.html

 	<header>
 		<h1 class="no-toc no-num">LOL</h1>
 	</header>
-</section>
+</section>

File tests/basic/toc-multi-a.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar-lol><span class=secno>1 </span>Bar LOL</a></ol>
 <!--end-toc-->
-<h2 id=bar-lol><span class=secno>1 </span><a href=http://example.com>Bar</a> <a href=http://example.net>LOL</a></h2>
+<h2 id=bar-lol><span class=secno>1 </span><a href=http://example.com>Bar</a> <a href=http://example.net>LOL</a></h2>

File tests/basic/toc-multi-a.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2><a href=http://example.com>Bar</a> <a href=http://example.net>LOL</a></h2>
+<h2><a href=http://example.com>Bar</a> <a href=http://example.net>LOL</a></h2>

File tests/basic/toc-multi-dfn-children.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#text-state-and-search-state><span class=secno>1 </span>Text state and Search state</a></ol>
 <!--end-toc-->
-<h6 id=text-state-and-search-state><span class=secno>1 </span><dfn title=attr-input-type-text>Text</dfn> state and <dfn title=attr-input-type-search>Search</dfn> state</h6>
+<h6 id=text-state-and-search-state><span class=secno>1 </span><dfn title=attr-input-type-text>Text</dfn> state and <dfn title=attr-input-type-search>Search</dfn> state</h6>

File tests/basic/toc-multi-dfn-children.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h6><dfn title="attr-input-type-text">Text</dfn> state and <dfn title="attr-input-type-search">Search</dfn> state</h6>
+<h6><dfn title="attr-input-type-text">Text</dfn> state and <dfn title="attr-input-type-search">Search</dfn> state</h6>

File tests/basic/toc-nested-dfn.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#barlol><span class=secno>1 </span>BarLOL</a></ol>
 <!--end-toc-->
-<h2 id=barlol><span class=secno>1 </span><dfn><dfn>Bar</dfn>LOL</dfn></h2>
+<h2 id=barlol><span class=secno>1 </span><dfn><dfn>Bar</dfn>LOL</dfn></h2>

File tests/basic/toc-nested-dfn.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2><dfn><dfn>Bar</dfn>LOL</dfn></h2>
+<h2><dfn><dfn>Bar</dfn>LOL</dfn></h2>

File tests/basic/toc-remove-a.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc>
  <li><a href=#bar><span class=secno>1 </span>Bar</a></ol>
 <!--end-toc-->
-<h2 id=bar><span class=secno>1 </span>B<a>a</a>r</h2>
+<h2 id=bar><span class=secno>1 </span>B<a>a</a>r</h2>

File tests/basic/toc-remove-a.src.html

 <!doctype html>
 <h1>Foo</h1>
 <!--toc-->
-<h2>B<a>a</a>r</h2>
+<h2>B<a>a</a>r</h2>

File tests/basic/toc-tail.html

-<!DOCTYPE html><head><meta charset=utf-8><h1>Foo</h1>
+<!DOCTYPE html><head><h1>Foo</h1>
 
 <!--begin-toc-->
 <ol class=toc></ol>
-<!--end-toc-->bar
+<!--end-toc-->bar

File tests/basic/toc-tail.src.html

 <!doctype html>
 <h1>Foo</h1>
-<!--toc-->bar
+<!--toc-->bar

File tests/basic/xref-nested.html

-<!DOCTYPE html><head><meta charset=utf-8><p><dfn id=foobar>foobar</dfn></p>
+<!DOCTYPE html><head><p><dfn id=foobar>foobar</dfn></p>
 <p><dfn id=lol>lol</dfn></p>
 <p><a href=#foobar><code>foo<span title="">bar</span></code></a></p>
-<p><a href=#lol>lol</a>
+<p><a href=#lol>lol</a></p>

File tests/basic/xref-nested.src.html

 <p><dfn>foobar</dfn></p>
 <p><dfn>lol</dfn></p>
 <p><code>foo<span title="">bar</span></code></p>
-<p><span>lol</span></p>
+<p><span>lol</span></p>