11from __future__ import annotations
22
3+ import re
34import sys
45from pathlib import Path
56from typing import Any
1819
1920
2021@pytest .mark .write_disk
21- def test_register_plugin_function_invalid_plugin_path (tmp_path : Path ) -> None :
22+ def test_register_plugin_function_invalid_plugin_path (
23+ plmonkeypatch : PlMonkeyPatch , tmp_path : Path
24+ ) -> None :
25+ # The full path is shown in verbose mode; tmp_path may be long enough to truncate.
26+ plmonkeypatch .setenv ("POLARS_VERBOSE" , "1" )
2227 tmp_path .mkdir (exist_ok = True )
2328 plugin_path = tmp_path / "lib.so"
2429 plugin_path .touch ()
@@ -27,8 +32,38 @@ def test_register_plugin_function_invalid_plugin_path(tmp_path: Path) -> None:
2732 plugin_path = plugin_path , function_name = "hello" , args = 5
2833 )
2934
30- with pytest .raises (ComputeError , match = "error loading dynamic library" ):
35+ with pytest .raises (
36+ ComputeError ,
37+ match = f"error loading dynamic library: .*: { re .escape (str (plugin_path ))} $" ,
38+ ):
39+ pl .select (expr )
40+
41+
42+ @pytest .mark .write_disk
43+ def test_register_plugin_function_invalid_plugin_long_path (
44+ plmonkeypatch : PlMonkeyPatch , tmp_path : Path
45+ ) -> None :
46+ plmonkeypatch .setenv ("POLARS_VERBOSE" , "0" )
47+ plugin_dir = tmp_path / ("a" * 100 )
48+ plugin_dir .mkdir ()
49+ plugin_path = plugin_dir / "lib.so"
50+ plugin_path .touch ()
51+
52+ expr = register_plugin_function (
53+ plugin_path = plugin_path , function_name = "hello" , args = 5
54+ )
55+
56+ # Long paths are truncated from the front, keeping the tail and a hint.
57+ # Match either path separator, as Windows joins paths with a backslash.
58+ with pytest .raises (
59+ ComputeError ,
60+ match = (
61+ r"error loading dynamic library: .*: \.\.\.a+[\\/]lib\.so "
62+ r"\(set POLARS_VERBOSE=1 to see full path\)"
63+ ),
64+ ) as exc_info :
3165 pl .select (expr )
66+ assert str (plugin_path ) not in str (exc_info .value )
3267
3368
3469@pytest .mark .parametrize (
0 commit comments