|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | import sys |
5 | | - |
| 5 | +import stat |
6 | 6 | import pytest |
7 | 7 |
|
8 | 8 | import grass.script as gs |
@@ -65,3 +65,35 @@ def test_in_session(tmp_path): |
65 | 65 | with gs.setup.init(project, env=os.environ.copy()) as session: |
66 | 66 | executables_set, scripts_dict = gs.get_commands(env=session.env) |
67 | 67 | common_test_code(executables_set, scripts_dict) |
| 68 | + |
| 69 | + |
| 70 | +def test_addon_path_multiple_dirs(tmp_path): |
| 71 | + """Test that get_commands scans multiple directories in GRASS_ADDON_PATH""" |
| 72 | + |
| 73 | + dir_a = tmp_path / "addon_a" |
| 74 | + dir_b = tmp_path / "addon_b" |
| 75 | + dir_a.mkdir() |
| 76 | + dir_b.mkdir() |
| 77 | + |
| 78 | + bin_a = dir_a / "scripts" |
| 79 | + bin_b = dir_b / "bin" |
| 80 | + bin_a.mkdir() |
| 81 | + bin_b.mkdir() |
| 82 | + |
| 83 | + ext = ".py" if sys.platform == "win32" else "" |
| 84 | + script_a = f"my_custom_cmd_a{ext}" |
| 85 | + script_b = f"my_custom_cmd_b{ext}" |
| 86 | + |
| 87 | + for folder, script in [(bin_a, script_a), (bin_b, script_b)]: |
| 88 | + file_path = folder / script |
| 89 | + file_path.write_text("#!/bin/sh\necho 'Test ADDON PATH'", encoding="utf-8") |
| 90 | + file_path.chmod(stat.S_IRWXU) |
| 91 | + |
| 92 | + new_path = f"{dir_a}{os.pathsep}{dir_b}" |
| 93 | + env = os.environ.copy() |
| 94 | + env["GRASS_ADDON_PATH"] = new_path |
| 95 | + |
| 96 | + executables_set, _ = gs.get_commands(env=env) |
| 97 | + |
| 98 | + assert "my_custom_cmd_a" in executables_set |
| 99 | + assert "my_custom_cmd_b" in executables_set |
0 commit comments