|
3 | 3 | import re |
4 | 4 | from typing import TYPE_CHECKING |
5 | 5 | from unittest import mock |
| 6 | +from unittest.mock import patch |
6 | 7 |
|
7 | 8 | import click |
8 | 9 | import pytest |
9 | 10 |
|
10 | | -from deptry.cli import CommaSeparatedMappingParamType, CommaSeparatedTupleParamType |
| 11 | +from deptry.cli import CommaSeparatedMappingParamType, CommaSeparatedTupleParamType, display_deptry_version |
11 | 12 |
|
12 | 13 | if TYPE_CHECKING: |
13 | 14 | from collections.abc import MutableMapping, Sequence |
@@ -174,3 +175,38 @@ def test_comma_separated_mapping_param_type_convert_err( |
174 | 175 |
|
175 | 176 | with pytest.raises(err_type, match=err_msg_matcher): |
176 | 177 | 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