@@ -29,7 +29,7 @@ class TestTriggerReleaseWithMocking:
2929 def _get_mock_string (args ) -> str :
3030 if args == ("git" , "remote" , "show" , "origin" ):
3131 return "test\n HEAD branch: main\n test"
32- if args in [ ("git" , "tag" , "--list" ), ( "gh" , "release" , "list" )] :
32+ if args == ("git" , "tag" , "--list" ):
3333 return "0.1.0\n 0.2.0"
3434 return ""
3535
@@ -50,50 +50,17 @@ def simulate_pass(args, **kwargs):
5050
5151 with patch ("subprocess.run" , side_effect = simulate_pass ) as subprocess_mock :
5252 result = _trigger_release (noxconfig .PROJECT_CONFIG )
53- assert subprocess_mock .mock_calls == [
54- call (
55- ("git" , "remote" , "show" , "origin" ),
56- capture_output = True ,
57- text = True ,
58- check = True ,
59- ),
60- call (
61- ("git" , "checkout" , "main" ),
62- capture_output = True ,
63- text = True ,
64- check = True ,
65- ),
66- call (("git" , "pull" ), capture_output = True , text = True , check = True ),
67- call (
68- ("git" , "tag" , "--list" ), capture_output = True , text = True , check = True
69- ),
70- call (
71- ("gh" , "release" , "list" ),
72- capture_output = True ,
73- text = True ,
74- check = True ,
75- ),
76- call (
77- ("git" , "tag" , "0.3.0" ), capture_output = True , text = True , check = True
78- ),
79- call (
80- ("git" , "push" , "origin" , "0.3.0" ),
81- capture_output = True ,
82- text = True ,
83- check = True ,
84- ),
85- call (
86- ("git" , "tag" , "-f" , "v0" ),
87- capture_output = True ,
88- text = True ,
89- check = True ,
90- ),
91- call (
92- ("git" , "push" , "-f" , "origin" , "v0" ),
93- capture_output = True ,
94- text = True ,
95- check = True ,
96- ),
53+ commands = [c .args [0 ] for c in subprocess_mock .mock_calls ]
54+ assert commands == [
55+ ("git" , "remote" , "show" , "origin" ),
56+ ("git" , "checkout" , "main" ),
57+ ("git" , "pull" ),
58+ ("git" , "fetch" , "--all" ),
59+ ("git" , "tag" , "--list" ),
60+ ("git" , "tag" , "0.3.0" ),
61+ ("git" , "push" , "origin" , "0.3.0" ),
62+ ("git" , "tag" , "-f" , "v0" ),
63+ ("git" , "push" , "-f" , "origin" , "v0" ),
9764 ]
9865 assert result == mock_from_poetry .return_value
9966
@@ -106,38 +73,15 @@ def simulate_pass(args, **kwargs):
10673
10774 with patch ("subprocess.run" , side_effect = simulate_pass ) as subprocess_mock :
10875 result = _trigger_release (DummyConfig )
109- assert subprocess_mock .mock_calls == [
110- call (
111- ("git" , "remote" , "show" , "origin" ),
112- capture_output = True ,
113- text = True ,
114- check = True ,
115- ),
116- call (
117- ("git" , "checkout" , "main" ),
118- capture_output = True ,
119- text = True ,
120- check = True ,
121- ),
122- call (("git" , "pull" ), capture_output = True , text = True , check = True ),
123- call (
124- ("git" , "tag" , "--list" ), capture_output = True , text = True , check = True
125- ),
126- call (
127- ("gh" , "release" , "list" ),
128- capture_output = True ,
129- text = True ,
130- check = True ,
131- ),
132- call (
133- ("git" , "tag" , "0.3.0" ), capture_output = True , text = True , check = True
134- ),
135- call (
136- ("git" , "push" , "origin" , "0.3.0" ),
137- capture_output = True ,
138- text = True ,
139- check = True ,
140- ),
76+ commands = [c .args [0 ] for c in subprocess_mock .mock_calls ]
77+ assert commands == [
78+ ("git" , "remote" , "show" , "origin" ),
79+ ("git" , "checkout" , "main" ),
80+ ("git" , "pull" ),
81+ ("git" , "fetch" , "--all" ),
82+ ("git" , "tag" , "--list" ),
83+ ("git" , "tag" , "0.3.0" ),
84+ ("git" , "push" , "origin" , "0.3.0" ),
14185 ]
14286 assert result == mock_from_poetry .return_value
14387
@@ -148,7 +92,6 @@ def simulate_pass(args, **kwargs):
14892 ("git" , "checkout" , "main" ),
14993 ("git" , "pull" ),
15094 ("git" , "tag" , "--list" ),
151- ("gh" , "release" , "list" ),
15295 ("git" , "tag" , "0.3.0" ),
15396 ("git" , "push" , "origin" , "0.3.0" ),
15497 ],
@@ -189,16 +132,3 @@ def simulate_fail(args, **kwargs):
189132 with pytest .raises (ReleaseError ) as ex :
190133 _trigger_release (noxconfig .PROJECT_CONFIG )
191134 assert f"tag { version } already exists" in str (ex )
192-
193- def test_release_already_exists (self , mock_from_poetry ):
194- version = mock_from_poetry .return_value
195-
196- def simulate_fail (args , ** kwargs ):
197- if args == ("gh" , "release" , "list" ):
198- return MagicMock (returncode = 0 , stdout = f"0.1.0\n 0.2.0\n { version } " )
199- return self ._get_subprocess_run_mock (args )
200-
201- with patch ("subprocess.run" , side_effect = simulate_fail ):
202- with pytest .raises (ReleaseError ) as ex :
203- _trigger_release (noxconfig .PROJECT_CONFIG )
204- assert f"release { version } already exists" in str (ex )
0 commit comments