Skip to content

Commit 551bfcb

Browse files
garethgreenawaydwoz
authored andcommitted
suggested changes
1 parent 7cd8553 commit 551bfcb

File tree

1 file changed

+58
-106
lines changed

1 file changed

+58
-106
lines changed

tests/pytests/functional/modules/test_mac_brew_pkg.py

Lines changed: 58 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import pytest
77

8-
from salt.exceptions import CommandExecutionError
9-
108
pytestmark = [
119
pytest.mark.slow_test,
1210
pytest.mark.destructive_test,
@@ -34,8 +32,8 @@ def del_pkg():
3432
yield "acme"
3533

3634

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):
3937
try:
4038
yield
4139
finally:
@@ -48,147 +46,101 @@ def setup_teardown_vars(pkg, add_pkg, del_pkg):
4846
pkg.remove(del_pkg)
4947

5048

51-
def test_brew_install(pkg, add_pkg, setup_teardown_vars):
49+
def test_brew_install(pkg, add_pkg):
5250
"""
5351
Tests the installation of packages
5452
"""
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
6656

6757

68-
def test_remove(pkg, del_pkg, setup_teardown_vars):
58+
def test_remove(pkg, del_pkg):
6959
"""
7060
Tests the removal of packages
7161
"""
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:
7466
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")
7968

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
8773

8874

89-
def test_version(pkg, add_pkg, setup_teardown_vars):
75+
def test_version(pkg, add_pkg):
9076
"""
9177
Test pkg.version for mac. Installs a package and then checks we can get
9278
a version for the installed package.
9379
"""
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):
12298
"""
12399
Test pkg.latest_version:
124100
- get the latest version available
125101
- install the package
126102
- get the latest version available
127103
- check that the latest version is empty after installing it
128104
"""
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
145113

146114

147-
def test_refresh_db(pkg, setup_teardown_vars):
115+
def test_refresh_db(pkg):
148116
"""
149117
Integration test to ensure pkg.refresh_db works with brew
150118
"""
151119
refresh_brew = pkg.refresh_db()
152120
assert refresh_brew
153121

154122

155-
def test_list_upgrades(pkg, add_pkg, setup_teardown_vars):
123+
def test_list_upgrades(pkg, add_pkg):
156124
"""
157125
Test pkg.list_upgrades: data is in the form {'name1': 'version1',
158126
'name2': 'version2', ... }
159127
"""
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)
174134

175135

176-
def test_info_installed(pkg, add_pkg, setup_teardown_vars):
136+
def test_info_installed(pkg, add_pkg):
177137
"""
178138
Test pkg.info_installed: info returned has certain fields used by
179139
mac_brew.latest_version
180140
"""
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

Comments
 (0)