Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cuda_pathfinder/tests/test_ctk_root_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess
import sys
import textwrap
from pathlib import Path

import pytest

Expand Down Expand Up @@ -427,7 +428,7 @@ def test_resolve_ctk_root_via_canary_none_when_probe_fails(mocker):
def test_resolve_ctk_root_via_canary_none_when_unrecognized(mocker):
mocker.patch(
f"{_MODULE}._resolve_system_loaded_abs_path_in_subprocess",
return_value=os.path.join(os.sep, "weird", "path", "libcudart.so.13"),
return_value=str(Path(os.sep, "weird", "path", "libcudart.so.13")),
)
assert resolve_ctk_root_via_canary("cudart") is None

Expand Down
3 changes: 2 additions & 1 deletion cuda_pathfinder/tests/test_driver_lib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import os
from pathlib import Path

import pytest
from child_load_nvidia_dynamic_lib_helper import (
Expand Down Expand Up @@ -157,7 +158,7 @@ def raise_child_process_failed():
abs_path = payload.abs_path
assert abs_path is not None
info_summary_append(f"abs_path={quote_for_shell(abs_path)}")
assert os.path.isfile(abs_path)
assert Path(abs_path).is_file()


def test_real_query_driver_cuda_version(info_summary_append):
Expand Down
8 changes: 4 additions & 4 deletions cuda_pathfinder/tests/test_find_bitcode_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _located_bitcode_lib_asserts(located_bitcode_lib):
assert isinstance(located_bitcode_lib.filename, str)
assert isinstance(located_bitcode_lib.found_via, str)
assert located_bitcode_lib.found_via in ("site-packages", "conda", "CUDA_PATH")
assert os.path.isfile(located_bitcode_lib.abs_path)
assert Path(located_bitcode_lib.abs_path).is_file()


@pytest.mark.usefixtures("clear_find_bitcode_lib_cache")
Expand All @@ -83,10 +83,10 @@ def test_locate_bitcode_lib(info_summary_append, libname):

info_summary_append(f"{lib_path=!r}")
_located_bitcode_lib_asserts(located_lib)
assert os.path.isfile(lib_path)
assert Path(lib_path).is_file()
assert lib_path == located_lib.abs_path
expected_filename = located_lib.filename
assert os.path.basename(lib_path) == expected_filename
assert Path(lib_path).name == expected_filename


@pytest.mark.usefixtures("clear_find_bitcode_lib_cache")
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_find_bitcode_lib_not_found_error_includes_cuda_home_directory_listing(m
find_bitcode_lib("device")

message = str(exc_info.value)
expected_missing_file = os.path.join(str(lib_dir), _bitcode_lib_filename("device"))
expected_missing_file = lib_dir / _bitcode_lib_filename("device")
assert f"No such file: {expected_missing_file}" in message
assert f'listdir("{lib_dir}"):' in message
assert "README.txt" in message
Expand Down
15 changes: 9 additions & 6 deletions cuda_pathfinder/tests/test_find_nvidia_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ def test_locate_non_ctk_headers(info_summary_append, libname):
info_summary_append(f"{hdr_dir=!r}")
if hdr_dir:
_located_hdr_dir_asserts(located_hdr_dir)
assert os.path.isdir(hdr_dir)
assert os.path.isfile(os.path.join(hdr_dir, SUPPORTED_HEADERS_NON_CTK[libname]))
hdr_dir_path = Path(hdr_dir)
assert hdr_dir_path.is_dir()
assert (hdr_dir_path / SUPPORTED_HEADERS_NON_CTK[libname]).is_file()
if have_distribution_for(libname):
assert hdr_dir is not None
hdr_dir_parts = hdr_dir.split(os.path.sep)
assert "site-packages" in hdr_dir_parts
assert "site-packages" in Path(hdr_dir).parts
elif STRICTNESS == "all_must_work":
assert hdr_dir is not None
if conda_prefix := os.environ.get("CONDA_PREFIX"):
Expand All @@ -152,6 +152,8 @@ def test_locate_non_ctk_headers(info_summary_append, libname):
inst_dirs = SUPPORTED_INSTALL_DIRS_NON_CTK.get(libname)
if inst_dirs is not None:
for inst_dir in inst_dirs:
# Absolute glob pattern: Path.glob needs a separate base dir,
# and the wildcard is not pinned to the last component.
globbed = glob.glob(inst_dir)
if hdr_dir in globbed:
break
Expand All @@ -172,9 +174,10 @@ def test_locate_ctk_headers(info_summary_append, libname):
info_summary_append(f"{hdr_dir=!r}")
if hdr_dir:
_located_hdr_dir_asserts(located_hdr_dir)
assert os.path.isdir(hdr_dir)
hdr_dir_path = Path(hdr_dir)
assert hdr_dir_path.is_dir()
h_filename = SUPPORTED_HEADERS_CTK[libname]
assert os.path.isfile(os.path.join(hdr_dir, h_filename))
assert (hdr_dir_path / h_filename).is_file()
if STRICTNESS == "all_must_work":
if libname == "cudla":
skip_if_missing_libnvcudla_so(libname, timeout=30)
Expand Down
10 changes: 5 additions & 5 deletions cuda_pathfinder/tests/test_find_static_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _located_static_lib_asserts(located_static_lib):
assert isinstance(located_static_lib.filename, str)
assert isinstance(located_static_lib.found_via, str)
assert located_static_lib.found_via in ("site-packages", "conda", "CUDA_PATH")
assert os.path.isfile(located_static_lib.abs_path)
assert Path(located_static_lib.abs_path).is_file()


@pytest.mark.usefixtures("clear_find_static_lib_cache")
Expand All @@ -69,10 +69,10 @@ def test_locate_static_lib(info_summary_append, libname):

info_summary_append(f"abs_path={quote_for_shell(lib_path)}")
_located_static_lib_asserts(located_lib)
assert os.path.isfile(lib_path)
assert Path(lib_path).is_file()
assert lib_path == located_lib.abs_path
expected_filename = located_lib.filename
assert os.path.basename(lib_path) == expected_filename
assert Path(lib_path).name == expected_filename


@pytest.mark.usefixtures("clear_find_static_lib_cache")
Expand All @@ -81,7 +81,7 @@ def test_locate_static_lib_search_order(monkeypatch, tmp_path):
conda_rel_path = CUDADEVRT_INFO["conda_rel_paths"][0]

site_pkg_rel = CUDADEVRT_INFO["site_packages_dirs"][0]
site_packages_lib_dir = tmp_path / "site-packages" / Path(site_pkg_rel.replace("/", os.sep))
site_packages_lib_dir = tmp_path / "site-packages" / Path(site_pkg_rel)
site_packages_path = _make_static_lib_file(site_packages_lib_dir, filename)

conda_prefix = tmp_path / "conda-prefix"
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_find_static_lib_not_found_error_includes_cuda_home_directory_listing(mo
find_static_lib("cudadevrt")

message = str(exc_info.value)
expected_missing_file = os.path.join(str(lib_dir), filename)
expected_missing_file = lib_dir / filename
assert f"No such file: {expected_missing_file}" in message
assert f'listdir("{lib_dir}"):' in message
assert "README.txt" in message
Expand Down
3 changes: 2 additions & 1 deletion cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
import platform
from pathlib import Path

import pytest
from child_load_nvidia_dynamic_lib_helper import (
Expand Down Expand Up @@ -159,4 +160,4 @@ def raise_child_process_failed():
abs_path = payload.abs_path
assert abs_path is not None
info_summary_append(f"abs_path={quote_for_shell(abs_path)}")
assert os.path.isfile(abs_path) # double-check the abs_path
assert Path(abs_path).is_file() # double-check the abs_path
4 changes: 2 additions & 2 deletions cuda_pathfinder/tests/test_utils_find_sub_dirs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import os
from pathlib import Path

import pytest

Expand Down Expand Up @@ -77,7 +77,7 @@ def test_empty_parent_paths():
def test_empty_sub_dirs(test_tree):
parent_paths = test_tree["parent_paths"]
result = find_sub_dirs(parent_paths, ())
expected = [p for p in parent_paths if os.path.isdir(p)]
expected = [p for p in parent_paths if Path(p).is_dir()]
assert sorted(result) == sorted(expected)


Expand Down
Loading