File tree 1 file changed +65
-2
lines changed
1 file changed +65
-2
lines changed Original file line number Diff line number Diff line change 3
3
from . import support # flake8: noqa
4
4
import unittest
5
5
import codecs
6
-
7
- from html5lib .inputstream import HTMLInputStream , HTMLUnicodeInputStream , HTMLBinaryInputStream
6
+ from io import BytesIO
7
+
8
+ from html5lib .inputstream import (BufferedStream , HTMLInputStream ,
9
+ HTMLUnicodeInputStream , HTMLBinaryInputStream )
10
+
11
+ class BufferedStreamTest (unittest .TestCase ):
12
+ def test_basic (self ):
13
+ s = b"abc"
14
+ fp = BufferedStream (BytesIO (s ))
15
+ read = fp .read (10 )
16
+ assert read == s
17
+
18
+ def test_read_length (self ):
19
+ fp = BufferedStream (BytesIO (b"abcdef" ))
20
+ read1 = fp .read (1 )
21
+ assert read1 == b"a"
22
+ read2 = fp .read (2 )
23
+ assert read2 == b"bc"
24
+ read3 = fp .read (3 )
25
+ assert read3 == b"def"
26
+ read4 = fp .read (4 )
27
+ assert read4 == b""
28
+
29
+ def test_tell (self ):
30
+ fp = BufferedStream (BytesIO (b"abcdef" ))
31
+ read1 = fp .read (1 )
32
+ assert fp .tell () == 1
33
+ read2 = fp .read (2 )
34
+ assert fp .tell () == 3
35
+ read3 = fp .read (3 )
36
+ assert fp .tell () == 6
37
+ read4 = fp .read (4 )
38
+ assert fp .tell () == 6
39
+
40
+ def test_seek (self ):
41
+ fp = BufferedStream (BytesIO (b"abcdef" ))
42
+ read1 = fp .read (1 )
43
+ assert read1 == b"a"
44
+ fp .seek (0 )
45
+ read2 = fp .read (1 )
46
+ assert read2 == b"a"
47
+ read3 = fp .read (2 )
48
+ assert read3 == b"bc"
49
+ fp .seek (2 )
50
+ read4 = fp .read (2 )
51
+ assert read4 == b"cd"
52
+ fp .seek (4 )
53
+ read5 = fp .read (2 )
54
+ assert read5 == b"ef"
55
+
56
+ def test_seek_tell (self ):
57
+ fp = BufferedStream (BytesIO (b"abcdef" ))
58
+ read1 = fp .read (1 )
59
+ assert fp .tell () == 1
60
+ fp .seek (0 )
61
+ read2 = fp .read (1 )
62
+ assert fp .tell () == 1
63
+ read3 = fp .read (2 )
64
+ assert fp .tell () == 3
65
+ fp .seek (2 )
66
+ read4 = fp .read (2 )
67
+ assert fp .tell () == 4
68
+ fp .seek (4 )
69
+ read5 = fp .read (2 )
70
+ assert fp .tell () == 6
8
71
9
72
10
73
class HTMLUnicodeInputStreamShortChunk (HTMLUnicodeInputStream ):
You can’t perform that action at this time.
0 commit comments