Skip to content

Commit 7ca8e34

Browse files
committed
Address comments in PR
1 parent 6c5f7c1 commit 7ca8e34

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

cuda_core/tests/example_tests/test_basic_examples.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ def has_cuda_path() -> bool:
6363

6464

6565
def has_package_requirements_or_skip(example):
66+
example_name = os.path.basename(example)
67+
6668
with open(example, encoding="utf-8") as f:
6769
content = f.read()
6870

6971
# The canonical regex as defined in PEP 723
7072
pep723 = re.search(r"(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)+)^# ///$", content)
7173
if not pep723:
72-
return
74+
raise ValueError(f"PEP 723 metadata not found in {example_name}")
7375

7476
metadata = {}
7577
for line in pep723.group("content").splitlines():
@@ -81,14 +83,20 @@ def has_package_requirements_or_skip(example):
8183
value = value.strip()
8284
metadata[key] = value
8385

84-
if "dependencies" in metadata:
85-
dependencies = eval(metadata["dependencies"]) # noqa: S307
86-
for dependency in dependencies:
87-
name = re.match("[a-zA-Z0-9_-]+", dependency)
88-
try:
89-
importlib.metadata.distribution(name.string)
90-
except importlib.metadata.PackageNotFoundError:
91-
pytest.skip(f"Skipping {example} due to missing package requirement: {name}")
86+
if "dependencies" not in metadata:
87+
raise ValueError(f"PEP 723 dependencies not found in {example_name}")
88+
89+
missing_dependencies = []
90+
dependencies = eval(metadata["dependencies"]) # noqa: S307
91+
for dependency in dependencies:
92+
name = re.match("[a-zA-Z0-9_-]+", dependency)
93+
try:
94+
importlib.metadata.distribution(name.string)
95+
except importlib.metadata.PackageNotFoundError:
96+
missing_dependencies.append(name.string)
97+
98+
if missing_dependencies:
99+
pytest.skip(f"Skipping {example} due to missing package requirement: {', '.join(missing_dependencies)}")
92100

93101

94102
@pytest.mark.parametrize("example", sample_files)
@@ -103,7 +111,7 @@ def test_example(example):
103111
process = subprocess.run([sys.executable, example_path], capture_output=True) # noqa: S603
104112
if process.returncode != 0:
105113
if process.stdout:
106-
print(process.stdout.decode())
114+
print(process.stdout.decode(errors="replace"))
107115
if process.stderr:
108-
print(process.stderr.decode(), file=sys.stderr)
116+
print(process.stderr.decode(errors="replace"), file=sys.stderr)
109117
raise AssertionError(f"`{example}` failed ({process.returncode})")

0 commit comments

Comments
 (0)