Skip to content

Commit bd24ee0

Browse files
authored
Merge branch 'master' into introduce_ruff
2 parents 51d9a93 + 4366a73 commit bd24ee0

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/pre_commit_terraform/terraform_docs_replace.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
5353
'https://github.com/antonbabenko/pre-commit-terraform/issues/248'
5454
'#issuecomment-1290829226',
5555
category=UserWarning,
56+
stacklevel=1, # It's should be 2, but tests are failing w/ values >1. As it's deprecated hook, it's safe to leave it as is w/o fixing it later.
5657
)
5758

5859
dirs: list[str] = []
59-
for filename in cast_to(list[str], parsed_cli_args.filenames):
60+
for filename in cast_to('list[str]', parsed_cli_args.filenames):
6061
if os.path.realpath(filename) not in dirs and (
61-
filename.endswith('.tf') or filename.endswith('.tfvars')
62+
filename.endswith(('.tf', '.tfvars'))
6263
):
6364
dirs.append(os.path.dirname(filename))
6465

@@ -68,14 +69,17 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
6869
try:
6970
procArgs = []
7071
procArgs.append('terraform-docs')
71-
if cast_to(bool, parsed_cli_args.sort):
72+
if cast_to('bool', parsed_cli_args.sort):
7273
procArgs.append('--sort-by-required')
73-
procArgs.append('md')
74-
procArgs.append('./{dir}'.format(dir=dir))
75-
procArgs.append('>')
76-
procArgs.append(
77-
'./{dir}/{dest}'.format(
78-
dir=dir, dest=cast_to(bool, parsed_cli_args.dest)
74+
procArgs.extend(
75+
(
76+
'md',
77+
f'./{dir}',
78+
'>',
79+
'./{dir}/{dest}'.format(
80+
dir=dir,
81+
dest=cast_to('bool', parsed_cli_args.dest),
82+
),
7983
),
8084
)
8185
subprocess.check_call(' '.join(procArgs), shell=True)

tests/pytest/_cli_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def invoke_cli_app( # noqa: PLR6301
9191
self,
9292
parsed_cli_args: Namespace, # noqa: ARG002
9393
) -> ReturnCodeType:
94-
err = 'sentinel'
95-
raise PreCommitTerraformExit(err)
94+
raise PreCommitTerraformExit(self.CLI_SUBCOMMAND_NAME)
9695

9796
monkeypatch.setattr(
9897
_cli_parsing_mod,

tests/pytest/terraform_docs_replace_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from argparse import ArgumentParser, Namespace
44
from subprocess import CalledProcessError
55

6-
import pytest
76
import pytest_mock
87

8+
import pytest
99
from pre_commit_terraform._structs import ReturnCode
1010
from pre_commit_terraform.terraform_docs_replace import (
1111
invoke_cli_app,
1212
populate_argument_parser,
13+
)
14+
from pre_commit_terraform.terraform_docs_replace import (
1315
subprocess as replace_docs_subprocess_mod,
1416
)
1517

@@ -82,7 +84,7 @@ def test_control_flow_positive(
8284
check_call_mock,
8385
)
8486

85-
assert ReturnCode.OK == invoke_cli_app(parsed_cli_args)
87+
assert invoke_cli_app(parsed_cli_args) == ReturnCode.OK
8688

8789
executed_commands = [
8890
cmd for ((cmd,), _shell) in check_call_mock.call_args_list
@@ -117,6 +119,6 @@ def test_control_flow_negative(
117119
check_call_mock,
118120
)
119121

120-
assert ReturnCode.ERROR == invoke_cli_app(parsed_cli_args)
122+
assert invoke_cli_app(parsed_cli_args) == ReturnCode.ERROR
121123

122124
check_call_mock.assert_called_once_with(expected_cmd, shell=True)

0 commit comments

Comments
 (0)