本文整理汇总了Python中saltunittest.TestLoader类的典型用法代码示例。如果您正苦于以下问题:Python TestLoader类的具体用法?Python TestLoader怎么用?Python TestLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_tests
def run_tests(TestCase):
'''
Run integration tests for a chosen test case.
Function uses optparse to set up test environment
'''
from saltunittest import TestLoader, TextTestRunner
opts = parse_opts()
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestCase)
print('Setting up Salt daemons to execute tests')
with TestDaemon(clean=opts.clean):
runner = TextTestRunner(verbosity=opts.verbosity).run(tests)
sys.exit(runner.wasSuccessful())
示例2: Algarvio
# -*- coding: utf-8 -*-
"""
tests.integration.shell.master
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: © 2012 UfSoft.org - :email:`Pedro Algarvio ([email protected])`
:license: Apache 2.0, see LICENSE for more details.
"""
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
class MasterTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
_call_binary_ = 'salt-master'
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(MasterTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例3: FileModuleTestCase
SED_CONTENT = """test
some
content
/var/lib/foo/app/test
here
"""
class FileModuleTestCase(TestCase):
def test_sed_limit_escaped(self):
with tempfile.NamedTemporaryFile() as tfile:
tfile.write(SED_CONTENT)
tfile.seek(0, 0)
path = tfile.name
before = "/var/lib/foo"
after = ""
limit = "^{0}".format(before)
filemod.sed(path, before, after, limit=limit)
with open(path, "rb") as newfile:
self.assertEquals(SED_CONTENT.replace(before, ""), newfile.read())
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(FileModuleTestCase)
TextTestRunner(verbosity=1).run(tests)
示例4: test_has_exec
"""
self.assertEqual(
self.run_function("cmd.which", ["echo"]).rstrip(), self.run_function("cmd.run", ["which echo"]).rstrip()
)
def test_has_exec(self):
"""
cmd.has_exec
"""
self.assertTrue(self.run_function("cmd.has_exec", ["python"]))
self.assertFalse(self.run_function("cmd.has_exec", ["alllfsdfnwieulrrh9123857ygf"]))
def test_exec_code(self):
"""
cmd.exec_code
"""
code = """
import sys
sys.stdout.write('cheese')
"""
self.assertEqual(self.run_function("cmd.exec_code", ["python", code]).rstrip(), "cheese")
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(CMDModuleTest)
print("Setting up Salt daemons to execute tests")
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例5: MagicMock
gemset_list = MagicMock(return_value=gems)
gemset_create = MagicMock(return_value=True)
check_ruby = MagicMock(
return_value={'result': False, 'changes': {}})
with patch.object(rvm, '_check_ruby', new=check_ruby):
with patch.dict(rvm.__salt__,
{'rvm.gemset_list': gemset_list,
'rvm.gemset_create': gemset_create}):
ret = rvm.gemset_present('foo')
self.assertEqual(True, ret['result'])
ret = rvm.gemset_present('quux')
self.assertEqual(True, ret['result'])
gemset_create.assert_called_once_with(
'default', 'quux', runas=None)
def test_installed(self):
mock = MagicMock()
with patch.object(rvm, '_check_rvm') as mock_method:
mock_method.return_value = {'result': True}
with patch.object(rvm, '_check_and_install_ruby', new=mock):
rvm.installed("1.9.3", default=True)
mock.assert_called_once_with(
{'result': True}, '1.9.3', True, runas=None)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestRvmState)
TextTestRunner(verbosity=1).run(tests)
示例6: test_set_known_host
# after removal
ret = self.run_function('ssh.check_known_host', arg, **kwargs)
self.assertEqual(ret, 'add')
def test_set_known_host(self):
'''
ssh.set_known_host
'''
# add item
ret = self.run_function('ssh.set_known_host', ['root', 'github.com'],
config=KNOWN_HOSTS)
self.assertEqual(ret['status'], 'updated')
self.assertEqual(ret['old'], None)
self.assertEqual(ret['new']['fingerprint'], GITHUB_FINGERPRINT)
# check that item does exist
ret = self.run_function('ssh.get_known_host', ['root', 'github.com'],
config=KNOWN_HOSTS)
self.assertEqual(ret['fingerprint'], GITHUB_FINGERPRINT)
# add the same item once again
ret = self.run_function('ssh.set_known_host', ['root', 'github.com'],
config=KNOWN_HOSTS)
self.assertEqual(ret['status'], 'exists')
if __name__ == '__main__':
loader = TestLoader()
tests = loader.loadTestsFromTestCase(SSHModuleTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例7: Algarvio
# -*- coding: utf-8 -*-
"""
tests.integration.shell.syndic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: © 2012 UfSoft.org - :email:`Pedro Algarvio ([email protected])`
:license: Apache 2.0, see LICENSE for more details.
"""
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
class SyndicTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
_call_binary_ = 'salt-syndic'
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(SyndicTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例8: TestsLoggingHandler
'No exception should have been raised: {0}'.format(err)
)
# Remove the testing handler
log.removeHandler(handler)
# Test for a format which does not include digits in name formatting.
log_format = '[%(name)s] %(message)s'
handler = TestsLoggingHandler(format=log_format)
log.addHandler(handler)
# Trigger TestsLoggingHandler.__enter__
with handler:
# Let's create another log instance to trigger salt's logging class
# calculations.
try:
saltlog.SaltLoggingClass('{0}.without_digits'.format(__name__))
except Exception as err:
raise AssertionError(
'No exception should have been raised: {0}'.format(err)
)
# Remove the testing handler
log.removeHandler(handler)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestLog)
TextTestRunner(verbosity=1).run(tests)
示例9: test_catch_recurse
self.assertTrue(isinstance(low[0], dict))
def test_catch_recurse(self):
'''
state.show_sls used to catch a recursive ref
'''
err = self.run_function('state.sls', mods='recurse_fail')
self.assertIn('recursive', err[0])
def test_no_recurse(self):
'''
verify that a sls structure is NOT a recursive ref
'''
sls = self.run_function('state.show_sls', mods='recurse_ok')
self.assertIn('snmpd', sls)
def test_no_recurse_two(self):
'''
verify that a sls structure is NOT a recursive ref
'''
sls = self.run_function('state.show_sls', mods='recurse_ok_two')
self.assertIn('/etc/nagios/nrpe.cfg', sls)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(StateModuleTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例10: test_clear
with_site = self.run_function('pip.freeze', bin_env=pip_bin)
self.run_function('file.remove', [self.venv_dir])
self.run_function('virtualenv.create',
[self.venv_dir])
without_site = self.run_function('pip.freeze', bin_env=pip_bin)
self.assertFalse(with_site == without_site)
def test_clear(self):
pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
self.run_function('virtualenv.create',
[self.venv_dir])
self.run_function('pip.install', [], pkgs='pep8', bin_env=pip_bin)
self.run_function('virtualenv.create',
[self.venv_dir],
clear=True)
packages = self.run_function('pip.list',
prefix='pep8',
bin_env=pip_bin)
self.assertFalse('pep8' in packages)
def tearDown(self):
self.run_function('file.remove', [self.venv_test_dir])
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(VirtualenvModuleTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例11: TestLoader
)
self.assertEqual(
self.run_function(
'data.getval',
['spam']
),
'eggs'
)
self.assertTrue(
self.run_function(
'data.update',
['unladen', 'swallow']
)
)
self.assertEqual(
self.run_function(
'data.getvals',
['["spam", "unladen"]']
),
['eggs', 'swallow']
)
self._clear_db()
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(DataModuleTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例12: test_rm_alias
self.assertTrue(set_ret)
tgt_ret = self.run_function(
'aliases.list_aliases')
self.assertIsInstance(tgt_ret, dict)
self.assertIn('alias=fred', tgt_ret)
def test_rm_alias(self):
'''
aliases.rm_alias
'''
set_ret = self.run_function(
'aliases.set_target',
alias='frank',
target='greg')
self.assertTrue(set_ret)
set_ret = self.run_function(
'aliases.rm_alias',
alias='frank')
tgt_ret = self.run_function(
'aliases.list_aliases')
self.assertIsInstance(tgt_ret, dict)
self.assertNotIn('alias=frank', tgt_ret)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(AliasesTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例13: test_cmd_is_empty_string
pid = 100
self.add_process(pid=pid, cmd=None)
self.call_procs()
self.proc = self.result[pid]
def test_cmd_is_empty_string(self):
self.assertEqual(self.proc['cmd'], '')
#class TestProcsComInitialization(TestProcsBase):
# def setUp(self):
# call_count = 5
# for _ in range(call_count):
# self.call_procs()
# self.expected_calls = [call()] * call_count
#
# def test_initialize_and_uninitialize_called(self):
# pythoncom.CoInitialize.assert_has_calls(self.expected_calls)
# pythoncom.CoUninitialize.assert_has_calls(self.expected_calls)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestProcsCount)
tests = loader.loadTestsFromTestCase(TestProcsAttributes)
tests = loader.loadTestsFromTestCase(TestProcsUnicodeAttributes)
tests = loader.loadTestsFromTestCase(
TestProcsWMIGetOwnerAccessDeniedWorkaround)
tests = loader.loadTestsFromTestCase(TestProcsWMIGetOwnerErrorsAreLogged)
TextTestRunner(verbosity=1).run(tests)
示例14: Algarvio
# -*- coding: utf-8 -*-
'''
tests.integration.shell.minion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:codeauthor: :email:`Pedro Algarvio ([email protected])`
:copyright: © 2012 by the SaltStack Team, see AUTHORS for more details.
:license: Apache 2.0, see LICENSE for more details.
'''
# Import python libs
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
class MinionTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
_call_binary_ = 'salt-minion'
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(MinionTest)
print('Setting up Salt daemons to execute tests')
with integration.TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例15: Algarvio
:copyright: © 2012 UfSoft.org - :email:`Pedro Algarvio ([email protected])`
:license: Apache 2.0, see LICENSE for more details.
"""
from saltunittest import TestCase, TestLoader, TextTestRunner
from salt.utils.filebuffer import BufferedReader, InvalidFileMode
class TestFileBuffer(TestCase):
def test_read_only_mode(self):
with self.assertRaises(InvalidFileMode):
BufferedReader("/tmp/foo", mode="a")
with self.assertRaises(InvalidFileMode):
BufferedReader("/tmp/foo", mode="ab")
with self.assertRaises(InvalidFileMode):
BufferedReader("/tmp/foo", mode="w")
with self.assertRaises(InvalidFileMode):
BufferedReader("/tmp/foo", mode="wb")
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestFileBuffer)
TextTestRunner(verbosity=1).run(tests)