11from subprocess import CalledProcessError
22from unittest .mock import (
33 MagicMock ,
4- patch , call ,
4+ call ,
5+ patch ,
56)
67
78import pytest
89
10+ import noxconfig
911from exasol .toolbox .nox ._release import (
1012 ReleaseError ,
1113 _trigger_release ,
1214)
1315from exasol .toolbox .util .version import Version
14- import noxconfig
1516
1617
1718@pytest .fixture (scope = "class" )
1819def mock_from_poetry ():
1920 with patch (
20- "exasol.toolbox.nox._release.Version.from_poetry" , return_value = Version (major = 0 ,minor = 3 ,patch = 0 )
21+ "exasol.toolbox.nox._release.Version.from_poetry" ,
22+ return_value = Version (major = 0 , minor = 3 , patch = 0 ),
2123 ) as mock_obj :
2224 yield mock_obj
2325
@@ -42,28 +44,64 @@ def simulate_pass(args, **kwargs):
4244 result = _trigger_release ()
4345 assert result == mock_from_poetry .return_value
4446
45-
4647 def test_creates_major_version_tag (self , mock_from_poetry ):
4748 def simulate_pass (args , ** kwargs ):
4849 return self ._get_subprocess_run_mock (args )
4950
5051 with patch ("subprocess.run" , side_effect = simulate_pass ) as subprocess_mock :
5152 result = _trigger_release ()
52- assert subprocess_mock .mock_calls == [call (('git' , 'remote' , 'show' , 'origin' ), capture_output = True , text = True , check = True ),
53- call (('git' , 'checkout' , 'main' ), capture_output = True , text = True , check = True ),
54- call (('git' , 'pull' ), capture_output = True , text = True , check = True ),
55- call (('git' , 'tag' , '--list' ), capture_output = True , text = True , check = True ),
56- call (('gh' , 'release' , 'list' ), capture_output = True , text = True , check = True ),
57- call (('git' , 'tag' , '0.3.0' ), capture_output = True , text = True , check = True ),
58- call (('git' , 'push' , 'origin' , '0.3.0' ), capture_output = True , text = True , check = True ),
59- call (('git' , 'tag' , '-f' , 'v0' ), capture_output = True , text = True , check = True ),
60- call (('git' , 'push' , '-f' , 'origin' , 'v0' ), capture_output = True , text = True , check = True )]
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+ ),
97+ ]
6198 assert result == mock_from_poetry .return_value
6299
63100 @pytest .fixture
64101 def mock_project_config (self , monkeypatch ):
65102 class DummyConfig :
66103 pass
104+
67105 monkeypatch .setattr (noxconfig , "PROJECT_CONFIG" , DummyConfig ())
68106
69107 def test_not_creates_major_version_tag (self , mock_from_poetry , mock_project_config ):
@@ -72,13 +110,39 @@ def simulate_pass(args, **kwargs):
72110
73111 with patch ("subprocess.run" , side_effect = simulate_pass ) as subprocess_mock :
74112 result = _trigger_release ()
75- assert subprocess_mock .mock_calls == [call (('git' , 'remote' , 'show' , 'origin' ), capture_output = True , text = True , check = True ),
76- call (('git' , 'checkout' , 'main' ), capture_output = True , text = True , check = True ),
77- call (('git' , 'pull' ), capture_output = True , text = True , check = True ),
78- call (('git' , 'tag' , '--list' ), capture_output = True , text = True , check = True ),
79- call (('gh' , 'release' , 'list' ), capture_output = True , text = True , check = True ),
80- call (('git' , 'tag' , '0.3.0' ), capture_output = True , text = True , check = True ),
81- call (('git' , 'push' , 'origin' , '0.3.0' ), capture_output = True , text = True , check = True )]
113+ assert subprocess_mock .mock_calls == [
114+ call (
115+ ("git" , "remote" , "show" , "origin" ),
116+ capture_output = True ,
117+ text = True ,
118+ check = True ,
119+ ),
120+ call (
121+ ("git" , "checkout" , "main" ),
122+ capture_output = True ,
123+ text = True ,
124+ check = True ,
125+ ),
126+ call (("git" , "pull" ), capture_output = True , text = True , check = True ),
127+ call (
128+ ("git" , "tag" , "--list" ), capture_output = True , text = True , check = True
129+ ),
130+ call (
131+ ("gh" , "release" , "list" ),
132+ capture_output = True ,
133+ text = True ,
134+ check = True ,
135+ ),
136+ call (
137+ ("git" , "tag" , "0.3.0" ), capture_output = True , text = True , check = True
138+ ),
139+ call (
140+ ("git" , "push" , "origin" , "0.3.0" ),
141+ capture_output = True ,
142+ text = True ,
143+ check = True ,
144+ ),
145+ ]
82146 assert result == mock_from_poetry .return_value
83147
84148 @pytest .mark .parametrize (
0 commit comments