5
5
6
6
import pytest
7
7
8
- from salt .exceptions import CommandExecutionError
9
-
10
8
pytestmark = [
11
9
pytest .mark .slow_test ,
12
10
pytest .mark .destructive_test ,
@@ -34,8 +32,8 @@ def del_pkg():
34
32
yield "acme"
35
33
36
34
37
- @pytest .fixture (scope = "function" )
38
- def setup_teardown_vars (pkg , add_pkg , del_pkg ):
35
+ @pytest .fixture (scope = "function" , autouse = True )
36
+ def _setup_teardown_vars (pkg , add_pkg , del_pkg ):
39
37
try :
40
38
yield
41
39
finally :
@@ -48,147 +46,101 @@ def setup_teardown_vars(pkg, add_pkg, del_pkg):
48
46
pkg .remove (del_pkg )
49
47
50
48
51
- def test_brew_install (pkg , add_pkg , setup_teardown_vars ):
49
+ def test_brew_install (pkg , add_pkg ):
52
50
"""
53
51
Tests the installation of packages
54
52
"""
55
- try :
56
- pkg .install (add_pkg )
57
- pkg_list = pkg .list_pkgs ()
58
- try :
59
- assert add_pkg in pkg_list
60
- except AssertionError :
61
- pkg .remove (add_pkg )
62
- raise
63
- except CommandExecutionError :
64
- pkg .remove (add_pkg )
65
- raise
53
+ pkg .install (add_pkg )
54
+ pkg_list = pkg .list_pkgs ()
55
+ assert add_pkg in pkg_list
66
56
67
57
68
- def test_remove (pkg , del_pkg , setup_teardown_vars ):
58
+ def test_remove (pkg , del_pkg ):
69
59
"""
70
60
Tests the removal of packages
71
61
"""
72
- try :
73
- # Install a package to delete - If unsuccessful, skip the test
62
+ # Install a package to delete - If unsuccessful, skip the test
63
+ pkg .install (del_pkg )
64
+ pkg_list = pkg .list_pkgs ()
65
+ if del_pkg not in pkg_list :
74
66
pkg .install (del_pkg )
75
- pkg_list = pkg .list_pkgs ()
76
- if del_pkg not in pkg_list :
77
- pkg .install (del_pkg )
78
- pytest .skip ("Failed to install a package to delete" )
67
+ pytest .skip ("Failed to install a package to delete" )
79
68
80
- # Now remove the installed package
81
- pkg .remove (del_pkg )
82
- del_list = pkg .list_pkgs ()
83
- assert del_pkg not in del_list
84
- except CommandExecutionError :
85
- pkg .remove (del_pkg )
86
- raise
69
+ # Now remove the installed package
70
+ pkg .remove (del_pkg )
71
+ del_list = pkg .list_pkgs ()
72
+ assert del_pkg not in del_list
87
73
88
74
89
- def test_version (pkg , add_pkg , setup_teardown_vars ):
75
+ def test_version (pkg , add_pkg ):
90
76
"""
91
77
Test pkg.version for mac. Installs a package and then checks we can get
92
78
a version for the installed package.
93
79
"""
94
- try :
95
- pkg .install (add_pkg )
96
- pkg_list = pkg .list_pkgs ()
97
- version = pkg .version (add_pkg )
98
- try :
99
- assert version , "version: {} is empty, or other issue is present" .format (
100
- version
101
- )
102
- assert (
103
- add_pkg in pkg_list
104
- ), "package: {} is not in the list of installed packages: {}" .format (
105
- add_pkg , pkg_list
106
- )
107
- # make sure the version is accurate and is listed in the pkg_list
108
- assert version in str (
109
- pkg_list [add_pkg ]
110
- ), "The {} version: {} is not listed in the pkg_list: {}" .format (
111
- add_pkg , version , pkg_list [add_pkg ]
112
- )
113
- except AssertionError :
114
- pkg .remove (add_pkg )
115
- raise
116
- except CommandExecutionError :
117
- pkg .remove (add_pkg )
118
- raise
119
-
120
-
121
- def test_latest_version (pkg , add_pkg , setup_teardown_vars ):
80
+ pkg .install (add_pkg )
81
+ pkg_list = pkg .list_pkgs ()
82
+ version = pkg .version (add_pkg )
83
+ assert version , f"version: { version } is empty, or other issue is present"
84
+ assert (
85
+ add_pkg in pkg_list
86
+ ), "package: {} is not in the list of installed packages: {}" .format (
87
+ add_pkg , pkg_list
88
+ )
89
+ # make sure the version is accurate and is listed in the pkg_list
90
+ assert version in str (
91
+ pkg_list [add_pkg ]
92
+ ), "The {} version: {} is not listed in the pkg_list: {}" .format (
93
+ add_pkg , version , pkg_list [add_pkg ]
94
+ )
95
+
96
+
97
+ def test_latest_version (pkg , add_pkg ):
122
98
"""
123
99
Test pkg.latest_version:
124
100
- get the latest version available
125
101
- install the package
126
102
- get the latest version available
127
103
- check that the latest version is empty after installing it
128
104
"""
129
- try :
130
- pkg .remove (add_pkg )
131
- uninstalled_latest = pkg .latest_version (add_pkg )
132
-
133
- pkg .install (add_pkg )
134
- installed_latest = pkg .latest_version (add_pkg )
135
- version = pkg .version (add_pkg )
136
- try :
137
- assert isinstance (uninstalled_latest , str )
138
- assert installed_latest == version
139
- except AssertionError :
140
- pkg .remove (add_pkg )
141
- raise
142
- except CommandExecutionError :
143
- pkg .remove (add_pkg )
144
- raise
105
+ pkg .remove (add_pkg )
106
+ uninstalled_latest = pkg .latest_version (add_pkg )
107
+
108
+ pkg .install (add_pkg )
109
+ installed_latest = pkg .latest_version (add_pkg )
110
+ version = pkg .version (add_pkg )
111
+ assert isinstance (uninstalled_latest , str )
112
+ assert installed_latest == version
145
113
146
114
147
- def test_refresh_db (pkg , setup_teardown_vars ):
115
+ def test_refresh_db (pkg ):
148
116
"""
149
117
Integration test to ensure pkg.refresh_db works with brew
150
118
"""
151
119
refresh_brew = pkg .refresh_db ()
152
120
assert refresh_brew
153
121
154
122
155
- def test_list_upgrades (pkg , add_pkg , setup_teardown_vars ):
123
+ def test_list_upgrades (pkg , add_pkg ):
156
124
"""
157
125
Test pkg.list_upgrades: data is in the form {'name1': 'version1',
158
126
'name2': 'version2', ... }
159
127
"""
160
- try :
161
- upgrades = pkg .list_upgrades ()
162
- try :
163
- assert isinstance (upgrades , dict )
164
- if upgrades :
165
- for name in upgrades :
166
- assert isinstance (name , str )
167
- assert isinstance (upgrades [name ], str )
168
- except AssertionError :
169
- pkg .remove (add_pkg )
170
- raise
171
- except CommandExecutionError :
172
- pkg .remove (add_pkg )
173
- raise
128
+ upgrades = pkg .list_upgrades ()
129
+ assert isinstance (upgrades , dict )
130
+ if upgrades :
131
+ for name in upgrades :
132
+ assert isinstance (name , str )
133
+ assert isinstance (upgrades [name ], str )
174
134
175
135
176
- def test_info_installed (pkg , add_pkg , setup_teardown_vars ):
136
+ def test_info_installed (pkg , add_pkg ):
177
137
"""
178
138
Test pkg.info_installed: info returned has certain fields used by
179
139
mac_brew.latest_version
180
140
"""
181
- try :
182
- pkg .install (add_pkg )
183
- info = pkg .info_installed (add_pkg )
184
- try :
185
- assert add_pkg in info
186
- assert "versions" in info [add_pkg ]
187
- assert "revision" in info [add_pkg ]
188
- assert "stable" in info [add_pkg ]["versions" ]
189
- except AssertionError :
190
- pkg .remove (add_pkg )
191
- raise
192
- except CommandExecutionError :
193
- pkg .remove (add_pkg )
194
- raise
141
+ pkg .install (add_pkg )
142
+ info = pkg .info_installed (add_pkg )
143
+ assert add_pkg in info
144
+ assert "versions" in info [add_pkg ]
145
+ assert "revision" in info [add_pkg ]
146
+ assert "stable" in info [add_pkg ]["versions" ]
0 commit comments