示例#1
0
def test_none_read():
    class NoneReader(object):
        def read(self, size=None):
            return None

    stream = StreamSlice(NoneReader(), 0)
    assert stream.read(-1) == None
    assert stream.tell() == 0
示例#2
0
def test_slice_explictread():
    fileobj = StringIO('this is a cool test')
    stream = StreamSlice(fileobj, 5, 9)
    assert stream.read(2) == 'is'
    assert stream.read(5) == ' a'
    assert len('is a') == stream.tell()
示例#3
0
def test_startindex_limitedread():
    fileobj = StringIO('this is a cool test')
    stream = StreamSlice(fileobj, 5)
    assert stream.read(4) == 'is a'
    assert 4 == stream.tell()
示例#4
0
def test_startindex():
    fileobj = StringIO('this is a cool test')
    stream = StreamSlice(fileobj, 5)
    assert stream.read(-1) == 'is a cool test'
    assert len('is a cool test') == stream.tell()
示例#5
0
def test_noslice():
    fileobj = StringIO('this is a cool test')
    stream = StreamSlice(fileobj, 0)
    assert stream.read(-1) == 'this is a cool test'
    assert len('this is a cool test') == stream.tell()
示例#6
0
def test_startindex_limitedread():
    fileobj = BytesIO(b"this is a cool test")
    stream = StreamSlice(fileobj, 5)
    assert stream.read(4) == b"is a"
    assert 4 == stream.tell()
示例#7
0
def test_slice_explictread():
    fileobj = BytesIO(b"this is a cool test")
    stream = StreamSlice(fileobj, 5, 9)
    assert stream.read(2) == b"is"
    assert stream.read(5) == b" a"
    assert len(b"is a") == stream.tell()
示例#8
0
def test_startindex():
    fileobj = BytesIO(b"this is a cool test")
    stream = StreamSlice(fileobj, 5)
    assert stream.read(-1) == b"is a cool test"
    assert len(b"is a cool test") == stream.tell()
示例#9
0
def test_noslice():
    fileobj = BytesIO(b"this is a cool test")
    stream = StreamSlice(fileobj, 0)
    assert stream.read(-1) == b"this is a cool test"
    assert len(b"this is a cool test") == stream.tell()
示例#10
0
def test_slice_explictread():
    fileobj = StringIO("this is a cool test")
    stream = StreamSlice(fileobj, 5, 9)
    assert stream.read(2) == "is"
    assert stream.read(5) == " a"
    assert len("is a") == stream.tell()
示例#11
0
def test_startindex():
    fileobj = StringIO("this is a cool test")
    stream = StreamSlice(fileobj, 5)
    assert stream.read(-1) == "is a cool test"
    assert len("is a cool test") == stream.tell()
示例#12
0
def test_noslice():
    fileobj = StringIO("this is a cool test")
    stream = StreamSlice(fileobj, 0)
    assert stream.read(-1) == "this is a cool test"
    assert len("this is a cool test") == stream.tell()