Skip to content

Commit c50416f

Browse files
committed
Example of deferred command
1 parent f1060be commit c50416f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/cmd/test_git.py

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from libvcs._internal.subprocess import SubprocessCommand
67
from libvcs.cmd import git
78

89

@@ -11,3 +12,20 @@ def test_run(dir_type: Callable, tmp_path: pathlib.Path):
1112
repo = git.Git(dir=dir_type(tmp_path))
1213

1314
assert repo.dir == tmp_path
15+
16+
17+
@pytest.mark.parametrize("dir_type", [str, pathlib.Path])
18+
def test_run_deferred(dir_type: Callable, tmp_path: pathlib.Path):
19+
class GitDeferred(git.Git):
20+
def run(self, args, **kwargs):
21+
return SubprocessCommand(["git", *args], **kwargs)
22+
23+
g = GitDeferred(dir=dir_type(tmp_path))
24+
cmd = g.run(["help"])
25+
26+
assert g.dir == tmp_path
27+
assert cmd.args == ["git", "help"]
28+
29+
assert cmd.run(capture_output=True, text=True).stdout.startswith(
30+
"usage: git [--version] [--help] [-C <path>]"
31+
)

0 commit comments

Comments
 (0)