コード例 #1
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #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()
コード例 #3
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #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()
コード例 #5
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #6
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #7
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #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()
コード例 #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()
コード例 #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()
コード例 #11
0
ファイル: test_filelike.py プロジェクト: sabre1041/quay-1
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()
コード例 #12
0
ファイル: test_filelike.py プロジェクト: sabre1041/quay-1
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()
コード例 #13
0
ファイル: test_filelike.py プロジェクト: zhill/quay
def test_simplelimit_readdefined():
    fileobj = StringIO("this is a cool test")
    stream = LimitingStream(fileobj, 4)
    assert stream.read(2) == "th"
    assert 2 == stream.tell()
コード例 #14
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #15
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #16
0
ファイル: test_filelike.py プロジェクト: zhill/quay
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()
コード例 #17
0
ファイル: test_filelike.py プロジェクト: epasham/quay-1
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()
コード例 #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()
コード例 #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()
コード例 #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()