Example #1
0
def test_seek_to_tell():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj, 3)
    stream.seek(stream.tell())

    assert stream.read(4) == b"thi"
    assert 3 == stream.tell()
Example #2
0
def test_seek_to_tell():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj, 3)
    stream.seek(stream.tell())

    assert stream.read(4) == 'thi'
    assert 3 == stream.tell()
Example #3
0
def test_seek_pastlimit():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj, 3)
    stream.seek(4)

    assert stream.read(1) == b""
    assert 3 == stream.tell()
Example #4
0
def test_seek():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj)
    stream.seek(2)

    assert stream.read(2) == 'is'
    assert 4 == stream.tell()
Example #5
0
def test_seek():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj)
    stream.seek(2)

    assert stream.read(2) == b"is"
    assert 4 == stream.tell()
Example #6
0
def test_seek_withlimit():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj, 3)
    stream.seek(2)

    assert stream.read(2) == b"i"
    assert 3 == stream.tell()
Example #7
0
def test_limit_multiread():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj, 7)
    assert stream.read(4) == b"this"
    assert stream.read(3) == b" is"
    assert stream.read(2) == b""
    assert 7 == stream.tell()
Example #8
0
def test_seek_withlimit():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj, 3)
    stream.seek(2)

    assert stream.read(2) == 'i'
    assert 3 == stream.tell()
Example #9
0
def test_seek_pastlimit():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj, 3)
    stream.seek(4)

    assert stream.read(1) == ''
    assert 3 == stream.tell()
Example #10
0
def test_limit_multiread():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj, 7)
    assert stream.read(4) == 'this'
    assert stream.read(3) == ' is'
    assert stream.read(2) == ''
    assert 7 == stream.tell()
Example #11
0
def test_non_filelike_obj_read_limit():
    from gunicorn.http.body import Body

    content = b"this will not really be a real fileobj"
    fileobj = BytesIO(content)
    body = Body(fileobj)
    ls = LimitingStream(body)

    assert ls.readable()
    assert ls.read(-1) == content
    assert len(content) == ls.tell()
Example #12
0
def test_non_filelike_obj_read():
    from gunicorn.http.body import Body

    content = b"this will not really be a real fileobj"
    fileobj = BytesIO(content)

    # Limited
    body1 = Body(fileobj)
    ls1 = LimitingStream(body1, 4)
    assert ls1.readable()

    resp1 = b""
    while True:
        buf = ls1.read(-1)
        if not buf:
            break
        resp1 += buf

    assert resp1 == content[:4]
    assert ls1.read(1) == b""
    assert 4 == ls1.tell()

    # Non limited
    fileobj.seek(0)
    body2 = Body(fileobj)
    ls2 = LimitingStream(body2)

    resp2 = b""
    while True:
        buf = ls2.read(-1)
        if not buf:
            break
        resp2 += buf

    assert resp2 == content
    assert ls2.read(1) == b""
    assert len(content) == ls2.tell()
Example #13
0
def test_simplelimit_readdefined():
    fileobj = StringIO("this is a cool test")
    stream = LimitingStream(fileobj, 4)
    assert stream.read(2) == "th"
    assert 2 == stream.tell()
Example #14
0
def test_nolimit_readdefined():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj, -1)
    assert stream.read(2) == b"th"
    assert 2 == stream.tell()
Example #15
0
def test_simplelimit():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj, 4)
    assert stream.read(-1) == b"this"
    assert 4 == stream.tell()
Example #16
0
def test_limit_multiread2():
    fileobj = StringIO("this is a cool test")
    stream = LimitingStream(fileobj, 7)
    assert stream.read(4) == "this"
    assert stream.read(-1) == " is"
    assert 7 == stream.tell()
Example #17
0
def test_nolimit():
    fileobj = BytesIO(b"this is a cool test")
    stream = LimitingStream(fileobj)
    assert stream.read(-1) == b"this is a cool test"
    assert len(b"this is a cool test") == stream.tell()
Example #18
0
def test_nolimit_readdefined():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj, -1)
    assert stream.read(2) == 'th'
    assert 2 == stream.tell()
Example #19
0
def test_simplelimit():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj, 4)
    assert stream.read(-1) == 'this'
    assert 4 == stream.tell()
Example #20
0
def test_nolimit():
    fileobj = StringIO('this is a cool test')
    stream = LimitingStream(fileobj)
    assert stream.read(-1) == 'this is a cool test'
    assert len('this is a cool test') == stream.tell()