Coverage for tests/test_process_utils.py: 100%
18 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-19 16:12 -0700
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-19 16:12 -0700
1from image_utils.process_utils import parallelize
2from image_utils.file_utils import get_rand_hex
3import pytest
4from pathlib import Path
5import numpy as np
7img_path = Path('tests/flower.jpg')
8save_path = Path(__file__).parent / 'output'
11# memory = Memory(location='./cachedir', verbose=0, mmap_mode='r')
12# @memory.cache
13# def costly_compute(data, column):
14# """Emulate a costly function by sleeping and returning a column."""
15# time.sleep(1)
16# return data[column] + 1
18def do_func(lst, idx, arr):
19 print(len(lst), arr.shape)
22def get_test_list(list_size):
23 return [get_rand_hex() for _ in range(list_size)]
26@pytest.mark.parametrize("num_processes", [1, 2, 10])
27@pytest.mark.parametrize("list_size", [1, 10, 1000])
28def test_parallelize(num_processes, list_size):
29 test_list = get_test_list(list_size)
30 rng = np.random.RandomState(42)
31 test_arr = rng.randn(int(1e4), 4)
32 test_parallel = parallelize(do_func, num_processes=num_processes, shuffle=False, use_joblib=True)(test_list, arr=test_arr)