|
1 | 1 | # Copyright (C) 2020 ISIS Rutherford Appleton Laboratory UKRI
|
2 | 2 | # SPDX - License - Identifier: GPL-3.0-or-later
|
3 | 3 |
|
| 4 | +from typing import List, Tuple, Union |
4 | 5 | from unittest import mock
|
5 | 6 |
|
| 7 | +import pytest |
| 8 | + |
6 | 9 | from mantidimaging.core.parallel.utility import execute_impl, multiprocessing_necessary
|
7 | 10 |
|
8 | 11 |
|
9 |
| -def test_correctly_chooses_parallel(): |
10 |
| - # forcing 1 core should always return False |
11 |
| - assert multiprocessing_necessary((100, 10, 10), cores=1) is False |
12 |
| - # shapes less than 10 should return false |
13 |
| - assert multiprocessing_necessary((10, 10, 10), cores=12) is False |
14 |
| - assert multiprocessing_necessary(10, cores=12) is False |
15 |
| - # shapes over 10 should return True |
16 |
| - assert multiprocessing_necessary((11, 10, 10), cores=12) is True |
17 |
| - assert multiprocessing_necessary(11, cores=12) is True |
| 12 | +@pytest.mark.parametrize( |
| 13 | + 'shape,cores,should_be_parallel', |
| 14 | + ( |
| 15 | + [(100, 10, 10), 1, False], # forcing 1 core should always return False |
| 16 | + # shapes <= 10 should return False |
| 17 | + [(10, 10, 10), 12, False], |
| 18 | + [10, 12, False], |
| 19 | + # shapes over 10 should return True |
| 20 | + [(11, 10, 10), 12, True], |
| 21 | + [11, 12, True], |
| 22 | + # repeat from above but with list, to cover that branch of the if |
| 23 | + [[100, 10, 10], 1, False], |
| 24 | + [[10, 10, 10], 12, False], |
| 25 | + [[11, 10, 10], 12, True], |
| 26 | + )) |
| 27 | +def test_correctly_chooses_parallel(shape: Union[int, List, Tuple[int, int, int]], cores: int, |
| 28 | + should_be_parallel: bool): |
| 29 | + assert multiprocessing_necessary(shape, cores) is should_be_parallel |
18 | 30 |
|
19 | 31 |
|
20 | 32 | @mock.patch('mantidimaging.core.parallel.utility.Pool')
|
|
0 commit comments