Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python version number in cookiecutter --version and test on Python 3.10 #1621

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Expand Up @@ -37,14 +37,17 @@ jobs:
- "ubuntu-py37"
- "ubuntu-py38"
- "ubuntu-py39"
- "ubuntu-py310"

- "macos-py37"
- "macos-py38"
- "macos-py39"
- "macos-py310"

- "windows-py37"
- "windows-py38"
- "windows-py39"
- "windows-py310"

include:
- name: "ubuntu-py37"
Expand All @@ -59,6 +62,10 @@ jobs:
python: "3.9"
os: ubuntu-latest
tox_env: "py39"
- name: "ubuntu-py310"
python: "3.10"
os: ubuntu-latest
tox_env: "py310"

- name: "macos-py37"
python: "3.7"
Expand All @@ -72,6 +79,10 @@ jobs:
python: "3.9"
os: macos-latest
tox_env: "py39"
- name: "macos-py310"
python: "3.10"
os: macos-latest
tox_env: "py310"

- name: "windows-py37"
python: "3.7"
Expand All @@ -85,6 +96,10 @@ jobs:
python: "3.9"
os: windows-latest
tox_env: "py39"
- name: "windows-py310"
python: "3.10"
os: windows-latest
tox_env: "py310"

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter/cli.py
Expand Up @@ -25,7 +25,7 @@

def version_msg():
"""Return the Cookiecutter version, location and Python powering it."""
python_version = sys.version[:3]
python_version = f'{sys.version_info.major}.{sys.version_info.minor}'
michaeljoseph marked this conversation as resolved.
Show resolved Hide resolved
location = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
message = 'Cookiecutter %(version)s from {} (Python {})'
return message.format(location, python_version)
Expand Down
17 changes: 16 additions & 1 deletion tests/test_cli.py
Expand Up @@ -4,6 +4,9 @@
import os
import re

import sys


import pytest
from click.testing import CliRunner

Expand Down Expand Up @@ -48,12 +51,24 @@ def version_cli_flag(request):


def test_cli_version(cli_runner, version_cli_flag):
"""Verify correct version output by `cookiecutter` on cli invocation."""
"""Verify Cookiecutter version output by `cookiecutter` on cli invocation."""
result = cli_runner(version_cli_flag)
assert result.exit_code == 0
assert result.output.startswith('Cookiecutter')


def test_cli_version_python(cli_runner, version_cli_flag):
"""Verify correct Python version output by `cookiecutter` on cli invocation."""
result = cli_runner(version_cli_flag)
python_major_number = sys.version_info.major
python_minor_number = sys.version_info.minor
version_output_string = result.output[:-1]
version_output_string = version_output_string[-5:-1]
if version_output_string[0] == ' ':
version_output_string = version_output_string[1:]
assert f'{python_major_number}.{python_minor_number}' == version_output_string


@pytest.mark.usefixtures('make_fake_project_dir', 'remove_fake_project_dir')
def test_cli_error_on_existing_output_directory(cli_runner):
"""Test cli invocation without `overwrite-if-exists` fail if dir exist."""
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -4,6 +4,7 @@ envlist =
py37
py38
py39
py310
minversion = 3.14.2
requires =
virtualenv >= 20.4.5
Expand Down