From 8de299ebe5e97ecd909a059d3fcd2bc8ce862bdc Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sat, 11 Dec 2021 22:00:06 +0530 Subject: [PATCH 1/6] Get python version from version_info tuple Co-authored-by: Sahil --- cookiecutter/cli.py | 2 +- tests/test_cli.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cookiecutter/cli.py b/cookiecutter/cli.py index 84241ac2a..6ce8f0ada 100644 --- a/cookiecutter/cli.py +++ b/cookiecutter/cli.py @@ -25,7 +25,7 @@ def version_msg(): """Return the Cookiecutter version, location and Python powering it.""" - python_version = sys.version[:3] + python_version = str(sys.version_info[0]) + '.' + str(sys.version_info[1]) location = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) message = 'Cookiecutter %(version)s from {} (Python {})' return message.format(location, python_version) diff --git a/tests/test_cli.py b/tests/test_cli.py index 623945e8b..b5c8d3c78 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -53,6 +53,8 @@ def test_cli_version(cli_runner, version_cli_flag): assert result.exit_code == 0 assert result.output.startswith('Cookiecutter') +def test_version_msg(): + print("to do") @pytest.mark.usefixtures('make_fake_project_dir', 'remove_fake_project_dir') def test_cli_error_on_existing_output_directory(cli_runner): From b1403ead3bcac644eb2619642dee4b325f7b8b08 Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sun, 12 Dec 2021 13:18:30 +0530 Subject: [PATCH 2/6] Added test for version_msg Co-authored-by: Sahil --- .github/workflows/main.yml | 5 +++++ tests/test_cli.py | 22 ++++++++++++++++++++-- tox.ini | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 436de42a6..b4e49ae73 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,6 +37,7 @@ jobs: - "ubuntu-py37" - "ubuntu-py38" - "ubuntu-py39" + - "ubuntu-py310" - "macos-py37" - "macos-py38" @@ -59,6 +60,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" diff --git a/tests/test_cli.py b/tests/test_cli.py index b5c8d3c78..12ca5f5bb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,6 +4,9 @@ import os import re +import sys + + import pytest from click.testing import CliRunner @@ -53,8 +56,23 @@ def test_cli_version(cli_runner, version_cli_flag): assert result.exit_code == 0 assert result.output.startswith('Cookiecutter') -def test_version_msg(): - print("to do") + +def test_version_msg(cli_runner, version_cli_flag): + """Verify correct output for Cookiecutter Python version.""" + 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:] + if version_output_string[-1] == ')': + version_output_string = version_output_string[:-1] + assert ( + str(python_major_number) + '.' + str(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): diff --git a/tox.ini b/tox.ini index 591fc50ee..b8dd5c5e1 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ envlist = py37 py38 py39 + py310 minversion = 3.14.2 requires = virtualenv >= 20.4.5 From e5e0e96a0212219e9b80210f85b464b6226c83bc Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sun, 12 Dec 2021 22:21:56 +0530 Subject: [PATCH 3/6] Use f strings and add Python 3.10 CI environments Co-authored-by: Sahil --- .github/workflows/main.yml | 10 ++++++++++ cookiecutter/cli.py | 2 +- tests/test_cli.py | 13 ++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b4e49ae73..12dce4e24 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,10 +42,12 @@ jobs: - "macos-py37" - "macos-py38" - "macos-py39" + - "macos-py310" - "windows-py37" - "windows-py38" - "windows-py39" + - "windows-py310" include: - name: "ubuntu-py37" @@ -77,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" @@ -90,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 diff --git a/cookiecutter/cli.py b/cookiecutter/cli.py index 6ce8f0ada..385e024c5 100644 --- a/cookiecutter/cli.py +++ b/cookiecutter/cli.py @@ -25,7 +25,7 @@ def version_msg(): """Return the Cookiecutter version, location and Python powering it.""" - python_version = str(sys.version_info[0]) + '.' + str(sys.version_info[1]) + python_version = f'{sys.version_info.major}.{sys.version_info.minor}' location = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) message = 'Cookiecutter %(version)s from {} (Python {})' return message.format(location, python_version) diff --git a/tests/test_cli.py b/tests/test_cli.py index 12ca5f5bb..180314373 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -51,14 +51,14 @@ 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_version_msg(cli_runner, version_cli_flag): - """Verify correct output for Cookiecutter Python version.""" +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 @@ -66,12 +66,7 @@ def test_version_msg(cli_runner, version_cli_flag): version_output_string = version_output_string[-5:-1] if version_output_string[0] == ' ': version_output_string = version_output_string[1:] - if version_output_string[-1] == ')': - version_output_string = version_output_string[:-1] - assert ( - str(python_major_number) + '.' + str(python_minor_number) - == version_output_string - ) + assert f'{python_major_number}.{python_minor_number}' == version_output_string @pytest.mark.usefixtures('make_fake_project_dir', 'remove_fake_project_dir') From 8a7a6f51688940a67c397de0396d51a696dbcece Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sat, 18 Dec 2021 22:56:09 +0530 Subject: [PATCH 4/6] Prints the whole sys.version string Co-authored-by: Sahil --- cookiecutter/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookiecutter/cli.py b/cookiecutter/cli.py index 385e024c5..6b3c583ad 100644 --- a/cookiecutter/cli.py +++ b/cookiecutter/cli.py @@ -25,7 +25,7 @@ def version_msg(): """Return the Cookiecutter version, location and Python powering it.""" - python_version = f'{sys.version_info.major}.{sys.version_info.minor}' + python_version = sys.version location = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) message = 'Cookiecutter %(version)s from {} (Python {})' return message.format(location, python_version) From cfef5740e47ec5be22be6edb51b4d919a5a724ad Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sat, 18 Dec 2021 23:11:23 +0530 Subject: [PATCH 5/6] Removed python_version_test Co-authored-by: Sahil --- tests/test_cli.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 180314373..6bf093522 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -57,18 +57,6 @@ def test_cli_version(cli_runner, version_cli_flag): 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.""" From 11743af681e37a998748f69d646661b7a2043ff0 Mon Sep 17 00:00:00 2001 From: Prathamesh Desai Date: Sat, 18 Dec 2021 23:17:36 +0530 Subject: [PATCH 6/6] Fixed linting errors Co-authored-by: Sahil --- tests/test_cli.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 6bf093522..19740ef26 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,8 +4,6 @@ import os import re -import sys - import pytest from click.testing import CliRunner