mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix PyLint
This commit is contained in:
parent
c0eab8b549
commit
bc05acf7c3
1 changed files with 29 additions and 33 deletions
|
@ -38,6 +38,7 @@ zypper.__salt__ = dict()
|
|||
zypper.__context__ = dict()
|
||||
zypper.rpm = None
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class ZypperTestCase(TestCase):
|
||||
'''
|
||||
|
@ -56,13 +57,12 @@ class ZypperTestCase(TestCase):
|
|||
}
|
||||
with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=ref_out)}):
|
||||
upgrades = zypper.list_upgrades(refresh=False)
|
||||
assert (len(upgrades) == 3)
|
||||
assert len(upgrades) == 3
|
||||
for pkg, version in {'SUSEConnect': '0.2.33-7.1',
|
||||
'bind-utils': '9.9.6P1-35.1',
|
||||
'bind-libs': '9.9.6P1-35.1'}.items():
|
||||
assert (pkg in upgrades)
|
||||
assert (upgrades[pkg] == version)
|
||||
|
||||
assert pkg in upgrades
|
||||
assert upgrades[pkg] == version
|
||||
|
||||
def test_list_upgrades_error_handling(self):
|
||||
'''
|
||||
|
@ -78,7 +78,7 @@ class ZypperTestCase(TestCase):
|
|||
try:
|
||||
zypper.list_upgrades(refresh=False)
|
||||
except CommandExecutionError as error:
|
||||
assert (error.message == ref_out['stderr'])
|
||||
assert error.message == ref_out['stderr']
|
||||
|
||||
# Test unhandled error
|
||||
ref_out = {
|
||||
|
@ -88,8 +88,7 @@ class ZypperTestCase(TestCase):
|
|||
try:
|
||||
zypper.list_upgrades(refresh=False)
|
||||
except CommandExecutionError as error:
|
||||
assert (error.message == 'Zypper returned non-zero system exit. See Zypper logs for more details.')
|
||||
|
||||
assert error.message == 'Zypper returned non-zero system exit. See Zypper logs for more details.'
|
||||
|
||||
def test_list_products(self):
|
||||
'''
|
||||
|
@ -98,7 +97,7 @@ class ZypperTestCase(TestCase):
|
|||
ref_out = get_test_data('zypper-products.xml')
|
||||
with patch.dict(zypper.__salt__, {'cmd.run': MagicMock(return_value=ref_out)}):
|
||||
products = zypper.list_products()
|
||||
assert (len(products) == 5)
|
||||
assert len(products) == 5
|
||||
assert (['SLES', 'SLES', 'SUSE-Manager-Proxy', 'SUSE-Manager-Server', 'sle-manager-tools-beta'] ==
|
||||
sorted([prod['name'] for prod in products]))
|
||||
assert ('SUSE LLC <https://www.suse.com/>' in [product['vendor'] for product in products])
|
||||
|
@ -113,7 +112,6 @@ class ZypperTestCase(TestCase):
|
|||
assert ([1509408000, 1522454400, 1522454400, 1730332800, 1730332800] ==
|
||||
sorted([product['eol_t'] for product in products]))
|
||||
|
||||
|
||||
def test_refresh_db(self):
|
||||
'''
|
||||
Test if refresh DB handled correctly
|
||||
|
@ -138,7 +136,6 @@ class ZypperTestCase(TestCase):
|
|||
self.assertEqual(result.get("openSUSE-Leap-42.1-Update"), False)
|
||||
self.assertEqual(result.get("openSUSE-Leap-42.1-Update-Non-Oss"), True)
|
||||
|
||||
|
||||
def test_info_installed(self):
|
||||
'''
|
||||
Test the return information of the named package(s), installed on the system.
|
||||
|
@ -171,17 +168,17 @@ class ZypperTestCase(TestCase):
|
|||
with patch.dict(zypper.__salt__, {'lowpkg.info': MagicMock(return_value=run_out)}):
|
||||
installed = zypper.info_installed()
|
||||
# Test overall products length
|
||||
assert (len(installed) == 2)
|
||||
assert len(installed) == 2
|
||||
|
||||
# Test translated fields
|
||||
for pkg_name, pkg_info in installed.items():
|
||||
assert (installed[pkg_name].get('source') == run_out[pkg_name]['source_rpm'])
|
||||
assert installed[pkg_name].get('source') == run_out[pkg_name]['source_rpm']
|
||||
|
||||
# Test keys transition from the lowpkg.info
|
||||
for pn_key, pn_val in run_out['virgo-dummy'].items():
|
||||
if pn_key == 'source_rpm':
|
||||
continue
|
||||
assert (installed['virgo-dummy'][pn_key] == pn_val)
|
||||
assert installed['virgo-dummy'][pn_key] == pn_val
|
||||
|
||||
def test_info_available(self):
|
||||
'''
|
||||
|
@ -193,21 +190,21 @@ class ZypperTestCase(TestCase):
|
|||
ref_out = get_test_data('zypper-available.txt')
|
||||
with patch.dict(zypper.__salt__, {'cmd.run_stdout': MagicMock(return_value=ref_out)}):
|
||||
available = zypper.info_available(*test_pkgs, refresh=False)
|
||||
assert (len(available) == 3)
|
||||
assert len(available) == 3
|
||||
for pkg_name, pkg_info in available.items():
|
||||
assert (pkg_name in test_pkgs)
|
||||
assert pkg_name in test_pkgs
|
||||
|
||||
assert (available['emacs']['status'] == 'up-to-date')
|
||||
assert (available['emacs']['installed'] == True)
|
||||
assert (available['emacs']['support level'] == 'Level 3')
|
||||
assert (available['emacs']['vendor'] == 'SUSE LLC <https://www.suse.com/>')
|
||||
assert (available['emacs']['summary'] == 'GNU Emacs Base Package')
|
||||
assert available['emacs']['status'] == 'up-to-date'
|
||||
assert available['emacs']['installed']
|
||||
assert available['emacs']['support level'] == 'Level 3'
|
||||
assert available['emacs']['vendor'] == 'SUSE LLC <https://www.suse.com/>'
|
||||
assert available['emacs']['summary'] == 'GNU Emacs Base Package'
|
||||
|
||||
assert (available['vim']['status'] == 'not installed')
|
||||
assert (available['vim']['installed'] == False)
|
||||
assert (available['vim']['support level'] == 'Level 3')
|
||||
assert (available['vim']['vendor'] == 'SUSE LLC <https://www.suse.com/>')
|
||||
assert (available['vim']['summary'] == 'Vi IMproved')
|
||||
assert available['vim']['status'] == 'not installed'
|
||||
assert not available['vim']['installed']
|
||||
assert available['vim']['support level'] == 'Level 3'
|
||||
assert available['vim']['vendor'] == 'SUSE LLC <https://www.suse.com/>'
|
||||
assert available['vim']['summary'] == 'Vi IMproved'
|
||||
|
||||
@patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True))
|
||||
def test_latest_version(self):
|
||||
|
@ -218,7 +215,7 @@ class ZypperTestCase(TestCase):
|
|||
'''
|
||||
ref_out = get_test_data('zypper-available.txt')
|
||||
with patch.dict(zypper.__salt__, {'cmd.run_stdout': MagicMock(return_value=ref_out)}):
|
||||
assert (zypper.latest_version('vim') == '7.4.326-2.62')
|
||||
assert zypper.latest_version('vim') == '7.4.326-2.62'
|
||||
|
||||
@patch('salt.modules.zypper.refresh_db', MagicMock(return_value=True))
|
||||
def test_upgrade_available(self):
|
||||
|
@ -230,8 +227,8 @@ class ZypperTestCase(TestCase):
|
|||
ref_out = get_test_data('zypper-available.txt')
|
||||
with patch.dict(zypper.__salt__, {'cmd.run_stdout': MagicMock(return_value=ref_out)}):
|
||||
for pkg_name in ['emacs', 'python']:
|
||||
assert (not zypper.upgrade_available(pkg_name))
|
||||
assert (zypper.upgrade_available('vim'))
|
||||
assert not zypper.upgrade_available(pkg_name)
|
||||
assert zypper.upgrade_available('vim')
|
||||
|
||||
@patch('salt.modules.zypper.HAS_RPM', True)
|
||||
def test_version_cmp_rpm(self):
|
||||
|
@ -242,7 +239,7 @@ class ZypperTestCase(TestCase):
|
|||
'''
|
||||
with patch('salt.modules.zypper.rpm', MagicMock(return_value=MagicMock)):
|
||||
with patch('salt.modules.zypper.rpm.labelCompare', MagicMock(return_value=0)):
|
||||
assert (0 == zypper.version_cmp('1', '2')) # mock returns 0, which means RPM was called
|
||||
assert 0 == zypper.version_cmp('1', '2') # mock returns 0, which means RPM was called
|
||||
|
||||
@patch('salt.modules.zypper.HAS_RPM', False)
|
||||
def test_version_cmp_fallback(self):
|
||||
|
@ -253,8 +250,7 @@ class ZypperTestCase(TestCase):
|
|||
'''
|
||||
with patch('salt.modules.zypper.rpm', MagicMock(return_value=MagicMock)):
|
||||
with patch('salt.modules.zypper.rpm.labelCompare', MagicMock(return_value=0)):
|
||||
assert (-1 == zypper.version_cmp('1', '2')) # mock returns -1, a python implementation was called
|
||||
|
||||
assert -1 == zypper.version_cmp('1', '2') # mock returns -1, a python implementation was called
|
||||
|
||||
def test_list_pkgs(self):
|
||||
'''
|
||||
|
@ -285,8 +281,8 @@ class ZypperTestCase(TestCase):
|
|||
'susemanager-build-keys-web': '12.0-5.1.develHead',
|
||||
'apache-commons-cli': '1.2-1.233',
|
||||
'jose4j': '0.4.4-2.1.develHead'}.items():
|
||||
assert (pkgs.get(pkg_name))
|
||||
assert (pkgs[pkg_name] == pkg_version)
|
||||
assert pkgs.get(pkg_name)
|
||||
assert pkgs[pkg_name] == pkg_version
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Reference in a new issue