本文整理汇总了Python中saltunittest.TestLoader.loadTestsFromTestCase方法的典型用法代码示例。如果您正苦于以下问题:Python TestLoader.loadTestsFromTestCase方法的具体用法?Python TestLoader.loadTestsFromTestCase怎么用?Python TestLoader.loadTestsFromTestCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类saltunittest.TestLoader
的用法示例。
在下文中一共展示了TestLoader.loadTestsFromTestCase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_tests
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
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: test_full_returns
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
self.assertIn('qux', data)
self.assertEqual(data['foo'], 'bar')
self.assertEqual(data['baz'], 'quo')
self.assertEqual(data['qux'], 'quux')
def test_full_returns(self):
'''
test cmd_iter
'''
ret = self.client.cmd_full_return(
'minion',
'test.kwarg',
['foo=bar', 'baz=quo'],
kwarg={'qux': 'quux'}
)
data = ret['minion']
self.assertIn('foo', data['ret'])
self.assertIn('baz', data['ret'])
self.assertIn('qux', data['ret'])
self.assertEqual(data['ret']['foo'], 'bar')
self.assertEqual(data['ret']['baz'], 'quo')
self.assertEqual(data['ret']['qux'], 'quux')
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(StdTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例3: FileModuleTestCase
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
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
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
"""
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: CallTest
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
_call_binary_ = 'salt-call'
def test_default_output(self):
out = self.run_call('test.fib 3')
self.assertEqual(
"local: !!python/tuple\n- [0, 1, 1, 2]", '\n'.join(out[:-3])
)
def test_text_output(self):
out = self.run_call('--text-out test.fib 3')
self.assertEqual("local: ([0, 1, 1, 2]", ''.join(out).rsplit(",", 1)[0])
@skipIf(sys.platform.startswith('win'), 'This test does not apply on Win')
def test_user_delete_kw_output(self):
ret = self.run_call('-d user.delete')
self.assertIn(
'salt \'*\' user.delete name remove=True force=True',
''.join(ret)
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(CallTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例6: test_static
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
'''
test compound matcher
'''
match = '[email protected]_grain:^cheese$ and * and [email protected]_grain:cheese'
data = self.run_salt('-t 1 -C \'{0}\' test.ping'.format(match))
data = '\n'.join(data)
self.assertIn('minion', data)
self.assertNotIn('sub_minion', data)
match = '[email protected]_minion and [email protected]*'
data = self.run_salt('-t 1 -C "{0}" test.ping'.format(match))
data = '\n'.join(data)
self.assertIn('sub_minion', data)
self.assertNotIn('minion', data.replace('sub_minion', 'stub'))
def test_static(self):
'''
test salt static call
'''
data = self.run_salt('minion test.ping --static')
data = '\n'.join(data)
self.assertIn('minion', data)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(KeyTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
示例7: dict
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
opts = dict(id='foo', ipc_mode='tcp')
me = event.MinionEvent(**opts)
self.assertEqual(me.puburi, 'tcp://127.0.0.1:4510')
self.assertEqual(me.pulluri, 'tcp://127.0.0.1:4511')
def test_minion_event_no_id(self):
me = event.MinionEvent(sock_dir=SOCK_DIR)
id_hash = hashlib.md5('').hexdigest()
self.assertEqual(
me.puburi,
'ipc://{0}'.format(
os.path.join(
SOCK_DIR, 'minion_event_{0}_pub.ipc'.format(id_hash)
)
)
)
self.assertEqual(
me.pulluri,
'ipc://{0}'.format(
os.path.join(
SOCK_DIR, 'minion_event_{0}_pull.ipc'.format(id_hash)
)
)
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestSaltEvent)
TextTestRunner(verbosity=1).run(tests)
示例8: TestLoader
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
)
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())
示例9: test_clear
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
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())
示例10: test_cmd_is_empty_string
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
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)
示例11: test_rm_alias
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
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())
示例12: Algarvio
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
# -*- 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())
示例13: Algarvio
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
: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)
示例14: Algarvio
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
# -*- 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())
示例15: test_data
# 需要导入模块: from saltunittest import TestLoader [as 别名]
# 或者: from saltunittest.TestLoader import loadTestsFromTestCase [as 别名]
Validate the pillar module
'''
def test_data(self):
'''
pillar.data
'''
grains = self.run_function('grains.items')
pillar = self.run_function('pillar.data')
self.assertEqual(pillar['os'], grains['os'])
self.assertEqual(pillar['monty'], 'python')
if grains['os'] == 'Fedora':
self.assertEqual(pillar['class'], 'redhat')
else:
self.assertEqual(pillar['class'], 'other')
def test_ext_cmd_yaml(self):
'''
pillar.data for ext_pillar cmd.yaml
'''
self.assertEqual(
self.run_function('pillar.data')['ext_spam'], 'eggs'
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(PillarModuleTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())