| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import TYPE_CHECKING |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from commitizen.providers import get_provider |
| 8 |
from commitizen.providers.uv_provider import UvProvider |
| 9 |
|
| 10 |
if TYPE_CHECKING: |
| 11 |
from pytest_regressions.file_regression import FileRegressionFixture |
| 12 |
|
| 13 |
from commitizen.config.base_config import BaseConfig |
| 14 |
|
| 15 |
|
| 16 |
PYPROJECT_TOML = """ |
| 17 |
[project] |
| 18 |
name = "test-uv" |
| 19 |
version = "4.2.1" |
| 20 |
description = "Add your description here" |
| 21 |
readme = "README.md" |
| 22 |
requires-python = ">=3.13" |
| 23 |
dependencies = ["commitizen==4.2.1"] |
| 24 |
""" |
| 25 |
|
| 26 |
PYPROJECT_TOML_UNDERSCORE = """ |
| 27 |
[project] |
| 28 |
name = "test_uv" |
| 29 |
version = "4.2.1" |
| 30 |
description = "Add your description here" |
| 31 |
readme = "README.md" |
| 32 |
requires-python = ">=3.13" |
| 33 |
dependencies = ["commitizen==4.2.1"] |
| 34 |
""" |
| 35 |
|
| 36 |
UV_LOCK_SIMPLIFIED = """ |
| 37 |
version = 1 |
| 38 |
revision = 1 |
| 39 |
requires-python = ">=3.13" |
| 40 |
|
| 41 |
[[package]] |
| 42 |
name = "commitizen" |
| 43 |
version = "4.2.1" |
| 44 |
source = { registry = "https://pypi.org/simple" } |
| 45 |
dependencies = [ |
| 46 |
{ name = "argcomplete" }, |
| 47 |
{ name = "charset-normalizer" }, |
| 48 |
{ name = "colorama" }, |
| 49 |
{ name = "decli" }, |
| 50 |
{ name = "jinja2" }, |
| 51 |
{ name = "packaging" }, |
| 52 |
{ name = "pyyaml" }, |
| 53 |
{ name = "questionary" }, |
| 54 |
{ name = "termcolor" }, |
| 55 |
{ name = "tomlkit" }, |
| 56 |
] |
| 57 |
sdist = { url = "https://files.pythonhosted.org/packages/d8/a3/77ffc9aee014cbf46c84c9f156a1ddef2d4c7cfb87d567decf2541464245/commitizen-4.2.1.tar.gz", hash = "sha256:5255416f6d6071068159f0b97605777f3e25d00927ff157b7a8d01efeda7b952", size = 50645 } |
| 58 |
wheels = [ |
| 59 |
{ url = "https://files.pythonhosted.org/packages/57/ce/2f5d8ebe8376991b5f805e9f33d20c7f4c9ca6155bdbda761117dc41dff1/commitizen-4.2.1-py3-none-any.whl", hash = "sha256:a347889e0fe408c3b920a34130d8f35616be3ea8ac6b7b20c5b9aac19762661b", size = 72646 }, |
| 60 |
] |
| 61 |
|
| 62 |
[[package]] |
| 63 |
name = "decli" |
| 64 |
version = "0.6.2" |
| 65 |
source = { registry = "https://pypi.org/simple" } |
| 66 |
sdist = { url = "https://files.pythonhosted.org/packages/3d/a0/a4658f93ecb589f479037b164dc13c68d108b50bf6594e54c820749f97ac/decli-0.6.2.tar.gz", hash = "sha256:36f71eb55fd0093895efb4f416ec32b7f6e00147dda448e3365cf73ceab42d6f", size = 7424 } |
| 67 |
wheels = [ |
| 68 |
{ url = "https://files.pythonhosted.org/packages/bf/70/3ea48dc9e958d7d66c44c9944809181f1ca79aaef25703c023b5092d34ff/decli-0.6.2-py3-none-any.whl", hash = "sha256:2fc84106ce9a8f523ed501ca543bdb7e416c064917c12a59ebdc7f311a97b7ed", size = 7854 }, |
| 69 |
] |
| 70 |
|
| 71 |
[[package]] |
| 72 |
name = "test-uv" |
| 73 |
version = "4.2.1" |
| 74 |
source = { virtual = "." } |
| 75 |
dependencies = [ |
| 76 |
{ name = "commitizen" }, |
| 77 |
] |
| 78 |
""" |
| 79 |
|
| 80 |
|
| 81 |
@pytest.mark.parametrize( |
| 82 |
"pyproject_content", |
| 83 |
[ |
| 84 |
pytest.param(PYPROJECT_TOML, id="hyphenated"), |
| 85 |
pytest.param(PYPROJECT_TOML_UNDERSCORE, id="underscore"), |
| 86 |
], |
| 87 |
) |
| 88 |
def test_uv_provider( |
| 89 |
config: BaseConfig, |
| 90 |
tmp_path, |
| 91 |
monkeypatch, |
| 92 |
file_regression: FileRegressionFixture, |
| 93 |
pyproject_content: str, |
| 94 |
): |
| 95 |
monkeypatch.chdir(tmp_path) |
| 96 |
pyproject_toml_file = tmp_path / UvProvider.filename |
| 97 |
pyproject_toml_file.write_text(pyproject_content, encoding="utf-8") |
| 98 |
|
| 99 |
uv_lock_file = tmp_path / UvProvider.lock_filename |
| 100 |
uv_lock_file.write_text(UV_LOCK_SIMPLIFIED, encoding="utf-8") |
| 101 |
|
| 102 |
config.settings["version_provider"] = "uv" |
| 103 |
|
| 104 |
provider = get_provider(config) |
| 105 |
assert isinstance(provider, UvProvider) |
| 106 |
assert provider.get_version() == "4.2.1" |
| 107 |
|
| 108 |
provider.set_version("100.100.100") |
| 109 |
assert provider.get_version() == "100.100.100" |
| 110 |
|
| 111 |
updated_pyproject_toml_content = pyproject_toml_file.read_text(encoding="utf-8") |
| 112 |
updated_uv_lock_content = uv_lock_file.read_text(encoding="utf-8") |
| 113 |
|
| 114 |
for content in (updated_pyproject_toml_content, updated_uv_lock_content): |
| 115 |
# updated project version |
| 116 |
assert "100.100.100" in content |
| 117 |
# commitizen version which was the same as project version and should not be affected |
| 118 |
assert "4.2.1" in content |
| 119 |
|
| 120 |
file_regression.check(updated_pyproject_toml_content, extension=".toml") |
| 121 |
file_regression.check(updated_uv_lock_content, extension=".lock") |