Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cookiecutter_python/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import sys
import typing as t

import click

Expand All @@ -17,10 +18,10 @@

def version_msg():
"""Message about Python Generator version, location and Python version."""
python_version = sys.version[:3]
python_version: t.Tuple[int, int, int] = sys.version_info[:3]
message = u'Python Generator %(version)s from {} (Python {})'
location = os.path.dirname(this_file_location)
return message.format(location, python_version)
return message.format(location, ".".join(map(str, python_version)))


@click.command(context_settings=dict(help_option_names=[u'-h', u'--help']))
Expand Down
1 change: 1 addition & 0 deletions tests/test_build_backend_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def sdist_expected_correct_file_structure():
# 'src/stubs/requests_futures/sessions.pyi',
)
TESTS = (
'tests/test_version_string.py',
'tests/test_git_sdk.py',
'tests/test_git_porcelain.py',
'tests/test_is_repo_clean_function.py',
Expand Down
50 changes: 50 additions & 0 deletions tests/test_version_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from pathlib import Path

import pytest


def test_version_msg_function_returns_expected_string(distro_loc: Path):
# GIVEN the version_msg function
from cookiecutter_python.cli import version_msg

# WHEN the version_msg function is called
result: str = version_msg()

# THEN it should return the expected string
import sys

EXPECTED_PYTHON_VERSION: str = ".".join(map(str, sys.version_info[:3]))

EXPECTED_PARENT_DIR_OF_COOKIECUTTER_PYTHON: Path = distro_loc.parent

assert result == (
f'Python Generator %(version)s from {EXPECTED_PARENT_DIR_OF_COOKIECUTTER_PYTHON} (Python {EXPECTED_PYTHON_VERSION})'
)


@pytest.mark.runner_setup(mix_stderr=False)
def test_cli_version_flag_returns_expected_string(
distro_loc: Path,
isolated_cli_runner,
):
from cookiecutter_python import __version__
from cookiecutter_python.cli import main

result = isolated_cli_runner.invoke(
main,
args=['--version'],
input=None,
env=None,
catch_exceptions=False,
)
assert result.exit_code == 0

import sys

EXPECTED_PYTHON_VERSION: str = ".".join(map(str, sys.version_info[:3]))

EXPECTED_PARENT_DIR_OF_COOKIECUTTER_PYTHON: Path = distro_loc.parent

assert result.stdout == (
f'Python Generator {__version__} from {EXPECTED_PARENT_DIR_OF_COOKIECUTTER_PYTHON} (Python {EXPECTED_PYTHON_VERSION})\n'
)
Loading