10BC0 Someday I hope to make InputStream actually stream, but as a first · awesome-python/html5lib-python@5846a91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5846a91

Browse files
committed
Someday I hope to make InputStream actually stream, but as a first
step, here's some test cases to make sure that if I ever get around to that, I don't break anything... --HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40660
1 parent 013bbae commit 5846a91

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/test_stream.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import unittest, codecs
2+
3+
#RELEASE remove
4+
if __name__ == '__main__':
5+
import os, sys
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")))
8+
9+
from inputstream import HTMLInputStream
10+
#END RELEASE
11+
12+
#RELEASE add
13+
#import html5lib
14+
#from html5lib.inputstream import HTMLInputStream
15+
#END RELEASE
16+
17+
class HTMLInputStreamTest(unittest.TestCase):
18+
19+
def test_char_ascii(self):
20+
stream = HTMLInputStream("'")
21+
self.assertEquals(stream.charEncoding, 'ascii')
22+
self.assertEquals(stream.char(), "'")
23+
24+
def test_char_null(self):
25+
stream = HTMLInputStream("\x00")
26+
self.assertEquals(stream.char(), u'\ufffd')
27+
28+
def test_char_utf8(self):
29+
stream = HTMLInputStream(u'\u2018'.encode('utf-8'))
30+
self.assertEquals(stream.charEncoding, 'utf-8')
31+
self.assertEquals(stream.char(), u'\u2018')
32+
33+
def test_char_win1252(self):
34+
stream = HTMLInputStream(u'\u2018'.encode('windows-1252'))
35+
self.assertEquals(stream.charEncoding, 'windows-1252')
36+
self.assertEquals(stream.char(), u'\u2018')
37+
38+
def test_bom(self):
39+
stream = HTMLInputStream(codecs.BOM_UTF8 + "'")
40+
self.assertEquals(stream.charEncoding, 'utf-8')
41+
self.assertEquals(stream.char(), "'")
42+
43+
def test_utf_16(self):
44+
stream = HTMLInputStream((' '*1025).encode('utf-16'))
45+
self.assert_(stream.charEncoding in ['utf-16-le','utf-16-be'])
46+
self.assertEquals(len(stream.charsUntil(' ',True)),1025)
47+
48+
def test_newlines(self):
49+
stream = HTMLInputStream(codecs.BOM_UTF8 + "a\nbb\r\nccc\rdddd")
50+
self.assertEquals(stream.tell, 0)
51+
self.assertEquals(stream.charsUntil('x'),u"a\nbb\nccc\ndddd")
52+
self.assertEquals(stream.tell, 14)
53+
self.assertEquals(stream.position(), (4,5))
54+
self.assertEquals(stream.newLines, [0,1,4,8])
55+
56+
def buildTestSuite():
57+
return unittest.defaultTestLoader.loadTestsFromName(__name__)
58+
59+
def main():
60+
buildTestSuite()
61+
unittest.main()
62+
63+
if __name__ == '__main__':
64+
main()

0 commit comments

Comments
 (0)
0