1
1
"""Tests for g's CLI package."""
2
2
3
+ import enum
4
+ import pathlib
3
5
import subprocess
4
6
import typing as t
5
7
from unittest .mock import patch
@@ -20,6 +22,13 @@ def get_output(
20
22
return exc .output
21
23
22
24
25
+ class EnvFlag (enum .Enum ):
26
+ """Environmental conditions to simulate in test case."""
27
+
28
+ Git = "Git" # Inside a git directory (like this repo)
29
+ Empty = "Empty" # Empty directory (e.g. `tmp_path`)
30
+
31
+
23
32
@pytest .mark .parametrize (
24
33
("argv_args" , "expect_cmd" ),
25
34
[
@@ -33,6 +42,9 @@ class CommandLineTestFixture(t.NamedTuple):
33
42
# pytest internal
34
43
test_id : str
35
44
45
+ # env data
46
+ env : EnvFlag
47
+
36
48
# test data
37
49
argv_args : t .List [str ]
38
50
@@ -43,11 +55,13 @@ class CommandLineTestFixture(t.NamedTuple):
43
55
TEST_FIXTURES : t .List [CommandLineTestFixture ] = [
44
56
CommandLineTestFixture (
45
57
test_id = "g-cmd-inside-git-dir" ,
58
+ env = EnvFlag .Git ,
46
59
argv_args = ["g" ],
47
60
expect_cmd = "git" ,
48
61
),
49
62
CommandLineTestFixture (
50
63
test_id = "g-cmd-help-inside-git-dir" ,
64
+ env = EnvFlag .Git ,
51
65
argv_args = ["g --help" ],
52
66
expect_cmd = "git --help" ,
53
67
),
@@ -62,12 +76,20 @@ class CommandLineTestFixture(t.NamedTuple):
62
76
def test_command_line (
63
77
# capsys: pytest.CaptureFixture[str],
64
78
test_id : str ,
79
+ env : EnvFlag ,
65
80
argv_args : t .List [str ],
66
81
expect_cmd : str ,
82
+ monkeypatch : pytest .MonkeyPatch ,
83
+ tmp_path : pathlib .Path ,
67
84
) -> None :
68
85
"""Basic CLI usage."""
69
86
from g import sys as gsys
70
87
88
+ if env == EnvFlag .Git :
89
+ pass
90
+ elif env == EnvFlag .Empty :
91
+ monkeypatch .chdir (str (tmp_path ))
92
+
71
93
with patch .object (gsys , "argv" , argv_args ):
72
94
proc = run (wait = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
73
95
assert proc is not None
0 commit comments