def test_thread_map_pickle(): TEST_VAL = 5 objs = [Unpicklable(random.randint(0, 1000)) for _ in range(100)] identity_map_objs = iter(iterlib.thread_map(lambda x: x, objs)) for orig, mapped in zip(objs, identity_map_objs): assert orig.q == mapped.q assert orig.func1(TEST_VAL) == mapped.func1(TEST_VAL) assert orig.func2(TEST_VAL) == mapped.func2(TEST_VAL)
def test_thread_map_order_equality(): random_ints = [random.randint(0, 100) for _ in range(10000)] random_ints_sq = [x**2 for x in random_ints] random_ints_thread_map = iterlib.thread_map(lambda x: x**2, random_ints, num_workers=32) for i, j in zip(random_ints_sq, random_ints_thread_map): assert i == j
def test_map_index_equality(): random_ints = [random.randint(0, 100) for _ in range(10000)] random_ints_sq = [x**2 for x in random_ints] random_ints_thread_map = iterlib.thread_map(lambda x: x**2, random_ints) random_ints_proc_map = iterlib.process_map(lambda x: x**2, random_ints) for i in range(10000): assert random_ints_sq[i] == random_ints_proc_map[i] assert random_ints_sq[i] == random_ints_thread_map[i]
def test_thread_map_exception(): random_ints = [1 for _ in range(1000)] + [0] + [1 for _ in range(1000)] random_ints_inv = iterlib.thread_map(lambda x: 1.0 / x, random_ints, num_workers=32) random_ints_thread_loader = iter(random_ints_inv) with pytest.raises(ZeroDivisionError): inv_ints = list(random_ints_thread_loader) assert wait_until_shutdown(random_ints_thread_loader)
def test_thread_map_cleanup(): random_ints = [random.randint(0, 100) for _ in range(10000)] random_ints_thread_map = iter( iterlib.thread_map(lambda x: x**2, random_ints, num_workers=128)) list(random_ints_thread_map) assert wait_until_shutdown(random_ints_thread_map)