Skip to content

Commit 38f5a7c

Browse files
committed
test(commands): added integration test for bump command
1 parent 57ced8d commit 38f5a7c

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/test_bump_command.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import os
2+
import shutil
3+
import pytest
4+
import sys
5+
from typing import Optional
6+
from pathlib import Path
7+
from commitizen import git, cmd, cli
8+
import uuid
9+
10+
11+
@pytest.fixture
12+
def create_project():
13+
current_directory = os.getcwd()
14+
tmp_proj_path = "tests/tmp-proj"
15+
full_tmp_path = os.path.join(current_directory, tmp_proj_path)
16+
if not os.path.exists(full_tmp_path):
17+
os.makedirs(full_tmp_path)
18+
os.chdir(full_tmp_path)
19+
yield
20+
os.chdir(current_directory)
21+
shutil.rmtree(full_tmp_path)
22+
23+
24+
def create_file_and_commit(message: str, filename: Optional[str] = None):
25+
if not filename:
26+
filename = str(uuid.uuid4())
27+
Path(f"./{filename}").touch()
28+
cmd.run("git add .")
29+
git.commit(message)
30+
31+
32+
def test_bump_command(mocker, create_project):
33+
with open("./pyproject.toml", "w") as f:
34+
f.write("[tool.commitizen]\n" 'version="0.1.0"')
35+
36+
cmd.run("git init")
37+
38+
# MINOR
39+
create_file_and_commit("feat: new file")
40+
41+
testargs = ["cz", "bump", "--yes"]
42+
mocker.patch.object(sys, "argv", testargs)
43+
cli.main()
44+
45+
tag_exists = git.tag_exist("0.2.0")
46+
assert tag_exists is True
47+
48+
# PATCH
49+
create_file_and_commit("fix: username exception")
50+
51+
testargs = ["cz", "bump"]
52+
mocker.patch.object(sys, "argv", testargs)
53+
cli.main()
54+
55+
tag_exists = git.tag_exist("0.2.1")
56+
assert tag_exists is True
57+
58+
# PRERELEASE
59+
create_file_and_commit("feat: location")
60+
61+
testargs = ["cz", "bump", "--prerelease", "alpha"]
62+
mocker.patch.object(sys, "argv", testargs)
63+
cli.main()
64+
65+
tag_exists = git.tag_exist("0.3.0a0")
66+
assert tag_exists is True
67+
68+
# PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE
69+
testargs = ["cz", "bump"]
70+
mocker.patch.object(sys, "argv", testargs)
71+
cli.main()
72+
73+
tag_exists = git.tag_exist("0.3.0")
74+
assert tag_exists is True
75+
76+
# MAJOR
77+
create_file_and_commit(
78+
"feat: new user interface\n\nBREAKING CHANGE: age is no longer supported"
79+
)
80+
81+
testargs = ["cz", "bump"]
82+
mocker.patch.object(sys, "argv", testargs)
83+
cli.main()
84+
85+
tag_exists = git.tag_exist("1.0.0")
86+
assert tag_exists is True

0 commit comments

Comments
 (0)