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

Python testtools.iterate_tests函数代码示例

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

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



在下文中一共展示了iterate_tests函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: load_tests_input_scenario_utils

def load_tests_input_scenario_utils(*args):
    """
    Wrapper for testscenarios to set the scenarios to avoid running a getattr
    on the CONF object at import.
    """
    if getattr(args[0], "suiteClass", None) is not None:
        loader, standard_tests, pattern = args
    else:
        standard_tests, module, loader = args
    output = None
    scenario_utils = None
    try:
        scenario_utils = InputScenarioUtils()
        scenario_flavor = scenario_utils.scenario_flavors
        scenario_image = scenario_utils.scenario_images
    except (exc_lib.InvalidCredentials, TypeError):
        output = standard_tests
    finally:
        if scenario_utils:
            scenario_utils.clear_creds()
    if output is not None:
        return output
    for test in testtools.iterate_tests(standard_tests):
        setattr(test, "scenarios", testscenarios.multiply_scenarios(scenario_image, scenario_flavor))
    return testscenarios.load_tests_apply_scenarios(*args)
开发者ID:ravisantoshgudimetla,项目名称:tempest,代码行数:25,代码来源:utils.py


示例2: test_load_tests

    def test_load_tests(self):
        tests.write_tree_from_desc('''dir: t
file: t/__init__.py
import unittest

def load_tests(test_loader, tests, ignore):
    # A simple way to reveal the side effect is to add more tests
    class TestLoadTest(unittest.TestCase):
        def test_in_load_test(self):
          self.assertTrue(True)
    tests.addTests(test_loader.loadTestsFromTestCase(TestLoadTest))
    return tests

class TestInit(unittest.TestCase):

    def test_in_init(self):
      self.assertTrue(True)

file: t/test_not_discovered.py
import unittest

class Test(unittest.TestCase):

    def test_me(self):
      self.assertTrue(True)
''')
        test_loader = self.make_test_loader()
        suite = test_loader.discoverTestsFromTree('t')
        self.assertEqual(2, suite.countTestCases())
        self.assertEqual(['t.TestInit.test_in_init',
                          't.TestLoadTest.test_in_load_test'],
                         [t.id() for t in testtools.iterate_tests(suite)])
开发者ID:DramaFever,项目名称:sst,代码行数:32,代码来源:test_loaders.py


示例3: test_regular_below_scripts

    def test_regular_below_scripts(self):
        tests.write_tree_from_desc('''dir: t
file: t/__init__.py
dir: t/regular
file: t/regular/__init__.py
from sst import loaders

discover = loaders.discoverRegularTests

file: t/regular/test_foo.py
import unittest

class Test(unittest.TestCase):

    def test_me(self):
      self.assertTrue(True)
file: t/script.py
raise AssertionError('Loading only, executing fails')
''')
        suite = self.discover('t')
        # Check which kind of tests have been discovered or we may miss regular
        # test cases seen as scripts.
        self.assertEqual(['t.regular.test_foo.Test.test_me',
                          't.script'],
                         [t.id() for t in testtools.iterate_tests(suite)])
开发者ID:DramaFever,项目名称:sst,代码行数:25,代码来源:test_loaders.py


示例4: partition_tests

def partition_tests(suite, count):
    # Keep the same interface as the original concurrencytest.partition_tests
    independent_old_modules = [
        "pcs_test.tier0.test_constraints",
        "pcs_test.tier0.test_resource",
        "pcs_test.tier0.test_stonith",
    ]
    old_tests = [] # tests are not independent, cannot run in parallel
    old_tests_independent = {} # independent modules
    independent_tests = []
    for test in iterate_tests(suite):
        module = test.__class__.__module__
        if not (
            module.startswith("pcs_test.tier0.test_")
            or
            module.startswith("pcs_test.tier0.cib_resource")
        ):
            independent_tests.append(test)
        elif module in independent_old_modules:
            if module not in old_tests_independent:
                old_tests_independent[module] = []
            old_tests_independent[module].append(test)
        else:
            old_tests.append(test)
    return [old_tests, independent_tests] + list(old_tests_independent.values())
开发者ID:tomjelinek,项目名称:pcs,代码行数:25,代码来源:suite.py


示例5: test_scripts_below_regular

    def test_scripts_below_regular(self):
        tests.write_tree_from_desc('''dir: t
file: t/__init__.py
file: t/foo.py
import unittest

class Test(unittest.TestCase):

    def test_me(self):
      self.assertTrue(True)
dir: t/scripts
file: t/scripts/__init__.py
from sst import loader

discover = loader.discoverTestScripts
file: t/scripts/script.py
raise AssertionError('Loading only, executing fails')
''')
        test_loader = loader.TestLoader()
        suite = test_loader.discoverTests('t')
        self.assertEqual(2, suite.countTestCases())
        # Check which kind of tests have been discovered or we may miss regular
        # test cases seen as scripts.
        self.assertEqual(['t.foo.Test.test_me',
                          't.scripts.script'],
                         [t.id() for t in testtools.iterate_tests(suite)])
开发者ID:miing,项目名称:mci_migo_packages_selenium-simple-test,代码行数:26,代码来源:test_loader.py


示例6: _iter_tests

def _iter_tests(names):
    """
    Given a list of names, iterate through all the tests in them.
    """
    for name in names:
        suite = _load_tests(name)
        for test in iterate_tests(suite):
            yield test
开发者ID:petercolesdc,项目名称:flocker,代码行数:8,代码来源:flaky.py


示例7: test_custom_suite_without_sort_tests_works

 def test_custom_suite_without_sort_tests_works(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):pass
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([b, a], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
开发者ID:afazekas,项目名称:testtools,代码行数:8,代码来源:test_testsuite.py


示例8: test_sorts_custom_suites

 def test_sorts_custom_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):
         def sort_tests(self):
             self._tests = sorted_tests(self, True)
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([a, b], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
开发者ID:afazekas,项目名称:testtools,代码行数:10,代码来源:test_testsuite.py


示例9: test_load_tests_apply_scenarios

 def test_load_tests_apply_scenarios(self):
     suite = load_tests_apply_scenarios(
         unittest.TestLoader(),
         [self.SampleTest('test_nothing')],
         None)
     result_tests = list(testtools.iterate_tests(suite))
     self.assertEquals(
         2,
         len(result_tests),
         result_tests)
开发者ID:Julian,项目名称:testscenarios,代码行数:10,代码来源:test_scenarios.py


示例10: partition_tests

def partition_tests(suite, count):
    """Partition suite into count lists of tests."""
    # This just assigns tests in a round-robin fashion.  On one hand this
    # splits up blocks of related tests that might run faster if they shared
    # resources, but on the other it avoids assigning blocks of slow tests to
    # just one partition.  So the slowest partition shouldn't be much slower
    # than the fastest.
    partitions = [list() for _ in range(count)]
    tests = iterate_tests(suite)
    for partition, test in zip(cycle(partitions), tests):
        partition.append(test)
    return partitions
开发者ID:Noltari,项目名称:u-boot,代码行数:12,代码来源:concurrencytest.py


示例11: test_load_tests_apply_scenarios_old_style

 def test_load_tests_apply_scenarios_old_style(self):
     """Call load_tests in the way used by bzr."""
     suite = load_tests_apply_scenarios(
         [self.SampleTest('test_nothing')],
         self.__class__.__module__,
         unittest.TestLoader(),
         )
     result_tests = list(testtools.iterate_tests(suite))
     self.assertEquals(
         2,
         len(result_tests),
         result_tests)
开发者ID:Julian,项目名称:testscenarios,代码行数:12,代码来源:test_scenarios.py


示例12: load_tests

 def load_tests(*args):
     """
     Wrapper for testscenarios to set the mandatory scenarios variable
     only in case a real test loader is in place. Will be automatically
     called in case the variable "load_tests" is set.
     """
     if getattr(args[0], "suiteClass", None) is not None:
         loader, standard_tests, pattern = args
     else:
         standard_tests, module, loader = args
     for test in testtools.iterate_tests(standard_tests):
         schema_file = getattr(test, "_schema_file", None)
         if schema_file is not None:
             setattr(test, "scenarios", NegativeAutoTest.generate_scenario(schema_file))
     return testscenarios.load_tests_apply_scenarios(*args)
开发者ID:NetApp,项目名称:tempest,代码行数:15,代码来源:test.py


示例13: test_regular_and_scripts_mixed

    def test_regular_and_scripts_mixed(self):
        def regular(dir_name, name, suffix=None):
            if suffix is None:
                suffix = ''
            return '''
file: {dir_name}/{name}{suffix}
from sst import cases

class Test_{name}(cases.SSTTestCase):
    def test_{name}(self):
        pass
'''.format(**locals())

        tests.write_tree_from_desc('''dir: tests
file: tests/__init__.py
from sst import loader

discover = loader.discoverRegularTests
''')
        tests.write_tree_from_desc(regular('tests', 'test_real', '.py'))
        tests.write_tree_from_desc(regular('tests', 'test_real1', '.py'))
        tests.write_tree_from_desc(regular('tests', 'test_real2', '.py'))
        # Leading '_' => ignored
        tests.write_tree_from_desc(regular('tests', '_hidden', '.py'))
        # Not a python file => ignored
        tests.write_tree_from_desc(regular('tests', 'not-python'))
        # Some empty files
        tests.write_tree_from_desc('''
file: script1.py
file: script2.py
file: not_a_test
# '.p' is intentional, not a typoed '.py'
file: test_not_a_test.p
_hidden_too.py
''')
        test_loader = loader.TestLoader()
        suite = test_loader.discoverTests(
            '.',
            file_loader_class=loader.ScriptLoader,
            dir_loader_class=loader.ScriptDirLoader)
        self.assertEqual(['script1',
                          'script2',
                          'tests.test_real.Test_test_real.test_test_real',
                          'tests.test_real1.Test_test_real1.test_test_real1',
                          'tests.test_real2.Test_test_real2.test_test_real2'],
                         [t.id() for t in testtools.iterate_tests(suite)])
开发者ID:miing,项目名称:mci_migo_packages_selenium-simple-test,代码行数:46,代码来源:test_loader.py


示例14: partition_tests

def partition_tests(suite, count):
    # Keep tests from the same class together but allow tests from modules
    # to go to different processes to aid parallelisation.
    modules = {}
    for test in iterate_tests(suite):
        m = test.__module__ + "." + test.__class__.__name__
        if m not in modules:
            modules[m] = []
        modules[m].append(test)

    # Simply divide the test blocks between the available processes
    partitions = [list() for _ in range(count)]
    for partition, m in zip(cycle(partitions), modules):
        partition.extend(modules[m])

    # No point in empty threads so drop them
    return [p for p in partitions if p]
开发者ID:01org,项目名称:luv-yocto,代码行数:17,代码来源:concurrencytest.py


示例15: load_tests_input_scenario_utils

def load_tests_input_scenario_utils(*args):
    """
    Wrapper for testscenarios to set the scenarios to avoid running a getattr
    on the CONF object at import.
    """
    if getattr(args[0], 'suiteClass', None) is not None:
        loader, standard_tests, pattern = args
    else:
        standard_tests, module, loader = args
    scenario_utils = InputScenarioUtils()
    scenario_flavor = scenario_utils.scenario_flavors
    scenario_image = scenario_utils.scenario_images
    for test in testtools.iterate_tests(standard_tests):
        setattr(test, 'scenarios', testscenarios.multiply_scenarios(
            scenario_image,
            scenario_flavor))
    return testscenarios.load_tests_apply_scenarios(*args)
开发者ID:AminaMseddi,项目名称:tempest,代码行数:17,代码来源:utils.py


示例16: generate_scenarios

def generate_scenarios(test_or_suite):
    """Yield the tests in test_or_suite with scenario multiplication done.

    TestCase objects with no scenarios specified are yielded unaltered. Tests
    with scenarios are not yielded at all, instead the results of multiplying
    them by the scenarios they specified gets yielded.

    :param test_or_suite: A TestCase or TestSuite.
    :return: A generator of tests - objects satisfying the TestCase protocol.
    """
    for test in iterate_tests(test_or_suite):
        scenarios = getattr(test, 'scenarios', None)
        if scenarios:
            for newtest in apply_scenarios(scenarios, test):
                newtest.scenarios = None
                yield newtest
        else:
            yield test
开发者ID:Julian,项目名称:testscenarios,代码行数:18,代码来源:scenarios.py


示例17: test_discover_changing_file_matcher

    def test_discover_changing_file_matcher(self):
        tests.write_tree_from_desc('''dir: t
file: t/__init__.py
file: t/test_foo.py
import unittest

class Test(unittest.TestCase):

    def test_me(self):
      self.assertTrue(True)
dir: t/other
file: t/other/__init__.py
import unittest
from sst import loaders

def discover(test_loader, package, directory_path, names):
    suite = test_loader.loadTestsFromModule(package)
    # Change the test.*\.py rule
    fmatcher = loaders.NameMatcher(includes=['.*'])
    with loaders.NameMatchers(test_loader, fmatcher) as tl:
        suite.addTests(tl.discoverTestsFromNames(directory_path, names))
    return suite

class Test(unittest.TestCase):

    def test_in_init(self):
      self.assertTrue(True)
file: t/other/not_starting_with_test.py
import unittest

class Test(unittest.TestCase):

    def test_me(self):
      self.assertTrue(True)
''')
        test_loader = self.make_test_loader()
        suite = test_loader.discoverTestsFromTree('t')
        self.assertEqual(3, suite.countTestCases())
        self.assertEqual(['t.other.Test.test_in_init',
                          't.other.not_starting_with_test.Test.test_me',
                          't.test_foo.Test.test_me'],
                         [t.id() for t in testtools.iterate_tests(suite)])
开发者ID:DramaFever,项目名称:sst,代码行数:42,代码来源:test_loaders.py


示例18: split_suite

 def split_suite(self, suite):
     tests = list(enumerate(iterate_tests(suite)))
     return [(test, _u(str(pos))) for pos, test in tests]
开发者ID:afazekas,项目名称:testtools,代码行数:3,代码来源:test_testsuite.py


示例19: split_suite

 def split_suite(self, suite):
     tests = list(iterate_tests(suite))
     return tests[0], tests[1]
开发者ID:AIdrifter,项目名称:samba,代码行数:3,代码来源:test_testsuite.py


示例20: test_num_tests

 def test_num_tests(self):
     num_tests = len(list(iterate_tests(self.suite)))
     self.assertEqual(num_tests, 8)
开发者ID:cgoldberg,项目名称:concurrencytest,代码行数:3,代码来源:test_concurrencytest.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python testtools.RunTest类代码示例发布时间:2022-05-27
下一篇:
Python testscenarios.multiply_scenarios函数代码示例发布时间: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