From 93248c6a059013b274b14c34586f7269a6a90e30 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Sat, 23 Sep 2023 22:48:02 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Test=20version=20getting=20printed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/esxport_cli.py | 3 ++- src/strings.py | 1 + test/click/cli_test.py | 14 +++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/esxport_cli.py b/src/esxport_cli.py index 5daba9b..b4afcb8 100644 --- a/src/esxport_cli.py +++ b/src/esxport_cli.py @@ -13,6 +13,7 @@ from src.click_opt.click_custom import JSON, sort from src.constant import META_FIELDS from src.elastic import ElasticsearchClient +from src.strings import cli_version if TYPE_CHECKING: from pathlib import Path @@ -22,7 +23,7 @@ def print_version(ctx: Context, _: Parameter, value: bool) -> None: # noqa: FBT """Print Version information.""" if not value or ctx.resilient_parsing: return - click.echo(f"EsXport Cli {__version__}") + click.echo(cli_version.format(__version__=__version__)) ctx.exit() diff --git a/src/strings.py b/src/strings.py index 048b4f1..c235c3d 100644 --- a/src/strings.py +++ b/src/strings.py @@ -7,3 +7,4 @@ meta_field_not_found = "Meta Field {field} not found" invalid_sort_format = 'Invalid input format: "{value}". Use the format "field:sort_order".' invalid_query_format = "{value} is not a valid json string, caused {exc}" +cli_version = "EsXport Cli {__version__}" diff --git a/test/click/cli_test.py b/test/click/cli_test.py index 38f4848..073e59c 100644 --- a/test/click/cli_test.py +++ b/test/click/cli_test.py @@ -9,9 +9,10 @@ from click.testing import CliRunner from typing_extensions import Self +from src.__init__ import __version__ from src.esxport import EsXport from src.esxport_cli import cli -from src.strings import invalid_query_format, invalid_sort_format +from src.strings import cli_version, invalid_query_format, invalid_sort_format args = { "q": '{"query":{"match_all":{}}}', @@ -129,3 +130,14 @@ def test_error_is_rasied_on_invalid_json(self: Self, cli_runner: CliRunner) -> N json_error_message = invalid_query_format.format(value="@", exc="") assert json_error_message in result.output assert result.exit_code == usage_error_code + + def test_cli_version_check(self: Self, cli_runner: CliRunner) -> None: + """Test version is printed correctly.""" + result = cli_runner.invoke( + cli, + ["-v"], + catch_exceptions=False, + ) + version_message = cli_version.format(__version__=__version__) + assert version_message == result.output.strip() + assert result.exit_code == 0