Skip to content

Commit 5440177

Browse files
committed
Fix up some bitrotted tests and documentation
All sanitizer tests still error, but at least the script can be run. http://code.google.com/p/html5lib/issues/detail?id=179
1 parent 4cff604 commit 5440177

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ html5lib is packaged with distutils. To install it use:
1111

1212
You may wish to check that your installation has been a success by
1313
running the testsuite. All the tests can be run by invoking
14-
runtests.py in the tests/ directory
14+
runtests.py in the html5lib/tests/ directory
1515

1616
= Usage =
1717

html5lib/tests/README

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
The testcases for the tokenizer require the use of simplejson
2-
(http://cheeseshop.python.org/pypi/simplejson). Each testcase file can be run
3-
directly through a python interpreter (e.g. python test_tokenizer.py).
1+
Each testcase file can be run directly through a python interpreter
2+
(e.g. python test_tokenizer.py).
3+
4+
Some testcases depend on the json module (available since Python 2.6),
5+
but will fall back to using simplejson if json is not available.

html5lib/tests/test_sanitizer.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import os,sys,unittest
2-
from support import simplejson, html5lib_test_files
1+
import os
2+
import sys
3+
import unittest
34

5+
try:
6+
import json
7+
except ImportError:
8+
import simplejson as json
9+
10+
from support import html5lib_test_files
411
from html5lib import html5parser, sanitizer, constants
512

613
class SanitizeTest(unittest.TestCase):
714
def addTest(cls, name, expected, input):
815
def test(self, expected=expected, input=input):
916
expected = ''.join([token.toxml() for token in html5parser.HTMLParser().
1017
parseFragment(expected).childNodes])
11-
expected = simplejson.loads(simplejson.dumps(expected))
18+
expected = json.loads(json.dumps(expected))
1219
self.assertEqual(expected, self.sanitize_html(input))
1320
setattr(cls, name, test)
1421
addTest = classmethod(addTest)
@@ -73,7 +80,7 @@ def test_should_handle_astral_plane_characters(self):
7380

7481
def buildTestSuite():
7582
for filename in html5lib_test_files("sanitizer"):
76-
for test in simplejson.load(file(filename)):
83+
for test in json.load(file(filename)):
7784
SanitizeTest.addTest('test_' + test['name'], test['output'], test['input'])
7885

7986
return unittest.TestLoader().loadTestsFromTestCase(SanitizeTest)

0 commit comments

Comments
 (0)