10000 Minor cleanup · html5lib/html5lib-python@2b70d2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b70d2a

Browse files
committed
Minor cleanup
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40694
1 parent 688e4c9 commit 2b70d2a

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

tests/mockParser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import sys, hotshot, hotshot.stats
22
import os
33

4-
#Allow us to import from the src directory
5-
os.chdir(os.path.split(os.path.abspath(__file__))[0])
6-
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
4+
if __name__ == '__main__':
5+
#Allow us to import from the src directory
6+
os.chdir(os.path.split(os.path.abspath(__file__))[0])
7+
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
78

89
from tokenizer import HTMLTokenizer
910

tests/test_parser.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import glob
44
import StringIO
55
import unittest
6-
import new
76

87
#RELEASE remove
9-
# XXX Allow us to import the sibling module
10-
os.chdir(os.path.split(os.path.abspath(__file__))[0])
11-
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
8+
if __name__ == '__main__':
9+
# XXX Allow us to import the sibling module
10+
os.chdir(os.path.split(os.path.abspath(__file__))[0])
11+
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
1212

1313
import html5parser
1414
#Run tests over all treebuilders
@@ -159,8 +159,7 @@ def buildTestSuite():
159159
testFunc = lambda self, method=func, innerHTML=innerHTML, input=input, expected=expected, \
160160
errors=errors, treeCls=treeCls: method(self, innerHTML, input, expected, errors, treeCls)
161161
testFunc.__doc__ = 'Parser %s Tree %s Input: %s'%(testName, treeName, input)
162-
instanceMethod = new.instancemethod(testFunc, None, TestCase)
163-
setattr(TestCase, testName, instanceMethod)
162+
setattr(TestCase, testName, testFunc)
164163
return unittest.TestLoader().loadTestsFromTestCase(TestCase)
165164

166165
def main():

tests/test_sanitizer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import os,sys,unittest,new
1+
import os,sys,unittest
22

33
#RELEASE remove
4-
# XXX Allow us to import the sibling module
5-
os.chdir(os.path.split(os.path.abspath(__file__))[0])
6-
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
4+
if __name__ == '__main__':
5+
# XXX Allow us to import the sibling module
6+
os.chdir(os.path.split(os.path.abspath(__file__))[0])
7+
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
78

89
import html5parser, sanitizer, constants
910
#END RELEASE
1011

1112
#RELEASE add
1213
#from html5lib import html5parser, sanitizer, constants
1314
#END RELEASE
14-
#!/usr/bin/env ruby
1515

1616
class SanitizeTest(unittest.TestCase):
1717
def addTest(cls, name, expected, input):
18-
func = lambda self: self.assertEqual(expected, self.sanitize_html(input))
19-
setattr(cls, name, new.instancemethod(func, None, cls))
18+
setattr(cls, name,
19+
lambda self: self.assertEqual(expected, self.sanitize_html(input)))
2020
addTest = classmethod(addTest)
2121

2222
def sanitize_html(self,stream):

tests/test_serializer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import sys
22
import os
33
import glob
4-
import StringIO
54
import unittest
6-
import new
75

86
try:
97
import simplejson
@@ -17,9 +15,10 @@ def load(f):
1715
load = staticmethod(load)
1816

1917
#RELEASE remove
20-
# XXX Allow us to import the sibling module
21-
os.chdir(os.path.split(os.path.abspath(__file__))[0])
22-
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
18+
if __name__ == '__main__':
19+
# XXX Allow us to import the sibling module
20+
os.chdir(os.path.split(os.path.abspath(__file__))[0])
21+
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
2322

2423
import html5parser
2524
import serializer
@@ -60,7 +59,7 @@ class TestCase(unittest.TestCase):
6059
def addTest(cls, name, expected, input, description, options):
6160
func = lambda self: self.mockTest(expected, input, options)
6261
func.__doc__ = "\t".join([description, str(input), str(options)])
63-
setattr(cls, name, new.instancemethod(func, None, cls))
62+
setattr(cls, name, func)
6463
addTest = classmethod(addTest)
6564

6665
def mockTest(self, expected, input, options):

tests/test_tokenizer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import sys
22
import os
33
import glob
4-
import StringIO
54
import unittest
6-
import new
75

86
try:
97
import simplejson
@@ -156,8 +154,7 @@ def buildTestSuite():
156154
testFunc = lambda self, method=func, test=test: \
157155
method(self, test)
158156
testFunc.__doc__ = "\t".join([test['description'], str(test['input'])])
159-
instanceMethod = new.instancemethod(testFunc, None, TestCase)
160-
setattr(TestCase, testName, instanceMethod)
157+
setattr(TestCase, testName, testFunc)
161158
return unittest.TestLoader().loadTestsFromTestCase(TestCase)
162159

163160
def main():

tests/test_treewalkers.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import glob
44
import StringIO
55
import unittest
6-
import new
7-
8-
sys.path.insert(0, os.path.split(os.path.abspath(__file__))[0])
9-
from test_parser import parseTestcase
106

117
#RELEASE remove
12-
# XXX Allow us to import the sibling module
13-
os.chdir(os.path.split(os.path.abspath(__file__))[0])
14-
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
8+
if __name__ == '__main__':
9+
# XXX Allow us to import the sibling module
10+
os.chdir(os.path.split(os.path.abspath(__file__))[0])
11+
sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
1512

1613
import html5parser
1714
#Run tests over all treewalkers/treebuilders pairs
@@ -28,6 +25,8 @@
2825
#from html5lib.filters.lint import Filter as LintFilter, LintError
2926
#END RELEASE
3027

28+
from test_parser import parseTestcase
29+
3130
def PullDOMAdapter(node):
3231
from xml.dom import Node
3332
from xml.dom.pulldom import START_ELEMENT, END_ELEMENT, COMMENT, CHARACTERS
@@ -252,11 +251,11 @@ def buildTestSuite():
252251
for func, innerHTML, input, expected, errors, treeName, treeCls in test_treewalker():
253252
tests += 1
254253
testName = 'test%d' % tests
255-
testFunc = lambda self, method=func, innerHTML=innerHTML, input=input, expected=expected, \
256-
errors=errors, treeCls=treeCls: method(self, innerHTML, input, expected, errors, treeCls)
254+
def testFunc(self, method=func, innerHTML=innerHTML, input=input,
255+
expected=expected, errors=errors, treeCls=treeCls):
256+
method(self, innerHTML, input, expected, errors, treeCls)
257257
testFunc.__doc__ = 'Parser %s Tree %s Input: %s'%(testName, treeName, input)
258-
instanceMethod = new.instancemethod(testFunc, None, TestCase)
259-
setattr(TestCase, testName, instanceMethod)
258+
setattr(TestCase, testName, testFunc)
260259
return unittest.TestLoader().loadTestsFromTestCase(TestCase)
261260

262261
def main():

0 commit comments

Comments
 (0)
0