Exemplo n.º 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
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()