Skip to content

Commit 3e5ce5a

Browse files
committed
tests(cli): Add EnvFlag
1 parent 05aec2e commit 3e5ce5a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests for g's CLI package."""
22

3+
import enum
4+
import pathlib
35
import subprocess
46
import typing as t
57
from unittest.mock import patch
@@ -20,6 +22,13 @@ def get_output(
2022
return exc.output
2123

2224

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+
2332
@pytest.mark.parametrize(
2433
("argv_args", "expect_cmd"),
2534
[
@@ -33,6 +42,9 @@ class CommandLineTestFixture(t.NamedTuple):
3342
# pytest internal
3443
test_id: str
3544

45+
# env data
46+
env: EnvFlag
47+
3648
# test data
3749
argv_args: t.List[str]
3850

@@ -43,11 +55,13 @@ class CommandLineTestFixture(t.NamedTuple):
4355
TEST_FIXTURES: t.List[CommandLineTestFixture] = [
4456
CommandLineTestFixture(
4557
test_id="g-cmd-inside-git-dir",
58+
env=EnvFlag.Git,
4659
argv_args=["g"],
4760
expect_cmd="git",
4861
),
4962
CommandLineTestFixture(
5063
test_id="g-cmd-help-inside-git-dir",
64+
env=EnvFlag.Git,
5165
argv_args=["g --help"],
5266
expect_cmd="git --help",
5367
),
@@ -62,12 +76,20 @@ class CommandLineTestFixture(t.NamedTuple):
6276
def test_command_line(
6377
# capsys: pytest.CaptureFixture[str],
6478
test_id: str,
79+
env: EnvFlag,
6580
argv_args: t.List[str],
6681
expect_cmd: str,
82+
monkeypatch: pytest.MonkeyPatch,
83+
tmp_path: pathlib.Path,
6784
) -> None:
6885
"""Basic CLI usage."""
6986
from g import sys as gsys
7087

88+
if env == EnvFlag.Git:
89+
pass
90+
elif env == EnvFlag.Empty:
91+
monkeypatch.chdir(str(tmp_path))
92+
7193
with patch.object(gsys, "argv", argv_args):
7294
proc = run(wait=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7395
assert proc is not None

0 commit comments

Comments
 (0)