• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python saltunittest.TestLoader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中saltunittest.TestLoader的典型用法代码示例。如果您正苦于以下问题:Python TestLoader类的具体用法?Python TestLoader怎么用?Python TestLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TestLoader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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())
开发者ID:vlaci,项目名称:salt,代码行数:14,代码来源:__init__.py


示例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())
开发者ID:BackSeat,项目名称:salt,代码行数:28,代码来源:master.py


示例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)
开发者ID:herlo,项目名称:salt,代码行数:29,代码来源:file_test.py


示例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())
开发者ID:twinshadow,项目名称:salt,代码行数:30,代码来源:cmdmod.py


示例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)
开发者ID:BackSeat,项目名称:salt,代码行数:30,代码来源:rvm_test.py


示例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())
开发者ID:lixmgl,项目名称:Intern_OpenStack_Swift,代码行数:30,代码来源:ssh.py


示例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())
开发者ID:BackSeat,项目名称:salt,代码行数:28,代码来源:syndic.py


示例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)
开发者ID:herlo,项目名称:salt,代码行数:30,代码来源:log_test.py


示例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())
开发者ID:Adapptor,项目名称:salt,代码行数:30,代码来源:state.py


示例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())
开发者ID:lixmgl,项目名称:Intern_OpenStack_Swift,代码行数:30,代码来源:virtualenv.py


示例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())
开发者ID:Adapptor,项目名称:salt,代码行数:30,代码来源:data.py


示例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())
开发者ID:Adapptor,项目名称:salt,代码行数:30,代码来源:aliases.py


示例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)
开发者ID:herlo,项目名称:salt,代码行数:30,代码来源:win_status_test.py


示例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())
开发者ID:11craft,项目名称:salt,代码行数:30,代码来源:minion.py


示例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)
开发者ID:rrada,项目名称:salt,代码行数:29,代码来源:filebuffer_test.py


示例16: in

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z '$debian_chroot' ] && [ -r "/etc/debian_chroot" ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi
"""


class TestRuntimeWhitespaceRegex(TestCase):

    def test_single_quotes(self):
        regex = build_whitespace_split_regex(SINGLE_TXT)
        self.assertTrue(re.search(regex, MATCH))

    def test_double_quotes(self):
        regex = build_whitespace_split_regex(DOUBLE_TXT)
        self.assertTrue(re.search(regex, MATCH))

    def test_single_and_double_quotes(self):
        regex = build_whitespace_split_regex(SINGLE_DOUBLE_TXT)
        self.assertTrue(re.search(regex, MATCH))

    def test_issue_2227(self):
        regex = build_whitespace_split_regex(SINGLE_DOUBLE_SAME_LINE_TXT)
        self.assertTrue(re.search(regex, MATCH))


if __name__ == "__main__":
    loader = TestLoader()
    tests = loader.loadTestsFromTestCase(TestRuntimeWhitespaceRegex)
    TextTestRunner(verbosity=1).run(tests)
开发者ID:herlo,项目名称:salt,代码行数:30,代码来源:runtime_whitespace_regex_test.py


示例17: test_active

    def test_active(self):
        '''
        jobs.active
        '''
        ret = self.run_run_plus('jobs.active')
        self.assertFalse(ret['fun'])
        self.assertFalse(ret['out'][1])

    def test_lookup_jid(self):
        '''
        jobs.lookup_jid
        '''
        ret = self.run_run_plus('jobs.lookup_jid', '', '23974239742394')
        self.assertFalse(ret['fun'])
        self.assertFalse(ret['out'][1])

    def test_list_jobs(self):
        '''
        jobs.list_jobs
        '''
        ret = self.run_run_plus('jobs.list_jobs')
        self.assertIsInstance(ret['fun'], dict)

if __name__ == "__main__":
    loader = TestLoader()
    tests = loader.loadTestsFromTestCase(ManageTest)
    print('Setting up Salt daemons to execute tests')
    with TestDaemon():
        runner = TextTestRunner(verbosity=1).run(tests)
        sys.exit(runner.wasSuccessful())
开发者ID:DarkSinclair,项目名称:salt,代码行数:30,代码来源:jobs.py


示例18: test_active

    def test_active(self):
        '''
        jobs.active
        '''
        ret = self.run_run_plus('jobs.active')
        self.assertFalse(ret['fun'])
        self.assertFalse(ret['out'][1])

    def test_lookup_jid(self):
        '''
        jobs.lookup_jid
        '''
        ret = self.run_run_plus('jobs.lookup_jid', '', '23974239742394')
        self.assertFalse(ret['fun'])
        self.assertFalse(ret['out'][1])

    def test_list_jobs(self):
        '''
        jobs.list_jobs
        '''
        ret = self.run_run_plus('jobs.list_jobs')
        self.assertIsInstance(ret['fun'], dict)

if __name__ == "__main__":
    loader = TestLoader()
    tests = loader.loadTestsFromTestCase(RunTest)
    print('Setting up Salt daemons to execute tests')
    with TestDaemon():
        runner = TextTestRunner(verbosity=1).run(tests)
        sys.exit(runner.wasSuccessful())
开发者ID:Adapptor,项目名称:salt,代码行数:30,代码来源:jobs.py


示例19: dict

        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)
开发者ID:11craft,项目名称:salt,代码行数:30,代码来源:event_test.py


示例20: sass

sass (3.1.15, 3.1.7)
'''
        mock = MagicMock(return_value=output)
        with patch.object(gem, '_gem', new=mock):
            self.assertEqual(
                {'actionmailer': ['2.3.14'],
                 'actionpack': ['2.3.14'],
                 'activerecord': ['2.3.14'],
                 'activeresource': ['2.3.14'],
                 'activesupport': ['3.0.5', '2.3.14'],
                 'rake': ['0.9.2', '0.8.7'],
                 'responds_to_parent': ['1.0.20091013'],
                 'sass': ['3.1.15', '3.1.7']},
                gem.list())

    def test_sources_list(self):
        output = '''*** CURRENT SOURCES ***

http://rubygems.org/
'''
        mock = MagicMock(return_value=output)
        with patch.object(gem, '_gem', new=mock):
            self.assertEqual(
                ['http://rubygems.org/'], gem.sources_list())


if __name__ == "__main__":
    loader = TestLoader()
    tests = loader.loadTestsFromTestCase(TestGemModule)
    TextTestRunner(verbosity=1).run(tests)
开发者ID:Adapptor,项目名称:salt,代码行数:30,代码来源:gem_test.py



注:本文中的saltunittest.TestLoader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sam.eval函数代码示例发布时间:2022-05-27
下一篇:
Python patch.object函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap