当前位置: 首页>>代码示例>>Python>>正文


Python unittest.TestLoader类代码示例

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


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

示例1: TestHTMLTestRunner

class TestHTMLTestRunner(TestCase):
    
    def setUp(self):
   
        self.suite = TestSuite()
        self.loader = TestLoader()

        self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestPass))
        self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestFail))
        self.suite.addTests(self.loader.loadTestsFromModule(tests.SampleTestBasic))

        self.results_output_buffer = StringIO()
        HTMLTestRunner(stream=self.results_output_buffer).run(self.suite)
        self.byte_output = self.results_output_buffer.getvalue()

    def test_SampleTestPass(self):
        output1="".join(self.byte_output.split())
        output2="".join(SampleTestPass.EXPECTED_RESULT.split())
        self.assertGreater(output1.find(output2),0)
    
    @skip("Test Skipping")
    def test_SampleTestSkip(self):
        self.fail("This error should never be displayed")
        
    def test_SampleTestFail(self):
        output1="".join(self.byte_output.split())
        output2="".join(SampleTestFail.EXPECTED_RESULT.split())
        self.assertGreater(output1.find(output2),0)
        
    def test_SampleTestBasic(self):
        output1="".join(self.byte_output.split())
        output2="".join(SampleTestBasic.EXPECTED_RESULT.split())
        self.assertGreater(output1.find(output2),0)
开发者ID:dash0002,项目名称:HTMLTestRunner,代码行数:33,代码来源:test_HTMLTestRunner.py

示例2: load_tests

def load_tests():
    test_suite = TestSuite()
    this_dir = os.path.dirname(__file__)
    loader = TestLoader()
    package_tests = loader.discover(start_dir=this_dir)
    test_suite.addTests(package_tests)
    return test_suite
开发者ID:ricequant,项目名称:rqalpha,代码行数:7,代码来源:__init__.py

示例3: test_all

def test_all():
    loader = TestLoader()
    suite = TestSuite()
    suite.addTests(loader.loadTestsFromTestCase(TestLocale))
    suite.addTests(loader.loadTestsFromTestCase(TestExtract))
    suite.addTests(loader.loadTestsFromTestCase(TestMerge))
    return suite
开发者ID:RTOSkit,项目名称:tornado-babel,代码行数:7,代码来源:__init__.py

示例4: all

def all():
    '''
    This runs all tests and examples.  It is something of a compromise - seems
    to be the best solution that's independent of other libraries, doesn't
    use the file system (since code may be in a zip file), and keeps the
    number of required imports to a minimum.
    '''
    basicConfig(level=ERROR)
    log = getLogger('lepl._test.all.all')
    suite = TestSuite()
    loader = TestLoader()
    runner = TextTestRunner(verbosity=4)
    for module in ls_modules(lepl, MODULES):
        log.debug(module.__name__)
        suite.addTest(loader.loadTestsFromModule(module))
    result = runner.run(suite)
    print('\n\n\n----------------------------------------------------------'
          '------------\n')
    if version[0] == '2':
        print('Expect 2-5 failures + 2 errors in Python 2: {0:d}, {1:d} '
              .format(len(result.failures), len(result.errors)))
        assert 2 <= len(result.failures) <= 5, len(result.failures)
        assert 1 <= len(result.errors) <= 2, len(result.errors)
        target = TOTAL - NOT_DISTRIBUTED - NOT_3
    else:
        print('Expect at most 1 failure + 0 errors in Python 3: {0:d}, {1:d} '
              .format(len(result.failures), len(result.errors)))
        assert 0 <= len(result.failures) <= 1, len(result.failures)
        assert 0 <= len(result.errors) <= 0, len(result.errors)
        target = TOTAL - NOT_DISTRIBUTED
    print('Expect {0:d} tests total: {1:d}'.format(target, result.testsRun))
    assert result.testsRun == target, result.testsRun
    print('\nLooks OK to me!\n\n')
开发者ID:gcarothers,项目名称:lepl,代码行数:33,代码来源:__init__.py

示例5: loadTestCases

 def loadTestCases(self):
     loader = TestLoader()
     selector = QTestLoader()
     if selector.exec_():
         self.cases[:] = []
         for case in selector.selected:
             self.cases.extend(loader.loadTestsFromTestCase(case))
开发者ID:derdon,项目名称:qtestudo,代码行数:7,代码来源:qtestudo.py

示例6: discover

def discover(root_dir):
    if not os.path.exists(root_dir):
        return []

    loader = TestLoader()
    prev_dir = os.curdir
    os.chdir(root_dir)
    
    tests = loader.discover(root_dir, top_level_dir=root_dir)
    os.chdir(prev_dir)
    
    ret = []
    for suite in tests:
        for suite2 in suite:
            if suite2.__class__.__name__ == 'ModuleImportFailure':
                continue
            for test in suite2:
                name = ".".join((test.__class__.__name__, test._testMethodName))
                module = test.__module__
                ret.append([symbol(":name"), name,
                            symbol(":module"), module,
                            symbol(":root"), root_dir])

    modkey = lambda x: x[3]
    ret.sort(key=modkey)

    return [[k, list(g)] for k,g in groupby(ret, key=modkey)] # Converting to a list of lists
开发者ID:Abuelodelanada,项目名称:emacs-config,代码行数:27,代码来源:epy-unittest.py

示例7: test_suite

def test_suite():
    loader = TestLoader()
    tests = loader.loadTestsFromTestCase(PrincipalAnnotationTests)
    import zope.app.principalannotation

    tests.addTest(doctest.DocTestSuite(zope.app.principalannotation))
    return tests
开发者ID:wpjunior,项目名称:proled,代码行数:7,代码来源:tests.py

示例8: collect

    def collect(self):
        from unittest import TestLoader

        cls = self.obj
        if not getattr(cls, "__test__", True):
            return

        skipped = getattr(cls, "__unittest_skip__", False)
        if not skipped:
            self._inject_setup_teardown_fixtures(cls)
            self._inject_setup_class_fixture()

        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = TestLoader()
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            if not getattr(x, "__test__", True):
                continue
            funcobj = getimfunc(x)
            yield TestCaseFunction(name, parent=self, callobj=funcobj)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, "runTest", None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction("runTest", parent=self)
开发者ID:lfernandez55,项目名称:flask_books,代码行数:29,代码来源:unittest.py

示例9: main

def main():
    modules = ['test_360', 'test_dependencies', 'test_optional_dependencies', 'test_simple']
    simple_suite = TestSuite()
    loader = TestLoader()
    result = TestResult()
    for module in modules:
        suite = loader.loadTestsFromName(module)
        simple_suite.addTest(suite)

    print
    print 'Running simple test suite...'
    print

    simple_suite.run(result)

    print
    print 'Ran {0} tests.'.format(result.testsRun)
    print

    if len(result.errors) > 0:
        print '#########################################################'
        print 'There are {0} errors. See below for tracebacks:'.format(len(result.errors))
        print '#########################################################'
        print
        for error in result.errors:
            print error[1]
        print
        print '#########################################################'
        print 'There are {0} errors. See above for tracebacks.'.format(len(result.errors))
        print '#########################################################'
    else:
        print 'All tests passed.'
    print
开发者ID:HydroLogic,项目名称:ocgis,代码行数:33,代码来源:run_simple.py

示例10: build_suite

    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        '''
        Override the base class method to return a suite consisting of all
        TestCase subclasses throughought the whole project.
        '''
        if test_labels:
            suite = TestSuite()
        else:
            suite = DjangoTestSuiteRunner.build_suite(
                self, test_labels, extra_tests, **kwargs
            )
        added_test_classes = set(t.__class__ for t in suite)

        loader = TestLoader()
        for fname in _get_module_names(os.getcwd()):
            module = _import(_to_importable_name(fname))
            for test_class in _get_testcases(module):

                if test_class in added_test_classes:
                    continue

                for method_name in loader.getTestCaseNames(test_class):
                    testname = '.'.join([
                        module.__name__, test_class.__name__, method_name
                    ])
                    if self._test_matches(testname, test_labels):
                        suite.addTest(loader.loadTestsFromName(testname))
                        added_test_classes.add(test_class)

        return reorder_suite(suite, (TestCase,))
开发者ID:bloodearnest,项目名称:extending_unittest,代码行数:30,代码来源:all_dirs_runner.py

示例11: TestGroup

class TestGroup(object):
    def __init__(self, name, classnames=None, groupSetUp=lambda:None, groupTearDown=lambda:None):
        self.name = name
        self._classes = {}
        for classname in (classnames or []):
            self._loadClass(classname)
        self._loader = TestLoader()
        self.setUp = groupSetUp
        self.tearDown = groupTearDown

    def _loadClass(self, classname):
        moduleName, className = classname.rsplit('.', 1)
        cls = getattr(__import__(moduleName, globals(), locals(), [className]), className)
        self._classes[className] = cls

    def createSuite(self, testnames=None):
        if not testnames:
            testnames = sorted(self._classes.keys())
        suite = TestSuite()
        for testname in testnames:
            testcase = testname.split('.')
            testclass = self._classes.get(testcase[0], None)
            if not testclass:
                continue
            if len(testcase) == 1:
                suite.addTest(self._loader.loadTestsFromTestCase(testclass))
            else:
                suite.addTest(self._loader.loadTestsFromName(testcase[1], testclass))
        return suite
开发者ID:seecr,项目名称:meresco-triplestore,代码行数:29,代码来源:testrunner.py

示例12: run

 def run(self):
     where = os.path.join('pythran', 'tests')
     try:
         import py
         import xdist
         import multiprocessing
         cpu_count = multiprocessing.cpu_count()
         args = ["-n", str(cpu_count), where]
         if self.failfast:
             args.insert(0, '-x')
         if self.cov:
             try:
                 import pytest_cov
                 args = ["--cov-report", "html",
                         "--cov-report", "annotate",
                         "--cov", "pythran"] + args
             except ImportError:
                 print ("W: Skipping coverage analysis, pytest_cov"
                         "not found")
         py.test.cmdline.main(args)
     except ImportError:
         print ("W: Using only one thread, "
                 "try to install pytest-xdist package")
         loader = TestLoader()
         t = TextTestRunner(failfast=self.failfast)
         t.run(loader.discover(where))
开发者ID:franckCJ,项目名称:pythran,代码行数:26,代码来源:setup.py

示例13: collect

    def collect(self):
        from unittest import TestLoader

        cls = self.obj
        if not getattr(cls, "__test__", True):
            return
        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = TestLoader()
        module = self.getparent(Module).obj
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            if not getattr(x, "__test__", True):
                continue
            funcobj = getattr(x, "im_func", x)
            transfer_markers(funcobj, cls, module)
            yield TestCaseFunction(name, parent=self, callobj=funcobj)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, "runTest", None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction("runTest", parent=self)
开发者ID:kalekundert,项目名称:pytest,代码行数:25,代码来源:unittest.py

示例14: suite

def suite():
    """Suite of TestCases for Django"""
    suite = TestSuite()
    loader = TestLoader()

    test_cases = (ManagersTestCase, EntryTestCase,
                  LoadModelClassTestCase, SignalsTestCase,
                  EntryHtmlContentTestCase, CategoryTestCase,
                  ZinniaViewsTestCase, ZinniaFeedsTestCase,
                  ZinniaSitemapsTestCase, ComparisonTestCase,
                  DirectoryPingerTestCase, ExternalUrlsPingerTestCase,
                  TemplateTagsTestCase, QuickEntryTestCase,
                  URLShortenerTestCase, EntryCommentModeratorTestCase,
                  ZinniaCustomDetailViews, SpamCheckerTestCase,
                  EntryAdminTestCase, CategoryAdminTestCase,
                  MixinTestCase, LongEnoughTestCase,
                  AuthorTestCase, FlagsTestCase,
                  AuthorListFilterTestCase, CategoryListFilterTestCase,
                  TranslatedURLsTestCase, EntryAbsoluteUrlTestCase,
                  MarkupsTestCase, FailImportMarkupTestCase,
                  PingBackTestCase, MetaWeblogTestCase,
                  HTMLPreviewTestCase,
                  EntryAdminFormTestCase, CategoryAdminFormTestCase,
                  MPTTModelChoiceIteratorTestCase,
                  MPTTModelMultipleChoiceFieldTestCase,
                  MPTTFilteredSelectMultipleTestCase
                  )

    for test_class in test_cases:
        tests = loader.loadTestsFromTestCase(test_class)
        suite.addTests(tests)

    return suite
开发者ID:nffdiogosilva,项目名称:django-blog-zinnia,代码行数:33,代码来源:__init__.py

示例15: run

 def run(self):
     """
     Finds and executes unit tests in the 'tests' subdir.
     Because TestLoader imports the tests as a module this method
     automatically creates/updates the 'tests/__init__.py' to
     import all python scripts in the 'tests' subdir.
     """
     self.run_command('build')
     sys.path.insert(0,os.path.join(os.getcwd(),"build","lib"))
     self.tests  = []
     # make sure the 'tests' subdir actually exists.
     if not os.path.isdir(self.tests_dir):
         print "ExecuteTests: <Error> 'tests' subdir not found!"
     else:
         self.find_tests()
         self.gen_tests_init()
         # create a test suite.
         tests = TestLoader().loadTestsFromNames([t[0] for t in self.tests])
         if not self.filter is None:
             tests = self.filter_tests(tests)
         # run the test suite if it actually contains test cases.
         run_verbosity = 2
         if self.verbose == 0:
             run_verbosity = 0
         if tests.countTestCases() > 0:
             runner = TextTestRunner(verbosity=run_verbosity)
             runner.run(tests)
         else:
             print "ExecuteTests: <Warning> No test cases found!"
     sys.path.pop(0)
开发者ID:ahota,项目名称:visit_intel,代码行数:30,代码来源:setup_tests.py


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