File tree 3 files changed +17
-8
lines changed
3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ html5lib is packaged with distutils. To install it use:
11
11
12
12
You may wish to check that your installation has been a success by
13
13
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
15
15
16
16
= Usage =
17
17
Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 1
- import os ,sys ,unittest
2
- from support import simplejson , html5lib_test_files
1
+ import os
2
+ import sys
3
+ import unittest
3
4
5
+ try :
6
+ import json
7
+ except ImportError :
8
+ import simplejson as json
9
+
10
+ from support import html5lib_test_files
4
11
from html5lib import html5parser , sanitizer , constants
5
12
6
13
class SanitizeTest (unittest .TestCase ):
7
14
def addTest (cls , name , expected , input ):
8
15
def test (self , expected = expected , input = input ):
9
16
expected = '' .join ([token .toxml () for token in html5parser .HTMLParser ().
10
17
parseFragment (expected ).childNodes ])
11
- expected = simplejson .loads (simplejson .dumps (expected ))
18
+ expected = json .loads (json .dumps (expected ))
12
19
self .assertEqual (expected , self .sanitize_html (input ))
13
20
setattr (cls , name , test )
14
21
addTest = classmethod (addTest )
@@ -73,7 +80,7 @@ def test_should_handle_astral_plane_characters(self):
73
80
74
81
def buildTestSuite ():
75
82
for filename in html5lib_test_files ("sanitizer" ):
76
- for test in simplejson .load (file (filename )):
83
+ for test in json .load (file (filename )):
77
84
SanitizeTest .addTest ('test_' + test ['name' ], test ['output' ], test ['input' ])
78
85
79
86
return unittest .TestLoader ().loadTestsFromTestCase (SanitizeTest )
You can’t perform that action at this time.
0 commit comments