forked from NVIDIA/cuda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_examples.py
More file actions
33 lines (25 loc) · 1.25 KB
/
Copy pathtest_examples.py
File metadata and controls
33 lines (25 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
import glob
import os
import subprocess
import sys
import pytest
from cuda.bindings._test_helpers.pep723 import has_package_requirements_or_skip
examples_path = os.path.join(os.path.dirname(__file__), "..", "examples")
examples_files = glob.glob(os.path.join(examples_path, "**/*.py"), recursive=True)
@pytest.mark.parametrize("example", examples_files)
def test_example(example):
has_package_requirements_or_skip(example)
env = os.environ.copy()
env["CUDA_BINDINGS_SKIP_EXAMPLE"] = "100"
process = subprocess.run([sys.executable, example], capture_output=True, env=env) # noqa: S603
# returncode is a special value used in the examples to indicate that system requirements are not met.
if process.returncode == 100:
pytest.skip(process.stderr.decode(errors="replace").strip())
elif process.returncode != 0:
if process.stdout:
print(process.stdout.decode(errors="replace"))
if process.stderr:
print(process.stderr.decode(errors="replace"), file=sys.stderr)
raise AssertionError(f"`{example}` failed ({process.returncode})")