-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_commands.py
36 lines (30 loc) · 1.15 KB
/
test_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from contextlib import nullcontext as does_not_raise
from pathlib import Path
from subprocess import CalledProcessError
from typing import ContextManager, Dict, List, Optional, Union
from pytest import mark, raises
from repo_management import commands
@mark.parametrize("env", [(None), ({"FOO": "BAR"})])
def test__print_env(env: Optional[Dict[str, str]]) -> None:
commands._print_env(env)
@mark.parametrize(
"cmd, env, debug, echo, quiet, check, cwd, expectation",
[
(["ls", "-lah"], {"FOO": "BAR"}, False, False, False, False, None, does_not_raise()),
(["ls", "-lah"], {"FOO": "BAR"}, True, False, False, False, None, does_not_raise()),
(["cd", "-f"], {"FOO": "BAR"}, True, False, False, True, None, raises(CalledProcessError)),
],
)
@mark.asyncio
def test_run_command(
cmd: Union[str, List[str]],
env: Optional[Dict[str, str]],
debug: bool,
echo: bool,
quiet: bool,
check: bool,
cwd: Union[Optional[str], Optional[Path]],
expectation: ContextManager[str],
) -> None:
with expectation:
commands.run_command(cmd=cmd, env=env, debug=debug, echo=echo, quiet=quiet, check=check, cwd=cwd)