Skip to content

Commit 0e44f4a

Browse files
committed
Add tests
1 parent cdf8fa3 commit 0e44f4a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

python/grass/script/tests/grass_script_core_get_commands_test.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import sys
5-
5+
import stat
66
import pytest
77

88
import grass.script as gs
@@ -65,3 +65,35 @@ def test_in_session(tmp_path):
6565
with gs.setup.init(project, env=os.environ.copy()) as session:
6666
executables_set, scripts_dict = gs.get_commands(env=session.env)
6767
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

scripts/g.extension/tests/g_extension_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test g.extension"""
22

33
import pytest
4+
import grass.script as gs
45

56

67
# This should cover both C and Python tools.
@@ -9,3 +10,8 @@ def test_install(tools, name):
910
"""Test that a tools installs and gives help message"""
1011
tools.g_extension(extension=name)
1112
assert tools.call_cmd([name, "--help"]).stderr
13+
14+
# Check that the installed extension is in the get_commands() list
15+
# i.e., GRASS_ADDON_BASE is accessible or not.
16+
commands = gs.get_commands(env=tools._original_env)[0]
17+
assert name in commands, f"Extension {name} not found in get_commands() list"

0 commit comments

Comments
 (0)