Skip to content

Commit 264c6d8

Browse files
Add tests folder to dpnp conda package (#2116)
* Move tests to dpnp folder * Update import paths for dpnp tests * Update paths in skipped_tests files * Update import paths in tests_perf * Update import paths in cupy/testing * Update import paths in all cupy tests * Update tests path in pyproject.toml * Remove MANIFEST.in * Add tests folder to conda package * Simplify meta.yaml: move test logic to run_test.sh * Move pytest config from setup.cfg to conftest.py * Update call pytest in gen_coverage.py * Update path to cupy.testing in some tests * Update test paths for github action test_linux * Optimize test skipping and path normalization in conftest.py * Add norecursedirs config for tests_perf in conftest.py * Use relative imports for dpnp tests * Update docs for _loops.py * Add empty __init__.py files to cupy tests * Update import path in test_add_remove.py * Update tests-path for GH Actions * Show extra test summary info in internal CI * Fix normalize_test_name() to support subdirectories * Update normalize_test_name to run pytest from diff paths * Add run_test.bat to conda-recipe * Update pre-commit settings to move tests folder * Use absolute import paths in cupy tests * Update tests path in pyproject.toml * Use package_data instead of data_files in setup.py to pack tests * Update args for generate coverage * Update import path in test_arraypad.py * Rename TEST_SCOPE files to use pytest --pyargs * Remove unused imports in test files * Align import for test_arraypad.py * Use absolute import path in cupy/testing * Print dpnp version while testing conda package * Disable verbose and disable-warnings pytest mode for public CI * Disable quiet, verbose, disable-warnings pytest mode for testing conda package * Remove dublicate env variable MODULE_NAME in conda-package.yaml * Remove working-directory usage for Run tests in conda-package.yml
1 parent 0e50556 commit 264c6d8

File tree

166 files changed

+298
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+298
-204
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ exclude =
5656
build,
5757
dpnp/to_numba/*.py,
5858
conda.recipe,
59-
tests/*.py,
59+
dpnp/tests/*.py,
6060
tests_external/*.py,
6161
versioneer.py,
6262

.github/workflows/conda-package.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ permissions: read-all
1010

1111
env:
1212
PACKAGE_NAME: dpnp
13-
MODULE_NAME: dpnp
1413
# Follow oneAPI installation instruction for conda, since intel channel is not longer available
1514
# CHANNELS: '-c dppy/label/dev -c intel -c conda-forge --override-channels'
1615
CHANNELS: '-c dppy/label/dev -c https://software.repos.intel.com/python/conda/ -c conda-forge --override-channels'
@@ -116,7 +115,6 @@ jobs:
116115
channel-path: '${{ github.workspace }}/channel/'
117116
pkg-path-in-channel: '${{ github.workspace }}/channel/linux-64/'
118117
extracted-pkg-path: '${{ github.workspace }}/pkg/'
119-
tests-path: '${{ github.workspace }}/pkg/info/test/tests/'
120118
ver-json-path: '${{ github.workspace }}/version.json'
121119

122120
steps:
@@ -177,8 +175,7 @@ jobs:
177175
- name: Run tests
178176
if: env.RERUN_TESTS_ON_FAILURE != 'true'
179177
run: |
180-
python -m pytest -q -ra --disable-warnings -vv .
181-
working-directory: ${{ env.tests-path }}
178+
python -m pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
182179
183180
- name: Run tests
184181
if: env.RERUN_TESTS_ON_FAILURE == 'true'
@@ -192,8 +189,7 @@ jobs:
192189
command: |
193190
. $CONDA/etc/profile.d/conda.sh
194191
conda activate ${{ env.TEST_ENV_NAME }}
195-
cd ${{ env.tests-path }}
196-
python -m pytest -q -ra --disable-warnings -vv .
192+
pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
197193
198194
test_windows:
199195
name: Test ['windows-2019', python='${{ matrix.python }}']
@@ -216,8 +212,8 @@ jobs:
216212
channel-path: '${{ github.workspace }}\channel\'
217213
pkg-path-in-channel: '${{ github.workspace }}\channel\win-64\'
218214
extracted-pkg-path: '${{ github.workspace }}\pkg'
219-
tests-path: '${{ github.workspace }}\pkg\info\test\tests\'
220215
ver-json-path: '${{ github.workspace }}\version.json'
216+
workdir: '${{ github.workspace }}'
221217

222218
steps:
223219
- name: Download artifact
@@ -314,8 +310,7 @@ jobs:
314310
- name: Run tests
315311
if: env.RERUN_TESTS_ON_FAILURE != 'true'
316312
run: |
317-
python -m pytest -q -ra --disable-warnings -vv .
318-
working-directory: ${{ env.tests-path }}
313+
pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
319314
320315
- name: Run tests
321316
if: env.RERUN_TESTS_ON_FAILURE == 'true'
@@ -328,8 +323,7 @@ jobs:
328323
retry_on: any
329324
command: >-
330325
mamba activate ${{ env.TEST_ENV_NAME }}
331-
& cd ${{ env.tests-path }}
332-
& python -m pytest -q -ra --disable-warnings -vv .
326+
& pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
333327
334328
upload:
335329
name: Upload ['${{ matrix.os }}', python='${{ matrix.python }}']

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ repos:
3232
- id: python-no-eval
3333
exclude: |
3434
(?x)^(
35-
tests/test_arraycreation.py|
36-
tests/test_sycl_queue.py|
37-
tests/test_usm_type.py
35+
dpnp/tests/test_arraycreation.py|
36+
dpnp/tests/test_sycl_queue.py|
37+
dpnp/tests/test_usm_type.py
3838
)$
3939
- id: python-no-log-warn
4040
- id: python-use-type-annotations

MANIFEST.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

conda-recipe/meta.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ test:
5151
requires:
5252
- pytest
5353
- setuptools
54-
source_files:
55-
- examples
56-
- tests
57-
- setup.cfg
58-
commands:
59-
- python -c "import dpnp; print(dpnp.__version__)"
60-
- python -m dpctl -f
61-
- pytest -s
6254

6355
about:
6456
home: https://github.com/IntelPython/dpnp

conda-recipe/run_test.bat

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@echo on
2+
3+
REM if ONEAPI_ROOT is specified (use all from it)
4+
if defined ONEAPI_ROOT (
5+
set "DPCPPROOT=%ONEAPI_ROOT%\compiler\latest"
6+
set "MKLROOT=%ONEAPI_ROOT%\mkl\latest"
7+
set "TBBROOT=%ONEAPI_ROOT%\tbb\latest"
8+
set "DPLROOT=%ONEAPI_ROOT%\dpl\latest"
9+
)
10+
11+
REM if DPCPPROOT is specified (work with custom DPCPP)
12+
if defined DPCPPROOT (
13+
call "%DPCPPROOT%\env\vars.bat"
14+
)
15+
16+
REM if MKLROOT is specified (work with custom math library)
17+
if defined MKLROOT (
18+
call "%MKLROOT%\env\vars.bat"
19+
)
20+
21+
REM have to activate while SYCL CPU device/driver needs paths
22+
REM if TBBROOT is specified
23+
if defined TBBROOT (
24+
call "%TBBROOT%\env\vars.bat"
25+
)
26+
27+
REM If PYTHON is not set
28+
REM assign it to the Python interpreter from the testing environment
29+
if not defined PYTHON (
30+
for %%I in (python.exe) do set PYTHON=%%~$PATH:I
31+
)
32+
33+
34+
"%PYTHON%" -c "import dpnp; print(dpnp.__version__)"
35+
if errorlevel 1 exit 1
36+
37+
"%PYTHON%" -m dpctl -f
38+
if errorlevel 1 exit 1
39+
40+
"%PYTHON%" -m pytest -ra --pyargs dpnp
41+
if errorlevel 1 exit 1

conda-recipe/run_test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ if [ -n "${TBBROOT}" ]; then
2626
# shellcheck source=/dev/null
2727
. "${TBBROOT}"/env/vars.sh
2828
fi
29+
30+
# If PYTHON is not set
31+
# assign it to the Python interpreter from the testing environment
32+
if [ -z "${PYTHON}" ]; then
33+
PYTHON=$PREFIX/bin/python
34+
fi
35+
36+
set -e
37+
38+
$PYTHON -c "import dpnp; print(dpnp.__version__)"
39+
$PYTHON -m dpctl -f
40+
$PYTHON -m pytest -ra --pyargs dpnp

tests/__init__.py renamed to dpnp/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy
22

3-
from tests import testing
3+
from . import testing
44

55
numpy.testing.assert_allclose = testing.assert_allclose
66
numpy.testing.assert_array_equal = testing.assert_array_equal

tests/conftest.py renamed to dpnp/tests/conftest.py

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,66 @@ def get_excluded_tests(test_exclude_file):
4747
if os.path.exists(test_exclude_file):
4848
with open(test_exclude_file) as skip_names_file:
4949
excluded_tests = skip_names_file.readlines()
50-
return excluded_tests
50+
# Remove whitespace and filter out empty lines
51+
return [line.strip() for line in excluded_tests if line.strip()]
52+
53+
54+
# Normalize the nodeid to a relative path starting
55+
# from the "tests/" directory
56+
def normalize_test_name(nodeid):
57+
nodeid = nodeid.replace("\n", "").strip()
58+
59+
# case if run pytest from dpnp folder
60+
if nodeid.startswith("tests/"):
61+
return nodeid
62+
63+
# case if run pytest --pyargs
64+
if "/tests/" in nodeid:
65+
nodeid = nodeid.split("tests/", 1)[-1]
66+
# Add the "tests/" prefix to ensure the nodeid matches
67+
# the paths in the skipped tests files.
68+
normalized_nodeid = "tests/" + nodeid
69+
# case if run pytest from tests folder
70+
else:
71+
normalized_nodeid = "tests/" + nodeid
72+
73+
return normalized_nodeid
74+
75+
76+
def pytest_configure(config):
77+
# By default, tests marked as slow will be deselected.
78+
# To run all tests, use -m "slow or not slow".
79+
# To run only slow tests, use -m "slow".
80+
# Equivalent to addopts = -m "not slow"
81+
if not config.getoption("markexpr"):
82+
config.option.markexpr = "not slow"
83+
# Equivalent to addopts = --tb=short
84+
if not config.getoption("tbstyle"):
85+
config.option.tbstyle = "short"
86+
# Equivalent to addopts = --strict-markers
87+
if not config.getoption("strict_markers"):
88+
config.option.strict_markers = True
89+
90+
# Equivalent to norecursedirs = tests_perf
91+
config.addinivalue_line("norecursedirs", "tests_perf")
92+
93+
# Register pytest markers
94+
config.addinivalue_line(
95+
"markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')"
96+
)
97+
config.addinivalue_line(
98+
"markers",
99+
"multi_gpu: marks tests that require a specified number of GPUs",
100+
)
101+
102+
# NumPy arccosh
103+
# Undefined behavior depends on the backend:
104+
# NumPy with OpenBLAS for np.array[1.0] does not raise a warning
105+
# while numpy with OneMKL raises RuntimeWarning
106+
config.addinivalue_line(
107+
"filterwarnings",
108+
"ignore:invalid value encountered in arccosh:RuntimeWarning",
109+
)
51110

52111

53112
def pytest_collection_modifyitems(config, items):
@@ -85,16 +144,21 @@ def pytest_collection_modifyitems(config, items):
85144
excluded_tests.extend(get_excluded_tests(test_exclude_file))
86145

87146
for item in items:
88-
# some test name contains '\n' in the parameters
89-
test_name = item.nodeid.replace("\n", "").strip()
147+
test_name = normalize_test_name(item.nodeid)
90148

91149
for item_tbl in excluded_tests:
92-
# remove end-of-line character
93-
item_tbl_str = item_tbl.strip()
94150
# exact match of the test name with items from excluded_list
95-
if test_name == item_tbl_str:
151+
if test_name == item_tbl:
96152
item.add_marker(skip_mark)
97153

154+
# Handle the exclusion of tests marked as "slow"
155+
selected_marker = config.getoption("markexpr")
156+
if "not slow" in selected_marker:
157+
skip_slow = pytest.mark.skip(reason="Skipping slow tests")
158+
for item in items:
159+
if "slow" in item.keywords:
160+
item.add_marker(skip_slow)
161+
98162

99163
@pytest.fixture
100164
def allow_fall_back_on_numpy(monkeypatch):
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test_arithmetic.py renamed to dpnp/tests/test_arithmetic.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import unittest
22

3-
import numpy
4-
5-
from tests.helper import has_support_aspect64
6-
from tests.third_party.cupy import testing
3+
from .third_party.cupy import testing
74

85

96
class TestArithmetic(unittest.TestCase):
File renamed without changes.

tests/test_arraycreation.py renamed to dpnp/tests/test_arraycreation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
)
1414

1515
import dpnp
16-
from tests.third_party.cupy import testing
1716

1817
from .helper import (
1918
assert_dtype_allclose,
2019
get_all_dtypes,
21-
has_support_aspect64,
2220
)
21+
from .third_party.cupy import testing
2322

2423

2524
class TestArray:

tests/test_arraymanipulation.py renamed to dpnp/tests/test_arraymanipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
)
1111

1212
import dpnp
13-
from tests.third_party.cupy import testing
1413

1514
from .helper import get_all_dtypes, get_float_complex_dtypes
15+
from .third_party.cupy import testing
1616

1717

1818
class TestAtleast1d:

tests/test_arraypad.py renamed to dpnp/tests/test_arraypad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
import dpnp
1212
from dpnp.dpnp_utils.dpnp_utils_pad import _as_pairs as dpnp_as_pairs
13-
from tests.third_party.cupy import testing
1413

1514
from .helper import assert_dtype_allclose, get_all_dtypes
15+
from .third_party.cupy import testing
1616

1717

1818
class TestPad:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test_fft.py renamed to dpnp/tests/test_fft.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
assert_dtype_allclose,
1313
get_all_dtypes,
1414
get_complex_dtypes,
15-
get_float_complex_dtypes,
1615
get_float_dtypes,
1716
)
1817

File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test_functional.py renamed to dpnp/tests/test_functional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy
22
import pytest
3-
from numpy.testing import assert_array_equal, assert_equal, assert_raises
3+
from numpy.testing import assert_array_equal
44

55
import dpnp
66

File renamed without changes.

tests/test_indexing.py renamed to dpnp/tests/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import dpnp
1616
from dpnp.dpnp_array import dpnp_array
17-
from tests.third_party.cupy import testing
1817

1918
from .helper import get_all_dtypes, get_integer_dtypes, has_support_aspect64
19+
from .third_party.cupy import testing
2020

2121

2222
def _add_keepdims(func):

tests/test_linalg.py renamed to dpnp/tests/test_linalg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
)
1515

1616
import dpnp as inp
17-
from tests.third_party.cupy import testing
1817

1918
from .helper import (
2019
assert_dtype_allclose,
@@ -25,6 +24,7 @@
2524
has_support_aspect64,
2625
is_cpu_device,
2726
)
27+
from .third_party.cupy import testing
2828

2929

3030
def vvsort(val, vec, size, xp):
File renamed without changes.

tests/test_manipulation.py renamed to dpnp/tests/test_manipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from numpy.testing import assert_array_equal, assert_equal, assert_raises
88

99
import dpnp
10-
from tests.third_party.cupy import testing
1110

1211
from .helper import (
1312
assert_dtype_allclose,
@@ -18,6 +17,7 @@
1817
get_integer_dtypes,
1918
has_support_aspect64,
2019
)
20+
from .third_party.cupy import testing
2121

2222
testdata = []
2323
testdata += [

tests/test_mathematical.py renamed to dpnp/tests/test_mathematical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import dpnp
2121
from dpnp.dpnp_array import dpnp_array
22-
from tests.third_party.cupy import testing
2322

2423
from .helper import (
2524
assert_dtype_allclose,
@@ -36,6 +35,7 @@
3635
_get_numpy_arrays_2in_1out,
3736
_get_output_data_type,
3837
)
38+
from .third_party.cupy import testing
3939

4040

4141
class TestAngle:

tests/test_mixins.py renamed to dpnp/tests/test_mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from tests.third_party.cupy import testing
3+
from .third_party.cupy import testing
44

55

66
class TestMatMul(unittest.TestCase):

0 commit comments

Comments
 (0)