-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy pathtest_project_info.py
More file actions
91 lines (77 loc) · 2.36 KB
/
test_project_info.py
File metadata and controls
91 lines (77 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Tests for project_info module."""
from __future__ import annotations
from pathlib import Path
import pytest
from commitizen import project_info
def _create_project_files(files: dict[str, str | None]) -> None:
for file_path, content in files.items():
path = Path(file_path)
if content is None:
path.touch()
else:
path.write_text(content)
@pytest.mark.parametrize(
("which_return", "expected"),
[
("/usr/local/bin/pre-commit", True),
("/usr/local/bin/prek", True),
(None, False),
("", False),
],
)
def test_is_pre_commit_installed(mocker, which_return, expected):
mocker.patch("shutil.which", return_value=which_return)
assert project_info.is_pre_commit_installed() is expected
@pytest.mark.parametrize(
("files", "expected"),
[
(
{"pyproject.toml": '[tool.poetry]\nname = "test"\nversion = "0.1.0"'},
"poetry",
),
({"pyproject.toml": "", "uv.lock": ""}, "uv"),
(
{"pyproject.toml": '[tool.commitizen]\nversion = "0.1.0"'},
"pep621",
),
({"setup.py": ""}, "pep621"),
({"Cargo.toml": ""}, "cargo"),
({"package.json": ""}, "npm"),
({"composer.json": ""}, "composer"),
({}, "commitizen"),
(
{
"pyproject.toml": "",
"Cargo.toml": "",
"package.json": "",
"composer.json": "",
},
"pep621",
),
],
)
def test_get_default_version_provider(chdir, files, expected):
_create_project_files(files)
assert project_info.get_default_version_provider() == expected
@pytest.mark.parametrize(
("files", "expected"),
[
({"pyproject.toml": ""}, "pyproject.toml"),
({}, ".cz.toml"),
],
)
def test_get_default_config_filename(chdir, files, expected):
_create_project_files(files)
assert project_info.get_default_config_filename() == expected
@pytest.mark.parametrize(
("files", "expected"),
[
({"pyproject.toml": ""}, "pep440"),
({"setup.py": ""}, "pep440"),
({"package.json": ""}, "semver2"),
({}, "semver2"),
],
)
def test_get_default_version_scheme(chdir, files, expected):
_create_project_files(files)
assert project_info.get_default_version_scheme() == expected