mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix PEP8 warnings for test cases
This commit is contained in:
parent
2515033c08
commit
24bb4ea4e0
15 changed files with 35 additions and 20 deletions
|
@ -28,6 +28,7 @@ PYEXEC = 'python{0}.{1}'.format(sys.version_info[0], sys.version_info[1])
|
|||
TMP = os.path.join(INTEGRATION_TEST_DIR, 'tmp')
|
||||
FILES = os.path.join(INTEGRATION_TEST_DIR, 'files')
|
||||
|
||||
|
||||
class TestDaemon(object):
|
||||
'''
|
||||
Set up the master and minion daemons, and run related cases
|
||||
|
@ -173,7 +174,6 @@ class ModuleCase(TestCase):
|
|||
'''
|
||||
return self.run_function('state.single', [function], **kwargs)
|
||||
|
||||
|
||||
def minion_opts(self):
|
||||
'''
|
||||
Return the options used for the minion
|
||||
|
@ -196,6 +196,7 @@ class ModuleCase(TestCase):
|
|||
)
|
||||
)
|
||||
|
||||
|
||||
class SyndicCase(TestCase):
|
||||
'''
|
||||
Execute a syndic based execution test
|
||||
|
|
|
@ -8,6 +8,7 @@ from saltunittest import TestLoader, TextTestRunner
|
|||
import integration
|
||||
from integration import TestDaemon
|
||||
|
||||
|
||||
class AliasesTest(integration.ModuleCase):
|
||||
'''
|
||||
Validate aliases module
|
||||
|
@ -71,4 +72,3 @@ class AliasesTest(integration.ModuleCase):
|
|||
'aliases.list_aliases')
|
||||
self.assertIsInstance(tgt_ret, dict)
|
||||
self.assertNotIn('alias=frank', tgt_ret)
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ class CPModuleTest(integration.ModuleCase):
|
|||
ret = self.run_function(
|
||||
'cp.cache_files',
|
||||
[
|
||||
['salt://grail/scene33' ,'salt://grail/36/scene'],
|
||||
['salt://grail/scene33', 'salt://grail/36/scene'],
|
||||
])
|
||||
for path in ret:
|
||||
with open(path, 'r') as scene:
|
||||
|
|
|
@ -57,9 +57,9 @@ class PublishModuleTest(integration.ModuleCase):
|
|||
for name in check_true:
|
||||
self.assertTrue(name in ret)
|
||||
|
||||
self.assertEqual(ret['cheese'], 'spam')
|
||||
self.assertEqual(ret['cheese'], 'spam')
|
||||
self.assertEqual(ret['__pub_arg'], ['cheese=spam'])
|
||||
self.assertEqual(ret['__pub_id'], 'minion')
|
||||
self.assertEqual(ret['__pub_id'], 'minion')
|
||||
self.assertEqual(ret['__pub_fun'], 'test.kwarg')
|
||||
|
||||
def test_reject_minion(self):
|
||||
|
|
|
@ -77,7 +77,6 @@ class SSHModuleTest(integration.ModuleCase):
|
|||
ret = self.run_function('ssh.check_known_host', arg, **kwargs)
|
||||
self.assertEqual(ret, 'add')
|
||||
|
||||
|
||||
def test_check_known_host_update(self):
|
||||
shutil.copyfile(
|
||||
os.path.join(integration.FILES, 'ssh', 'known_hosts'),
|
||||
|
|
|
@ -48,23 +48,23 @@ class KeyTest(integration.ShellCase):
|
|||
'''
|
||||
data = self.run_key('-L --yaml-out')
|
||||
expect = [
|
||||
'accepted: [minion, sub_minion]',
|
||||
'rejected: []',
|
||||
'unaccepted: []',
|
||||
'',
|
||||
'accepted: [minion, sub_minion]',
|
||||
'rejected: []',
|
||||
'unaccepted: []',
|
||||
'',
|
||||
''
|
||||
]
|
||||
self.assertEqual(data, expect)
|
||||
|
||||
|
||||
def test_list_raw_out(self):
|
||||
'''
|
||||
test salt-key -L --raw-out
|
||||
'''
|
||||
data = self.run_key('-L --raw-out')
|
||||
expect = [
|
||||
"{'unaccepted': [], 'accepted': ['minion', 'sub_minion'], 'rejected': []}",
|
||||
"{'unaccepted': [], 'accepted': ['minion', 'sub_minion'], 'rejected': []}",
|
||||
''
|
||||
]
|
||||
]
|
||||
self.assertEqual(data, expect)
|
||||
|
||||
def test_list_acc(self):
|
||||
|
|
|
@ -9,6 +9,7 @@ from saltunittest import TestLoader, TextTestRunner
|
|||
import integration
|
||||
from integration import TestDaemon
|
||||
|
||||
|
||||
class CMDTest(integration.ModuleCase):
|
||||
'''
|
||||
Validate the cmd state
|
||||
|
@ -28,4 +29,3 @@ class CMDTest(integration.ModuleCase):
|
|||
ret = self.run_state('cmd.run', name='ls', test=True)
|
||||
result = ret[ret.keys()[0]]['result']
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from saltunittest import TestLoader, TextTestRunner
|
|||
import integration
|
||||
from integration import TestDaemon
|
||||
|
||||
|
||||
class CompileTest(integration.ModuleCase):
|
||||
'''
|
||||
Validate the state compiler
|
||||
|
|
|
@ -7,6 +7,7 @@ import os
|
|||
# Import salt libs
|
||||
import integration
|
||||
|
||||
|
||||
class FileTest(integration.ModuleCase):
|
||||
'''
|
||||
Validate the file state
|
||||
|
@ -350,7 +351,6 @@ if __name__ == "__main__":
|
|||
from saltunittest import TestLoader, TextTestRunner
|
||||
from integration import TestDaemon
|
||||
|
||||
|
||||
loader = TestLoader()
|
||||
tests = loader.loadTestsFromTestCase(FileTest)
|
||||
print('Setting up Salt daemons to execute tests')
|
||||
|
|
|
@ -12,6 +12,7 @@ from integration import TestDaemon
|
|||
|
||||
HFILE = os.path.join(integration.TMP, 'hosts')
|
||||
|
||||
|
||||
class HostTest(integration.ModuleCase):
|
||||
'''
|
||||
Validate the host state
|
||||
|
@ -25,4 +26,3 @@ class HostTest(integration.ModuleCase):
|
|||
self.assertTrue(result)
|
||||
with open(HFILE) as fp_:
|
||||
self.assertIn('{0}\t\t{1}'.format(ip, name), fp_.read())
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class SSHKnownHostsStateTest(integration.ModuleCase):
|
|||
self.assertEqual(ret['result'], None, ret)
|
||||
# then add a record for IP address
|
||||
_ret = self.run_state('ssh_known_hosts.present',
|
||||
**dict(kwargs, name=GITHUB_IP ))
|
||||
**dict(kwargs, name=GITHUB_IP))
|
||||
ret = _ret.values()[0]
|
||||
self.assertEqual(ret['changes']['new']['fingerprint'],
|
||||
GITHUB_FINGERPRINT, ret)
|
||||
|
@ -104,7 +104,6 @@ if __name__ == "__main__":
|
|||
from saltunittest import TestLoader, TextTestRunner
|
||||
from integration import TestDaemon
|
||||
|
||||
|
||||
loader = TestLoader()
|
||||
tests = loader.loadTestsFromTestCase(SSHKnownHostsStateTest)
|
||||
print('Setting up Salt daemons to execute tests')
|
||||
|
|
|
@ -16,6 +16,7 @@ import hashlib
|
|||
# Import third party libs
|
||||
import yaml
|
||||
|
||||
|
||||
def parse():
|
||||
'''
|
||||
Parse the cli options
|
||||
|
|
|
@ -12,7 +12,7 @@ import os
|
|||
import sys
|
||||
|
||||
# support python < 2.7 via unittest2
|
||||
if sys.version_info[0:2] < (2,7):
|
||||
if sys.version_info[0:2] < (2, 7):
|
||||
try:
|
||||
from unittest2 import TestLoader, TextTestRunner,\
|
||||
TestCase, expectedFailure, \
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from saltunittest import TestCase, expectedFailure
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_success(self):
|
||||
assert True
|
||||
|
||||
@expectedFailure
|
||||
def test_fail(self):
|
||||
assert False
|
||||
|
|
|
@ -7,13 +7,16 @@ from saltunittest import TestCase
|
|||
|
||||
TEMPLATES_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class MockFileClient(object):
|
||||
'''
|
||||
Does not download files but records any file request for testing
|
||||
'''
|
||||
def __init__(self, loader=None):
|
||||
if loader: loader._file_client = self
|
||||
if loader:
|
||||
loader._file_client = self
|
||||
self.requests = []
|
||||
|
||||
def get_file(self, template, dest='', makedirs=False, env='base'):
|
||||
self.requests.append({
|
||||
'path': template,
|
||||
|
@ -22,6 +25,7 @@ class MockFileClient(object):
|
|||
'env': env
|
||||
})
|
||||
|
||||
|
||||
class TestSaltCacheLoader(TestCase):
|
||||
def test_searchpath(self):
|
||||
'''
|
||||
|
@ -30,6 +34,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
tmp = tempfile.gettempdir()
|
||||
loader = SaltCacheLoader({'cachedir': tmp}, env='test')
|
||||
assert loader.searchpath == os.path.join(tmp, 'files', 'test')
|
||||
|
||||
def test_mockclient(self):
|
||||
'''
|
||||
A MockFileClient is used that records all file request normally send to the master.
|
||||
|
@ -44,6 +49,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
assert res[2](), "Template up to date?"
|
||||
assert len(fc.requests)
|
||||
self.assertEqual(fc.requests[0]['path'], 'salt://hello_simple')
|
||||
|
||||
def get_test_env(self):
|
||||
'''
|
||||
Setup a simple jinja test environment
|
||||
|
@ -52,6 +58,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
fc = MockFileClient(loader)
|
||||
jinja = Environment(loader=loader)
|
||||
return fc, jinja
|
||||
|
||||
def test_import(self):
|
||||
'''
|
||||
You can import and use macros from other files
|
||||
|
@ -62,6 +69,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
assert len(fc.requests) == 2
|
||||
self.assertEqual(fc.requests[0]['path'], 'salt://hello_import')
|
||||
self.assertEqual(fc.requests[1]['path'], 'salt://macro')
|
||||
|
||||
def test_include(self):
|
||||
'''
|
||||
You can also include a template that imports and uses macros
|
||||
|
@ -73,6 +81,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
self.assertEqual(fc.requests[0]['path'], 'salt://hello_include')
|
||||
self.assertEqual(fc.requests[1]['path'], 'salt://hello_import')
|
||||
self.assertEqual(fc.requests[2]['path'], 'salt://macro')
|
||||
|
||||
def test_include_context(self):
|
||||
'''
|
||||
Context variables are passes to the included template by default.
|
||||
|
@ -81,6 +90,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
result = jinja.get_template('hello_include').render(a='Hi', b='Salt')
|
||||
self.assertEqual(result, 'Hey world !Hi Salt !')
|
||||
|
||||
|
||||
class TestGetTemplate(TestCase):
|
||||
def test_fallback(self):
|
||||
'''
|
||||
|
@ -90,6 +100,7 @@ class TestGetTemplate(TestCase):
|
|||
filename = os.path.join(TEMPLATES_DIR, 'files', 'test', 'hello_simple')
|
||||
tmpl = get_template(filename, {'cachedir': TEMPLATES_DIR}, env='other')
|
||||
self.assertEqual(tmpl.render(), 'world')
|
||||
|
||||
def test_fallback_noloader(self):
|
||||
'''
|
||||
If the fallback is used any attempt to load other templates
|
||||
|
@ -98,6 +109,7 @@ class TestGetTemplate(TestCase):
|
|||
filename = os.path.join(TEMPLATES_DIR, 'files', 'test', 'hello_import')
|
||||
tmpl = get_template(filename, {'cachedir': TEMPLATES_DIR}, env='other')
|
||||
self.assertRaises(TypeError, tmpl.render)
|
||||
|
||||
def test_env(self):
|
||||
'''
|
||||
If the template is within the searchpath it can
|
||||
|
|
Loading…
Add table
Reference in a new issue