Skip to content

Commit ebff792

Browse files
committed
test(providers/uv_provider): add test case test_uv_provider
1 parent 839d108 commit ebff792

File tree

5 files changed

+159
-11
lines changed

5 files changed

+159
-11
lines changed

Diff for: commitizen/providers/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from commitizen.providers.pep621_provider import Pep621Provider
1919
from commitizen.providers.poetry_provider import PoetryProvider
2020
from commitizen.providers.scm_provider import ScmProvider
21+
from commitizen.providers.uv_provider import UvProvider
2122

2223
__all__ = [
2324
"get_provider",
@@ -28,6 +29,7 @@
2829
"Pep621Provider",
2930
"PoetryProvider",
3031
"ScmProvider",
32+
"UvProvider",
3133
]
3234

3335
PROVIDER_ENTRYPOINT = "commitizen.provider"

Diff for: pyproject.toml

+10-11
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ npm = "commitizen.providers:NpmProvider"
7474
pep621 = "commitizen.providers:Pep621Provider"
7575
poetry = "commitizen.providers:PoetryProvider"
7676
scm = "commitizen.providers:ScmProvider"
77+
uv = "commitizen.providers:UvProvider"
7778

7879
[project.entry-points."commitizen.scheme"]
7980
pep440 = "commitizen.version_schemes:Pep440"
@@ -165,9 +166,7 @@ omit = [
165166

166167
[tool.pytest.ini_options]
167168
addopts = "--strict-markers"
168-
testpaths = [
169-
"tests/",
170-
]
169+
testpaths = ["tests/"]
171170

172171
[tool.tox]
173172
requires = ["tox>=4.22"]
@@ -178,7 +177,7 @@ description = "Run tests suite against Python {base_python}"
178177
skip_install = true
179178
deps = ["poetry>=2.0"]
180179
commands_pre = [["poetry", "install", "--only", "main,test"]]
181-
commands = [["pytest", { replace = "posargs", extend = true}]]
180+
commands = [["pytest", { replace = "posargs", extend = true }]]
182181

183182
[tool.ruff]
184183
line-length = 88
@@ -227,14 +226,14 @@ poetry_command = ""
227226
[tool.poe.tasks]
228227
format.help = "Format the code"
229228
format.sequence = [
230-
{cmd = "ruff check --fix commitizen tests"},
231-
{cmd = "ruff format commitizen tests"},
229+
{ cmd = "ruff check --fix commitizen tests" },
230+
{ cmd = "ruff format commitizen tests" },
232231
]
233232

234233
lint.help = "Lint the code"
235234
lint.sequence = [
236-
{cmd = "ruff check commitizen/ tests/ --fix"},
237-
{cmd = "mypy commitizen/ tests/"},
235+
{ cmd = "ruff check commitizen/ tests/ --fix" },
236+
{ cmd = "mypy commitizen/ tests/" },
238237
]
239238

240239
check-commit.help = "Check the commit message"
@@ -254,7 +253,7 @@ all.sequence = [
254253
"format",
255254
"lint",
256255
"cover",
257-
"check-commit"
256+
"check-commit",
258257
]
259258

260259
"doc:screenshots".help = "Render documentation screeenshots"
@@ -268,10 +267,10 @@ doc.cmd = "mkdocs serve"
268267

269268
ci.help = "Run all tasks in CI"
270269
ci.sequence = [
271-
{cmd="pre-commit run --all-files"},
270+
{ cmd = "pre-commit run --all-files" },
272271
"cover",
273272
]
274-
ci.env = {SKIP = "no-commit-to-branch"}
273+
ci.env = { SKIP = "no-commit-to-branch" }
275274

276275
setup-pre-commit.help = "Install pre-commit hooks"
277276
setup-pre-commit.cmd = "pre-commit install"

Diff for: tests/providers/test_uv_provider.py

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

0 commit comments

Comments
 (0)