summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-11-06 15:00:08 -0600
committerGitHub <noreply@github.com>2018-11-06 15:00:08 -0600
commite1a8230b2e1d35ec2711d4d2ae4cea97284f131b (patch)
treee37a0163b17b6928f589560387883390d9c67892
parent97df928718a46b869d0d6675ffd6e8c539f32773 (diff)
parentce55462abe93ee16ae941c5e5973269ded0e96e0 (diff)
downloadnumpy-e1a8230b2e1d35ec2711d4d2ae4cea97284f131b.tar.gz
Merge pull request #12259 from hmaarrfk/block_single_concatenate_simplify_test
TST: simplify how the different code paths for block are tested.
-rw-r--r--numpy/core/tests/test_shape_base.py58
1 files changed, 26 insertions, 32 deletions
diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py
index b2c610da6..416bd18db 100644
--- a/numpy/core/tests/test_shape_base.py
+++ b/numpy/core/tests/test_shape_base.py
@@ -1,5 +1,6 @@
from __future__ import division, absolute_import, print_function
+import pytest
import warnings
import sys
import numpy as np
@@ -391,39 +392,32 @@ def test_stack():
assert_array_equal(result, np.array([0, 1, 2]))
-# See for more information on how to parametrize a whole class
-# https://docs.pytest.org/en/latest/example/parametrize.html#parametrizing-test-methods-through-per-class-configuration
-def pytest_generate_tests(metafunc):
- # called once per each test function
- if hasattr(metafunc.cls, 'params'):
- arglist = metafunc.cls.params
- argnames = sorted(arglist[0])
- metafunc.parametrize(argnames,
- [[funcargs[name] for name in argnames]
- for funcargs in arglist])
-
-
-# blocking small arrays and large arrays go through different paths.
-# the algorithm is triggered depending on the number of element
-# copies required.
-# We define a test fixture that forces most tests to go through
-# both code paths.
-# Ultimately, this should be removed if a single algorithm is found
-# to be faster for both small and large arrays.s
-def _block_force_concatenate(arrays):
- arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
- return _block_concatenate(arrays, list_ndim, result_ndim)
-
-
-def _block_force_slicing(arrays):
- arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
- return _block_slicing(arrays, list_ndim, result_ndim)
-
-
class TestBlock(object):
- params = [dict(block=block),
- dict(block=_block_force_concatenate),
- dict(block=_block_force_slicing)]
+ @pytest.fixture(params=['block', 'force_concatenate', 'force_slicing'])
+ def block(self, request):
+ # blocking small arrays and large arrays go through different paths.
+ # the algorithm is triggered depending on the number of element
+ # copies required.
+ # We define a test fixture that forces most tests to go through
+ # both code paths.
+ # Ultimately, this should be removed if a single algorithm is found
+ # to be faster for both small and large arrays.
+ def _block_force_concatenate(arrays):
+ arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
+ return _block_concatenate(arrays, list_ndim, result_ndim)
+
+ def _block_force_slicing(arrays):
+ arrays, list_ndim, result_ndim, _ = _block_setup(arrays)
+ return _block_slicing(arrays, list_ndim, result_ndim)
+
+ if request.param == 'force_concatenate':
+ return _block_force_concatenate
+ elif request.param == 'force_slicing':
+ return _block_force_slicing
+ elif request.param == 'block':
+ return block
+ else:
+ raise ValueError('Unknown blocking request. There is a typo in the tests.')
def test_returns_copy(self, block):
a = np.eye(3)