@@ -462,25 +462,36 @@ def test_cupy_cuda_requirement_accepts_conda_cupy_distribution(tmp_path: Path, i
462462 assert requested == ["cupy-cuda13x" , "cupy" ]
463463
464464
465- @pytest .mark .parametrize ("available" , [True , False ], ids = ["local-library" , "missing-library" ])
466- @pytest .mark .agent_authored (model = "gpt-6" )
467- def test_unversioned_curand_requirement_accepts_native_library (
468- tmp_path : Path , installed_distributions , monkeypatch : pytest .MonkeyPatch , available : bool
469- ) -> None :
470- pathfinder = ModuleType ("cuda.pathfinder" )
465+ @pytest .fixture
466+ def native_pathfinder (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ):
467+ modules = tmp_path / "native_modules"
468+ cuda = modules / "cuda"
469+ cuda .mkdir (parents = True )
470+ (cuda / "__init__.py" ).write_text ("" , encoding = "utf-8" )
471+ monkeypatch .setenv ("PYTHONPATH" , str (modules ))
472+
473+ def provide (body : str ) -> None :
474+ (cuda / "pathfinder.py" ).write_text (
475+ "class DynamicLibNotFoundError(RuntimeError):\n pass\n \n "
476+ "def load_nvidia_dynamic_lib(name):\n "
477+ " assert name == 'curand'\n "
478+ f" { body } \n " ,
479+ encoding = "utf-8" ,
480+ )
471481
472- class DynamicLibNotFoundError (RuntimeError ):
473- pass
482+ return provide
474483
475- def load_library (name : str ) -> object :
476- assert name == "curand"
477- if not available :
478- raise DynamicLibNotFoundError ("cuRAND is not installed" )
479- return object ()
480484
481- pathfinder .DynamicLibNotFoundError = DynamicLibNotFoundError
482- pathfinder .load_nvidia_dynamic_lib = load_library
483- monkeypatch .setattr (run_samples ._runner .importlib , "import_module" , lambda _name : pathfinder )
485+ @pytest .mark .parametrize ("available" , [True , False ], ids = ["local-library" , "parent-only-library" ])
486+ @pytest .mark .agent_authored (model = "gpt-6" )
487+ def test_unversioned_curand_requirement_checks_the_sample_process (
488+ tmp_path : Path , installed_distributions , monkeypatch : pytest .MonkeyPatch , native_pathfinder , available : bool
489+ ) -> None :
490+ native_pathfinder ("return object()" if available else "raise DynamicLibNotFoundError('cuRAND is not installed')" )
491+ parent = ModuleType ("cuda.pathfinder" )
492+ parent .DynamicLibNotFoundError = RuntimeError
493+ parent .load_nvidia_dynamic_lib = lambda _name : object ()
494+ monkeypatch .setitem (sys .modules , "cuda.pathfinder" , parent )
484495
485496 missing = run_samples .missing_dependencies (_sample (tmp_path , "['nvidia-curand']" ))
486497
@@ -489,30 +500,35 @@ def load_library(name: str) -> object:
489500
490501@pytest .mark .agent_authored (model = "gpt-6" )
491502def test_native_curand_check_tolerates_missing_pathfinder (
492- tmp_path : Path , installed_distributions , monkeypatch : pytest . MonkeyPatch
503+ tmp_path : Path , installed_distributions , native_pathfinder
493504) -> None :
494- def import_module (name : str ) -> ModuleType :
495- raise ModuleNotFoundError (name = name )
496-
497- monkeypatch .setattr (run_samples ._runner .importlib , "import_module" , import_module )
498-
499505 missing = run_samples .missing_dependencies (_sample (tmp_path , "['nvidia-curand']" ))
500506
501507 assert len (missing ) == 1
502508 assert "no provider distribution installed" in missing [0 ]
503509
504510
511+ @pytest .mark .agent_authored (model = "gpt-6" )
512+ def test_native_curand_check_propagates_unexpected_errors (native_pathfinder ) -> None :
513+ native_pathfinder ("raise RuntimeError('broken library probe')" )
514+
515+ with pytest .raises (subprocess .CalledProcessError ) as exc :
516+ run_samples ._runner ._native_curand_available ()
517+
518+ assert "RuntimeError: broken library probe" in exc .value .stderr
519+
520+
505521@pytest .mark .parametrize (
506522 "requirement" , ["nvidia-curand>=11" , "nvidia-curand[extra]" , "nvidia-curand @ https://example.com/curand.whl" ]
507523)
508524@pytest .mark .agent_authored (model = "gpt-6" )
509525def test_curand_constraints_require_a_provider_distribution (
510526 tmp_path : Path , installed_distributions , monkeypatch : pytest .MonkeyPatch , requirement : str
511527) -> None :
512- def unexpected_import ( name : str ) -> ModuleType :
528+ def unexpected_probe ( ) -> bool :
513529 raise AssertionError ("constrained requirements must use distribution metadata" )
514530
515- monkeypatch .setattr (run_samples ._runner . importlib , "import_module " , unexpected_import )
531+ monkeypatch .setattr (run_samples ._runner , "_native_curand_available " , unexpected_probe )
516532
517533 missing = run_samples .missing_dependencies (_sample (tmp_path , f"[{ requirement !r} ]" ))
518534
0 commit comments