def test_nested_gets_in_a_single_thread_use_new_objects(): pool = ObjectPool(object) with pool.get() as first_client: with pool.get() as second_client: pass assert first_client is not second_client assert len(pool.objects) == 2
def test_bounded_nonblocking_gets_raise_EWOULDBLOCK(): pool = ObjectPool(object, maxsize=1) with pool.get() as client1: with assert_raises(OSError) as cm: with pool.get(blocking=False) as client2: pass assert cm.exception.errno == errno.EWOULDBLOCK
def test_subsequent_gets_in_a_single_thread_reuse_the_same_object(): pool = ObjectPool(object) with pool.get() as first_client: pass with pool.get() as second_client: pass assert first_client is second_client
def test_get_adds_an_object_to_the_pool(): pool = ObjectPool(object) assert len(pool.objects) == 0 with pool.get() as client: pass assert len(pool.objects) == 1 assert pool.objects[0] is client