Skip to content

Commit 13e1e83

Browse files
committed
Add subprocess tests
1 parent 3ba82d9 commit 13e1e83

File tree

8 files changed

+167
-31
lines changed

8 files changed

+167
-31
lines changed

tests/test_executor/test_task_cwd/test_task_cwd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from pathlib import Path
22

3+
import pytest
4+
35
from tests.conftest import task_obj
46
from vscode_task_runner import executor
7+
from vscode_task_runner.exceptions import WorkingDirectoryNotFound
58

69

710
def test_full(linux: None, pathlib_is_dir_true: None) -> None:
@@ -38,3 +41,10 @@ def test_partial5(linux: None, pathlib_is_dir_true: None) -> None:
3841
task.linux = None
3942

4043
assert executor.task_cwd(task) == Path("/value2")
44+
45+
46+
def test_directroy_not_found() -> None:
47+
task = task_obj(__file__, "cwd-test")
48+
49+
with pytest.raises(WorkingDirectoryNotFound):
50+
executor.task_cwd(task)

tests/test_executor/test_task_env/test_task_env.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from tests.conftest import task_obj
24
from vscode_task_runner import executor
35

@@ -43,3 +45,19 @@ def test_partial5(linux: None) -> None:
4345
task.linux = None
4446

4547
assert executor._new_task_env(task) == {"TEST1": "value1", "TEST2": "value2"}
48+
49+
50+
@pytest.mark.parametrize(
51+
"environment_variable",
52+
[("TEST3", "oldvalue")],
53+
indirect=True,
54+
)
55+
def test_task_env(environment_variable: None) -> None:
56+
"""
57+
Test that the task environment is merged with the current environment.
58+
"""
59+
task = task_obj(__file__, "env-test")
60+
env = executor.task_env(task)
61+
assert env["TEST3"] == "value3"
62+
# moer than just test3 and 4
63+
assert len(env) >= 2

tests/test_executor/test_task_env_types/.vscode/tasks.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/test_executor/test_task_env_types/test_task_env_types.py

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "test1",
6+
"command": "echo $TEST1 $TEST2 $TEST3",
7+
"type": "shell",
8+
},
9+
{
10+
"label": "test2",
11+
"command": "echo $TEST1 $TEST2 $TEST3",
12+
"type": "shell",
13+
"dependsOn": "test1",
14+
},
15+
{
16+
"label": "test3",
17+
"dependsOn": "test1",
18+
},
19+
]
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from tests.conftest import task_obj
2+
from vscode_task_runner import executor
3+
4+
5+
def test_is_virtual_task() -> None:
6+
t1 = task_obj(__file__, "test1")
7+
assert executor.is_virtual_task(t1) is False
8+
9+
t2 = task_obj(__file__, "test2")
10+
assert executor.is_virtual_task(t2) is False
11+
12+
t3 = task_obj(__file__, "test3")
13+
assert executor.is_virtual_task(t3) is True
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "1",
6+
"type": "process",
7+
"command": "echo",
8+
"args": ["hello world"]
9+
},
10+
{
11+
"label": "2",
12+
"type": "shell",
13+
"command": "echo 'hello world'",
14+
"options": {"shell": {
15+
"executable": "bash",
16+
"args": ["-c"]
17+
}}
18+
},
19+
{
20+
"label": "3",
21+
"type": "shell",
22+
"command": "echo",
23+
"args": ["hello world"],
24+
"options": {"shell": {
25+
"executable": "bash",
26+
"args": ["-c"]
27+
}}
28+
},
29+
{
30+
"label": "4",
31+
"type": "shell",
32+
"command": {"value": "echo 'hello world'", "quoting": "weak"},
33+
"options": {"shell": {
34+
"executable": "bash",
35+
"args": ["-c"]
36+
}}
37+
},
38+
{
39+
"label": "5",
40+
},
41+
]
42+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import pytest
2+
3+
from tests.conftest import task_obj
4+
from vscode_task_runner import executor
5+
from vscode_task_runner.exceptions import MissingCommand
6+
7+
8+
@pytest.mark.parametrize(
9+
"label, expected",
10+
[
11+
(
12+
"1",
13+
["echo", "hello world"],
14+
),
15+
(
16+
"2",
17+
["bash", "-c", "echo 'hello world'"],
18+
),
19+
],
20+
)
21+
def test_task_subprocess_command(
22+
label: str, expected: list[str], shutil_which_patch: None
23+
) -> None:
24+
task = task_obj(__file__, label)
25+
26+
assert executor.task_subprocess_command(task) == expected
27+
28+
29+
@pytest.mark.parametrize(
30+
"label, expected",
31+
[
32+
(
33+
"1",
34+
["echo", "hello world", "--verbose"],
35+
),
36+
(
37+
"2",
38+
["bash", "-c", "echo 'hello world' --verbose"],
39+
),
40+
(
41+
"3",
42+
["bash", "-c", "echo 'hello world' --verbose"],
43+
),
44+
(
45+
"4",
46+
["bash", "-c", "\"echo 'hello world' --verbose\""],
47+
),
48+
],
49+
)
50+
def test_task_subprocess_command_extra_args(
51+
label: str, expected: list[str], shutil_which_patch: None
52+
) -> None:
53+
task = task_obj(__file__, label)
54+
55+
assert executor.task_subprocess_command(task, extra_args=["--verbose"]) == expected
56+
57+
58+
def test_task_subprocess_command_no_command(
59+
shutil_which_patch: None,
60+
) -> None:
61+
task = task_obj(__file__, "5")
62+
63+
with pytest.raises(MissingCommand):
64+
executor.task_subprocess_command(task)

0 commit comments

Comments
 (0)