def test_putmany_getmany():
    q = BlockingQueue()

    # empty putmany calls should have no effect
    q.putmany([])
    q.putmany(tuple())
    q.putmany(deque())
    assert q.is_empty
    assert q._esema.locked()            # pylint: disable-msg=W0212

    for i in xrange(1, 10):
        q.putmany([1]*i)
        assert len(q) == i
        q.putmany(tuple(q.getmany()))
        q.putmany(deque(q.getmany()))
        assert len(q.getmany(i)) == i
        assert q.is_empty

    items = range(20)
    q.putmany(items)
    assert q.getmany() == items
    q.putmany(items)
    assert q.getmany(5) == items[:5]
    assert q.getmany(5) == items[5:10]
    assert q.getmany(5) == items[10:15]
    assert q.getmany(5) == items[15:]
    assert len(q) == 0
    assert q.is_empty
def test_putleft():
    q = BlockingQueue()
    items = range(20)
    for i in items:
        q.putleft(i)
        assert len(q) == i+1
        assert q.get() == i
        assert len(q) == i
        q.putleft(i)
    assert q.getmany() == list(reversed(items))
    assert len(q) == 0
def test_maxsize(maxsize=5):
    q = BlockingQueue(maxsize=maxsize)
    assert q.maxsize == maxsize
    for i in xrange(maxsize):
        assert not q.is_full
        q.put(i)

    assert q.is_full
    assert len(q.getmany()) == maxsize
    assert not q.is_full

    q.putmany(range(maxsize))
    assert q.is_full
    q.putleft(99, respectmaxsize=0)
    assert q.is_full
    assert len(q) == maxsize+1
    assert q.get() == 99
    assert q.is_full
    assert q._fsema.locked()            # pylint: disable-msg=W0212

    assert len(q.getmany()) == maxsize
    assert not q.is_full
    assert q.is_empty