66
77import re ,unittest
88
9- class Html5EncodingTestCase (unittest .TestCase ):pass
9+ class Html5EncodingTestCase (unittest .TestCase ):
10+ def test_codec_name (self ):
11+ self .assertEquals (inputstream .codecName ("utf-8" ),"utf-8" )
12+ self .assertEquals (inputstream .codecName ("utf8" ),"utf-8" )
13+ self .assertEquals (inputstream .codecName (" utf8 " ),"utf-8" )
14+ self .assertEquals (inputstream .codecName ("ISO_8859--1" ),"windows-1252" )
1015
1116def buildTestSuite ():
1217for filename in html5lib_test_files ("encoding" ):
@@ -16,7 +21,9 @@ def buildTestSuite():
1621for idx ,test in enumerate (tests ):
1722def encodingTest (self ,data = test ['data' ],encoding = test ['encoding' ]):
1823stream = inputstream .HTMLInputStream (data ,chardet = False )
19- self .assertEquals (encoding .lower (),stream .charEncoding [0 ])
24+ errorMessage = "Input:\n %s\n Expected:\n %s\n Recieved\n %s\n " % (data ,encoding .lower (),
25+ stream .charEncoding [0 ])
26+ self .assertEquals (encoding .lower (),stream .charEncoding [0 ],errorMessage )
2027setattr (Html5EncodingTestCase ,'test_%s_%d' % (test_name ,idx + 1 ),
2128encodingTest )
2229
@@ -29,6 +36,7 @@ def test_chardet(self):
2936setattr (Html5EncodingTestCase ,'test_chardet' ,test_chardet )
3037except ImportError :
3138print "chardet not found, skipping chardet tests"
39+
3240
3341return unittest .defaultTestLoader .loadTestsFromName (__name__ )
3442