Skip to content

Commit

Permalink
✅ Test version getting printed
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbadyal committed Sep 23, 2023
1 parent bdf00cf commit 93248c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/esxport_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()


Expand Down
1 change: 1 addition & 0 deletions src/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}"
14 changes: 13 additions & 1 deletion test/click/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":{}}}',
Expand Down Expand Up @@ -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

0 comments on commit 93248c6

Please sign in to comment.