Exemple #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
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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()