Beispiel #1
0
def test_unhandled_exception():
    queue = FakeQueue()
    queue.put(QueueResult("hello world", None))
    queue.put(QueueResult(None, IOError("some exception")))
    queue.put(QueueResult("! how goes there?", None))
    queue.put(QueueResult(None, None))

    queuefile = QueueFile(queue)

    with pytest.raises(IOError):
        queuefile.read(size=12)
Beispiel #2
0
def test_handled_exception():
    queue = FakeQueue()
    queue.put(QueueResult("hello world", None))
    queue.put(QueueResult(None, IOError("some exception")))
    queue.put(QueueResult("! how goes there?", None))
    queue.put(QueueResult(None, None))

    ex_found = [None]

    def handler(ex):
        ex_found[0] = ex

    queuefile = QueueFile(queue)
    queuefile.add_exception_handler(handler)
    queuefile.read(size=12)

    assert ex_found[0] is not None
Beispiel #3
0
def test_basic():
    queue = FakeQueue()
    queue.put(QueueResult("hello world", None))
    queue.put(QueueResult("! how goes there?", None))
    queue.put(QueueResult(None, None))

    queuefile = QueueFile(queue)
    assert queuefile.read() == "hello world! how goes there?"
Beispiel #4
0
def test_chunk_reading():
    queue = FakeQueue()
    queue.put(QueueResult("hello world", None))
    queue.put(QueueResult("! how goes there?", None))
    queue.put(QueueResult(None, None))

    queuefile = QueueFile(queue)
    data = ""

    while True:
        result = queuefile.read(size=2)
        if not result:
            break

        data += result

    assert data == "hello world! how goes there?"
Beispiel #5
0
def test_binary_data():
    queue = FakeQueue()

    # Generate some binary data.
    binary_data = os.urandom(1024)
    queue.put(QueueResult(binary_data, None))
    queue.put(QueueResult(None, None))

    queuefile = QueueFile(queue)
    found_data = ""
    while True:
        current_data = queuefile.read(size=37)
        if len(current_data) == 0:
            break

        found_data = found_data + current_data

    assert found_data == binary_data