Skip to content

Commit 9f741d0

Browse files
committed
test(cli): add tests for display_deptry_version
1 parent 1f6d6ec commit 9f741d0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tests/unit/test_cli.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import re
44
from typing import TYPE_CHECKING
55
from unittest import mock
6+
from unittest.mock import patch
67

78
import click
89
import pytest
910

10-
from deptry.cli import CommaSeparatedMappingParamType, CommaSeparatedTupleParamType
11+
from deptry.cli import CommaSeparatedMappingParamType, CommaSeparatedTupleParamType, display_deptry_version
1112

1213
if TYPE_CHECKING:
1314
from collections.abc import MutableMapping, Sequence
@@ -174,3 +175,38 @@ def test_comma_separated_mapping_param_type_convert_err(
174175

175176
with pytest.raises(err_type, match=err_msg_matcher):
176177
param_type.convert(value=value, param=param, ctx=ctx)
178+
179+
180+
def test_display_deptry_version(capsys: pytest.CaptureFixture[str]) -> None:
181+
ctx = mock.Mock(resilient_parsing=False, spec=click.Context)
182+
param = mock.Mock(spec=click.Parameter)
183+
184+
with patch("deptry.cli.importlib_metadata.version", return_value="1.2.3"):
185+
display_deptry_version(ctx, param, True)
186+
187+
assert capsys.readouterr().out == "deptry 1.2.3\n"
188+
189+
190+
@pytest.mark.parametrize(
191+
("resilient_parsing", "value"),
192+
[
193+
(
194+
False,
195+
False,
196+
),
197+
(
198+
True,
199+
False,
200+
),
201+
(
202+
True,
203+
True,
204+
),
205+
],
206+
)
207+
def test_display_deptry_version_none(resilient_parsing: bool, value: bool, capsys: pytest.CaptureFixture[str]) -> None:
208+
ctx = mock.Mock(resilient_parsing=resilient_parsing, spec=click.Context)
209+
param = mock.Mock(spec=click.Parameter)
210+
211+
display_deptry_version(ctx, param, value)
212+
assert capsys.readouterr().out == ""

0 commit comments

Comments
 (0)