File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
from commitizen import commands
2
2
3
3
4
+ class FakeQuestion :
5
+ def __init__ (self , expected_return ):
6
+ self .expected_return = expected_return
7
+
8
+ def ask (self ):
9
+ return self .expected_return
10
+
11
+
12
+ def test_init (tmpdir , mocker , config ):
13
+ mocker .patch (
14
+ "questionary.select" ,
15
+ side_effect = [
16
+ FakeQuestion ("pyproject.toml" ),
17
+ FakeQuestion ("cz_conventional_commits" ),
18
+ ],
19
+ )
20
+ mocker .patch ("questionary.confirm" , return_value = FakeQuestion ("y" ))
21
+ mocker .patch ("questionary.text" , return_value = FakeQuestion ("y" ))
22
+ expected_config = (
23
+ "[tool.commitizen]\n "
24
+ 'name = "cz_conventional_commits"\n '
25
+ 'version = "0.0.1"\n '
26
+ 'tag_format = "y"\n '
27
+ )
28
+
29
+ with tmpdir .as_cwd ():
30
+ commands .Init (config )()
31
+
32
+ with open ("pyproject.toml" , "r" ) as toml_file :
33
+ config_data = toml_file .read ()
34
+
35
+ assert config_data == expected_config
36
+
37
+
4
38
def test_init_when_config_already_exists (config , capsys ):
5
39
# Set config path
6
40
path = "tests/pyproject.toml"
You can’t perform that action at this time.
0 commit comments