8
8
config = {"name" : defaults .name }
9
9
10
10
11
+ @pytest .fixture
12
+ def staging_is_clean (mocker ):
13
+ is_staging_clean_mock = mocker .patch ("commitizen.git.is_staging_clean" )
14
+ is_staging_clean_mock .return_value = False
15
+
16
+
17
+ @pytest .mark .usefixtures ("staging_is_clean" )
11
18
def test_commit (mocker ):
12
19
prompt_mock = mocker .patch ("questionary.prompt" )
13
20
prompt_mock .return_value = {
@@ -27,6 +34,7 @@ def test_commit(mocker):
27
34
success_mock .assert_called_once ()
28
35
29
36
37
+ @pytest .mark .usefixtures ("staging_is_clean" )
30
38
def test_commit_retry_fails_no_backup (mocker ):
31
39
commit_mock = mocker .patch ("commitizen.git.commit" )
32
40
commit_mock .return_value = cmd .Command ("success" , "" , "" , "" )
@@ -35,6 +43,7 @@ def test_commit_retry_fails_no_backup(mocker):
35
43
commands .Commit (config , {"retry" : True })()
36
44
37
45
46
+ @pytest .mark .usefixtures ("staging_is_clean" )
38
47
def test_commit_retry_works (mocker ):
39
48
prompt_mock = mocker .patch ("questionary.prompt" )
40
49
prompt_mock .return_value = {
@@ -72,6 +81,17 @@ def test_commit_retry_works(mocker):
72
81
assert not os .path .isfile (temp_file )
73
82
74
83
84
+ def test_commit_when_nothing_to_commit (mocker ):
85
+ is_staging_clean_mock = mocker .patch ("commitizen.git.is_staging_clean" )
86
+ is_staging_clean_mock .return_value = True
87
+
88
+ with pytest .raises (SystemExit ) as err :
89
+ commit_cmd = commands .Commit (config , {})
90
+ commit_cmd ()
91
+
92
+ assert err .value .code == commands .commit .NOTHING_TO_COMMIT
93
+
94
+
75
95
def test_example ():
76
96
with mock .patch ("commitizen.out.write" ) as write_mock :
77
97
commands .Example (config )()
0 commit comments