コード例 #1
0
ファイル: __init__.py プロジェクト: rbtcollins/shellvars
def load_tests(loader, tests, pattern):
    this_dir = os.path.dirname(__file__)
    tests.addTests(loader.discover(start_dir=this_dir, pattern=pattern))
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
    tests.addTest(
        doctest.DocFileSuite("../../README.rst", optionflags=doctest.ELLIPSIS))
    return loader.suiteClass(generate_scenarios(tests))
コード例 #2
0
def load_tests(loader, tests, pattern):
    this_dir = os.path.dirname(__file__)
    tests.addTests(loader.discover(start_dir=this_dir, pattern=pattern))
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
    tests.addTest(
        doctest.DocFileSuite("../../README.rst", optionflags=doctest.ELLIPSIS))
    return loader.suiteClass(generate_scenarios(tests))
コード例 #3
0
ファイル: tests.py プロジェクト: Zojax/zojax.skintool
def FunctionalDocFileSuite(*paths, **kw):
    globs = kw.setdefault('globs', {})
    globs['sync'] = functional.sync
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        root['intid'] = IntIds()
        component.provideUtility(root['intid'], IIntIds)

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old
                             | doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = zojaxSkinTool
    return suite
コード例 #4
0
ファイル: tests.py プロジェクト: Zojax/zojax.error
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxErrorLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #5
0
ファイル: tests.py プロジェクト: Zojax/zojax.content.model
def FunctionalModelDocFileSuite(*paths, **kw):
    globs = kw.setdefault('globs', {})
    globs['getRootFolder'] = functional.getRootFolder

    kwsetUp = kw.get('setUp')
    def setUp(test):
        root = functional.getRootFolder()
        if 'content' not in root:
            root['content'] = content.MyContent(u'My Content')

        if 'container' not in root:
            root['container'] = content.MyContentContainer(u'My Content Container')
            root['container']['content1'] = content.MyContent(u'My Content 1')
            root['container']['content2'] = content.MyContent(u'My Content 2')
            root['container']['content3'] = content.MyContent(u'My Content 3')

    kw['setUp'] = setUp
    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old
                             | doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = kw.get('layer', zojaxContentModelLayout)
    return suite
コード例 #6
0
ファイル: _doctest.py プロジェクト: jamesjer/zope.testrunner
    def global_setup(self):
        options = self.runner.options
        output = options.output

        self.old_reporting_flags = doctest.set_unittest_reportflags(0)

        reporting_flags = 0
        if options.ndiff:
            reporting_flags = doctest.REPORT_NDIFF
        if options.udiff:
            if reporting_flags:
                output.error(
                    "Can only give one of --ndiff, --udiff, or --cdiff")
                sys.exit(1)
            reporting_flags = doctest.REPORT_UDIFF
        if options.cdiff:
            if reporting_flags:
                output.error(
                    "Can only give one of --ndiff, --udiff, or --cdiff")
                sys.exit(1)
            reporting_flags = doctest.REPORT_CDIFF
        if options.report_only_first_failure:
            reporting_flags |= doctest.REPORT_ONLY_FIRST_FAILURE

        if reporting_flags:
            doctest.set_unittest_reportflags(reporting_flags)
コード例 #7
0
ファイル: tests.py プロジェクト: Zojax/zojax.project
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxBloggerLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        newInteraction()

        root = functional.getRootFolder()
        setSite(root)
        sm = root.getSiteManager()
        sm.getUtility(INameChooserConfiglet).short_url_enabled = True

        # IIntIds
        root['ids'] = IntIds()
        sm.registerUtility(root['ids'], IIntIds)
        root['ids'].register(root)

        # catalog
        root['catalog'] = Catalog()
        sm.registerUtility(root['catalog'], ICatalog)

        # space
        space = ContentSpace(title=u'Space')
        event.notify(ObjectCreatedEvent(space))
        root['space'] = space

        # people
        people = PersonalSpaceManager(title=u'People')
        event.notify(ObjectCreatedEvent(people))
        root['people'] = people
        sm.registerUtility(root['people'], IPersonalSpaceManager)

        endInteraction()

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #8
0
ファイル: tests.py プロジェクト: Zojax/zojax.cynin.xmlrpc
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxContentXMLRPCLayer

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()
        root = functional.getRootFolder()
        setSite(root)
        setattr(root, 'title', 'Test Site')

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #9
0
def _prepare_doctest_keywords(kw):
    globs = kw.setdefault('globs', {})
    globs['http'] = HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()
        if kwsetUp is not None:
            kwsetUp(test)
    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        if kwtearDown is not None:
            kwtearDown(test)
        functional.FunctionalTestSetup().tearDown()
    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old
                             | doctest.ELLIPSIS
                             | doctest.REPORT_NDIFF
                             | doctest.NORMALIZE_WHITESPACE)
コード例 #10
0
ファイル: tests.py プロジェクト: Zojax/zojax.preferences
def FunctionalDocFileSuite(*paths, **kw):
    globs = kw.setdefault('globs', {})
    globs['sync'] = functional.sync
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        root['principalannotation'] = PrincipalAnnotationUtility()
        root.getSiteManager().registerUtility(
            root['principalannotation'], IPrincipalAnnotationUtility)

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old
                             | doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = zojaxPreferences
    return suite
コード例 #11
0
ファイル: tests.py プロジェクト: Zojax/zojax.content.actions
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxContentActionsLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)
        setUpCache()

        sm = root.getSiteManager()

        # IIntIds
        root['ids'] = IntIds()
        sm.registerUtility(root['ids'], IIntIds)
        root['ids'].register(root)

        # catalog
        root['catalog'] = Catalog()
        sm.registerUtility(root['catalog'], ICatalog)

        # people
        root['people'] = PersonalSpaceManager()
        sm.registerUtility(root['people'], IPersonalSpaceManager)

        # space
        space = ContentSpace(title=u'Space')
        event.notify(ObjectCreatedEvent(space))
        root['space'] = space
        interface.directlyProvides(root['space'], IDoNotCacheActionsPortlet)

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        tearDownCache()
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #12
0
ファイル: __init__.py プロジェクト: frankk00/realtor
def main():
    try:
        doctest.register_optionflag
    except:
        print(
            "\n"
            "The regression test suite requires a more recent version of\n"
            "doctest (e.g., the version that ships with Python 2.4 or 2.5).\n"
            "Please place a new version of doctest on your path before \n"
            "running the test suite.\n")
        return

    PY24 = doctest.register_optionflag('PYTHON2.4')
    """Flag indicating that a doctest example requires Python 2.4+"""

    PY25 = doctest.register_optionflag('PYTHON2.5')
    """Flag indicating that a doctest example requires Python 2.5+"""
    class DocTestParser(doctest.DocTestParser):
        """
        Custom doctest parser that adds support for two new flags
        +PYTHON2.4 and +PYTHON2.5.
        """
        def parse(self, string, name='<string>'):
            pieces = doctest.DocTestParser.parse(self, string, name)
            for i, val in enumerate(pieces):
                if (isinstance(val, doctest.Example) and
                    ((val.options.get(PY24, False) and sys.version[:2] <
                      (2, 4)) or
                     (val.options.get(PY25, False) and sys.version[:2] <
                      (2, 5)))):
                    pieces[i] = doctest.Example('1', '1')
            return pieces

    # Turn on debugging.
    epydoc.DEBUG = True

    # Options for doctest:
    options = doctest.ELLIPSIS
    doctest.set_unittest_reportflags(doctest.REPORT_UDIFF)

    # Use a custom parser
    parser = DocTestParser()

    # Find all test cases.
    tests = []
    testdir = os.path.join(os.path.split(__file__)[0])
    if testdir == '': testdir = '.'
    for filename in os.listdir(testdir):
        if (filename.endswith('.doctest')
                and check_requirements(os.path.join(testdir, filename))):
            tests.append(
                doctest.DocFileSuite(filename,
                                     optionflags=options,
                                     parser=parser))

    # Run all test cases.
    unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests))
コード例 #13
0
ファイル: __init__.py プロジェクト: Afey/QuantSoftwareToolkit
def main():
    try:
        doctest.register_optionflag
    except:
        print ("\n"
            "The regression test suite requires a more recent version of\n"
            "doctest (e.g., the version that ships with Python 2.4 or 2.5).\n"
            "Please place a new version of doctest on your path before \n"
            "running the test suite.\n")
        return
                          
    
    PY24 = doctest.register_optionflag('PYTHON2.4')
    """Flag indicating that a doctest example requires Python 2.4+"""
    
    PY25 = doctest.register_optionflag('PYTHON2.5')
    """Flag indicating that a doctest example requires Python 2.5+"""
    
    class DocTestParser(doctest.DocTestParser):
        """
        Custom doctest parser that adds support for two new flags
        +PYTHON2.4 and +PYTHON2.5.
        """
        def parse(self, string, name='<string>'):
            pieces = doctest.DocTestParser.parse(self, string, name)
            for i, val in enumerate(pieces):
                if (isinstance(val, doctest.Example) and
                    ((val.options.get(PY24, False) and
                      sys.version[:2] < (2,4)) or
                     (val.options.get(PY25, False) and
                      sys.version[:2] < (2,5)))):
                    pieces[i] = doctest.Example('1', '1')
            return pieces

    # Turn on debugging.
    epydoc.DEBUG = True
    
    # Options for doctest:
    options = doctest.ELLIPSIS
    doctest.set_unittest_reportflags(doctest.REPORT_UDIFF)

    # Use a custom parser
    parser = DocTestParser()
    
    # Find all test cases.
    tests = []
    testdir = os.path.join(os.path.split(__file__)[0])
    if testdir == '': testdir = '.'
    for filename in os.listdir(testdir):
        if (filename.endswith('.doctest') and
            check_requirements(os.path.join(testdir, filename))):
            tests.append(doctest.DocFileSuite(filename, optionflags=options,
                                              parser=parser))
            
    # Run all test cases.
    unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests))
コード例 #14
0
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxPersistentFieldsLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)

        # IIntIds
        root['ids'] = IntIds()
        root.getSiteManager().registerUtility(root['ids'], IIntIds)

        # HomeFolderManager
        manager = PersonalSpaceManager(title=u'People')
        event.notify(ObjectCreatedEvent(manager))

        root['people'] = manager
        root.getSiteManager().registerUtility(root['people'], IPersonalSpaceManager)

        principal = root.getSiteManager().getUtility(
            IAuthentication).getPrincipal('zope.user')

        manager.assignPersonalSpace(principal)

        # profiles category
        configlet = component.getUtility(IProfilesCategory)
        configlet.fieldCategories = [u'Category1', u'Category2']


    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #15
0
def FunctionalDocFileSuite(*paths, **kw):
    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)
        sm = root.getSiteManager()

        root['ids'] = IntIds()
        sm.registerUtility(root['ids'], IIntIds)

        root['catalog'] = Catalog()
        sm.registerUtility(root['catalog'], ICatalog)

        authconfig = sm.getUtility(IAuthenticationConfiglet)
        authconfig.installUtility()

        auth = sm.getUtility(IAuthentication)
        auth._cache = False
        auth.prefix = u'test.'
        auth.authenticatorPlugins = tuple(auth.authenticatorPlugins) + ('principal.users',)

        authfactory = sm.getUtility(IAuthenticatorPluginFactory, name='principal.users')
        authfactory.install()

        if kwsetUp is not None:
            kwsetUp(test)

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        if kwtearDown is not None:
            kwtearDown(test)
        functional.FunctionalTestSetup().tearDown()
    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old
                             | doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = zojaxPrincipalManagement
    return suite
コード例 #16
0
def FunctionalDocFileSuite(*paths, **kw):
    layer = personalFavoritesLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)
        sm = root.getSiteManager()

        # IIntIds
        root['ids'] = IntIds()
        sm.registerUtility(root['ids'], IIntIds)
        root['ids'].register(root)

        # catalog
        root['catalog'] = Catalog()
        sm.registerUtility(root['catalog'], ICatalog)

        # people
        root['people'] = PersonalSpaceManager()
        sm.registerUtility(root['people'], IPersonalSpaceManager)

        user = sm.getUtility(IAuthentication).getPrincipal('zope.mgr')
        root['people'].assignPersonalSpace(user)

        user = sm.getUtility(IAuthentication).getPrincipal('zope.user1')
        root['people'].assignPersonalSpace(user)

        user = sm.getUtility(IAuthentication).getPrincipal('zope.user2')
        root['people'].assignPersonalSpace(user)

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #17
0
ファイル: __init__.py プロジェクト: RolfAndreassen/wiredtiger
def load_tests(standard_tests, module, loader):
    test_modules = [
        'testcase',
        'scenarios',
        ]
    prefix = "testscenarios.tests.test_"
    test_mod_names = [prefix + test_module for test_module in test_modules]
    standard_tests.addTests(loader.loadTestsFromNames(test_mod_names))
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
    standard_tests.addTest(doctest.DocFileSuite("../../../README"))
    return standard_tests
コード例 #18
0
ファイル: __init__.py プロジェクト: 571451370/devstack_mitaka
def load_tests(standard_tests, module, loader):
    test_modules = [
        'testcase',
        'scenarios',
        ]
    prefix = "testscenarios.tests.test_"
    test_mod_names = [prefix + test_module for test_module in test_modules]
    standard_tests.addTests(loader.loadTestsFromNames(test_mod_names))
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
    standard_tests.addTest(
        doctest.DocFileSuite("../../README", optionflags=doctest.ELLIPSIS))
    return loader.suiteClass(testscenarios.generate_scenarios(standard_tests))
コード例 #19
0
ファイル: tests.py プロジェクト: Zojax/zojax.formulator
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxFormulatorLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        portal = Portal()
        event.notify(ObjectCreatedEvent(portal))
        root['portal'] = portal
        sm = LocalSiteManager(portal)
        portal.setSiteManager(sm)
        setSite(portal)
        sm = portal.getSiteManager()
        portal['ids'] = IntIds()
        sm.registerUtility(portal['ids'], IIntIds)

        portal['catalog'] = Catalog()
        sm.registerUtility(portal['catalog'], ICatalog)

        authconfiglet = sm.getUtility(IAuthenticationConfiglet)
        authconfiglet.installUtility()

        sm.getUtility(IAuthentication)._caching = False




    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #20
0
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxContentUrlmapperLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)

        # default content
        content = Content1()
        event.notify(ObjectCreatedEvent(content))
        root['content11'] = content

        content = Content1()
        event.notify(ObjectCreatedEvent(content))
        root['content12'] = content

        content = Content2()
        event.notify(ObjectCreatedEvent(content))
        root['content21'] = content

        content = Content2()
        event.notify(ObjectCreatedEvent(content))
        root['content22'] = content


    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #21
0
ファイル: tests.py プロジェクト: Zojax/zojax.content.revision
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxContentRevision

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kwsetUp = kw.get('setUp')

    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        eventSetUp()

        root = functional.getRootFolder()
        setSite(root)
        sm = root.getSiteManager()

        # IIntIds
        root['ids'] = IntIds()
        sm.registerUtility(root['ids'], IIntIds)
        root['ids'].register(root)

        # catalog
        root['catalog'] = Catalog()
        sm.registerUtility(root['catalog'], ICatalog)

        # catalog
        root['content'] = Content()
        sm.registerUtility(root['content'], IContent)


    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')

    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old | doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #22
0
ファイル: tests.py プロジェクト: Zojax/zojax.personal.content
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxPersonalContentLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)

        # IIntIds
        root['ids'] = IntIds()
        root.getSiteManager().registerUtility(root['ids'], IIntIds)

        # catalog
        root['catalog'] = Catalog()
        root.getSiteManager().registerUtility(root['catalog'], ICatalog)

        # home folder manager
        manager = PersonalSpaceManager(title=u'People')
        event.notify(ObjectCreatedEvent(manager))

        root['people'] = manager
        root.getSiteManager().registerUtility(root['people'], IPersonalSpaceManager)


    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #23
0
def load_tests(loader, standard_tests, pattern):
    test_modules = [
        'callmany',
        'fixture',
        'testcase',
    ]
    prefix = "fixtures.tests.test_"
    test_mod_names = [prefix + test_module for test_module in test_modules]
    standard_tests.addTests(loader.loadTestsFromNames(test_mod_names))
    standard_tests.addTests(
        loader.loadTestsFromName('fixtures.tests._fixtures'))
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
    standard_tests.addTest(doctest.DocFileSuite("../../README"))
    return standard_tests
コード例 #24
0
ファイル: tests.py プロジェクト: Zojax/zojax.hubspot
def FunctionalDocFileSuite(*paths, **kw):
    layer = hubspot

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        newInteraction()

        root = functional.getRootFolder()
        setSite(root)
        sm = root.getSiteManager()

        # IIntIds
        root['ids'] = IntIds()
        sm.registerUtility(root['ids'], IIntIds)
        root['ids'].register(root)

        # space
        space = ContentSpace(title=u'Space')
        event.notify(ObjectCreatedEvent(space))
        root['space'] = space

        endInteraction()

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #25
0
ファイル: __init__.py プロジェクト: greghicks01/selenium
def main():
    # Options for doctest:
    options = doctest.ELLIPSIS
    doctest.set_unittest_reportflags(doctest.REPORT_UDIFF)

    # Find all test cases.
    tests = []
    testdir = os.path.join(os.path.split(__file__)[0])
    if testdir == '': testdir = '.'
    for filename in os.listdir(testdir):
        if filename.endswith('.doctest'):
            tests.append(doctest.DocFileSuite(filename, optionflags=options))
            
    # Run all test cases.
    unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests))
コード例 #26
0
ファイル: command.py プロジェクト: dlocke/unitable
def selftest(verbose=0):
  log.warning('selftests may report false errors on non-linux or non-32 bit machines')
  testmods = ['asarray', 'storage', 'unitable', 'evaltbl', 'rules', 'wrappers']
  for mod in testmods:
    __import__(mod)

  import unittest
  import doctest
  if not verbose:
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
  flags =  doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS

  suite = unittest.TestSuite()
  for mod in testmods:
    suite.addTest(doctest.DocTestSuite(mod,optionflags=flags))
  runner = unittest.TextTestRunner()
  return runner.run(suite)
コード例 #27
0
ファイル: command.py プロジェクト: Huskyeder/augustus
def selftest(verbose=0):
  log.warning('selftests may report false errors on non-linux or non-32 bit machines')
  testmods = ['asarray', 'storage', 'unitable', 'evaltbl', 'rules', 'wrappers']
  for mod in testmods:
    __import__(mod)

  import unittest
  import doctest
  if not verbose:
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
  flags =  doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS

  suite = unittest.TestSuite()
  for mod in testmods:
    suite.addTest(doctest.DocTestSuite(mod,optionflags=flags))
  runner = unittest.TextTestRunner()
  return runner.run(suite)
コード例 #28
0
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxPersonalPhotoalbumLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))
    global oldMethod
    oldMethod = utils.checkPermissionForPrincipal.func_code
    utils.checkPermissionForPrincipal.func_code = checkPermissionForPrincipal.func_code

    kwsetUp = kw.get('setUp')

    def setUp(test):
        functional.FunctionalTestSetup().setUp()
        newInteraction()
        root = functional.getRootFolder()
        setSite(root)
        sm = root.getSiteManager()
        auth = sm.getUtility(IAuthentication)
        p = auth.getPrincipal('zope.mgr')
        setattr(root, 'principal', p)
        setattr(root, 'owner', p)
        endInteraction()

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')

    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old | doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #29
0
ファイル: tests.py プロジェクト: Zojax/zojax.principal.roles
def FunctionalDocFileSuite(*paths, **kw):
    globs = kw.setdefault('globs', {})
    globs['sync'] = sync
    globs['getRootFolder'] = getRootFolder

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        FunctionalTestSetup().setUp()

        root = getRootFolder()
        setSite(root)

        root['ids'] = IntIds()
        root.getSiteManager().registerUtility(root['ids'], IIntIds)

        root['catalog'] = Catalog()
        root.getSiteManager().registerUtility(root['catalog'], ICatalog)


    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old
                             | doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE)

    layer = kw.get('layer', Functional)
    if 'layer' in kw:
        del kw['layer']

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #30
0
ファイル: __init__.py プロジェクト: SvenDowideit/clearlinux
def load_tests(loader, standard_tests, pattern):
    test_modules = [
        'callmany',
        'fixture',
        'testcase',
        ]
    prefix = "fixtures.tests.test_"
    test_mod_names = [prefix + test_module for test_module in test_modules]
    standard_tests.addTests(loader.loadTestsFromNames(test_mod_names))
    if sys.version_info >= (2, 7):
        # 2.7 calls load_tests for us
        standard_tests.addTests(loader.loadTestsFromName('fixtures.tests._fixtures'))
    else:
        # We need to call it ourselves.
        standard_tests.addTests(fixtures.tests._fixtures.load_tests(
            loader, loader.loadTestsFromName('fixtures.tests._fixtures'), pattern))
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
    standard_tests.addTest(doctest.DocFileSuite("../../README"))
    return standard_tests
コード例 #31
0
ファイル: tests.py プロジェクト: Zojax/zojax.principal.field
def FunctionalDocFileSuite(*paths, **kw):
    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)

        root['ids'] = IntIds()
        root.getSiteManager().registerUtility(root['ids'], IIntIds)

        root['catalog'] = Catalog()
        root.getSiteManager().registerUtility(root['catalog'], ICatalog)

        if kwsetUp is not None:
            kwsetUp(test)

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        if kwtearDown is not None:
            kwtearDown(test)
        functional.FunctionalTestSetup().tearDown()
    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old
                             | doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = zojaxPrincipalField
    return suite
コード例 #32
0
ファイル: tests.py プロジェクト: Zojax/zojax.batching
def FunctionalDocFileSuite(*paths, **kw):
    layer = batchingLayer

    def setUp(test):
        functional.FunctionalTestSetup().setUp()

    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['setUp'] = setUp
    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old | doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #33
0
ファイル: __init__.py プロジェクト: 571451370/devstack_mitaka
def load_tests(loader, standard_tests, pattern):
    test_modules = [
        'callmany',
        'fixture',
        'testcase',
    ]
    prefix = "fixtures.tests.test_"
    test_mod_names = [prefix + test_module for test_module in test_modules]
    standard_tests.addTests(loader.loadTestsFromNames(test_mod_names))
    if sys.version_info >= (2, 7):
        # 2.7 calls load_tests for us
        standard_tests.addTests(
            loader.loadTestsFromName('fixtures.tests._fixtures'))
    else:
        # We need to call it ourselves.
        standard_tests.addTests(
            fixtures.tests._fixtures.load_tests(
                loader, loader.loadTestsFromName('fixtures.tests._fixtures'),
                pattern))
    doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)
    standard_tests.addTest(doctest.DocFileSuite("../../README"))
    return standard_tests
コード例 #34
0
    def global_setup(self):
        options = self.runner.options
        output = options.output

        self.old_reporting_flags = doctest.set_unittest_reportflags(0)

        reporting_flags = 0
        if options.ndiff:
            reporting_flags = doctest.REPORT_NDIFF
        if options.udiff:
            if reporting_flags:
                output.error("Can only give one of --ndiff, --udiff, or --cdiff")
                sys.exit(1)
            reporting_flags = doctest.REPORT_UDIFF
        if options.cdiff:
            if reporting_flags:
                output.error("Can only give one of --ndiff, --udiff, or --cdiff")
                sys.exit(1)
            reporting_flags = doctest.REPORT_CDIFF
        if options.report_only_first_failure:
            reporting_flags |= doctest.REPORT_ONLY_FIRST_FAILURE

        if reporting_flags:
            doctest.set_unittest_reportflags(reporting_flags)
コード例 #35
0
ファイル: test.py プロジェクト: HomeRad/TorCleaner
        ignoremods = ['test']
        ignoredirs = [sys.prefix, sys.exec_prefix]
        tracer = trace.Trace(count=True, trace=False,
                    ignoremods=ignoremods, ignoredirs=ignoredirs)

    # Finding and importing
    test_files = get_test_files(cfg)
    if cfg.list_tests or cfg.run_tests:
        test_cases = get_test_cases(test_files, cfg, tracer=tracer)

    # Configure doctests
    if cfg.first_doctest_failure:
        import doctest
        # The doctest module in Python 2.3 does not have this feature
        if hasattr(doctest, 'REPORT_ONLY_FIRST_FAILURE'):
            doctest.set_unittest_reportflags(doctest.REPORT_ONLY_FIRST_FAILURE)

    # Configure the logging module
    import logging
    logging.basicConfig()
    logging.root.setLevel(logging.CRITICAL)

    # Running
    success = True
    if cfg.list_files:
        baselen = len(cfg.basedir) + 1
        print "\n".join([fn[baselen:] for fn in test_files])
    if cfg.list_tests:
        print "\n".join([test.id() for test in test_cases])
    if cfg.run_tests:
        run_tests(cfg, test_cases, tracer)
コード例 #36
0
import doctest

import transaction

from plone.app.testing import TEST_USER_ID
from plone.testing import layered
from plone.testing.z2 import Browser

from Products.CMFPlomino.testing import PRODUCTS_CMFPLOMINO_FUNCTIONAL_TESTING

OPTIONFLAGS = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE

doctest.set_unittest_reportflags(doctest.REPORT_NDIFF
                                 | doctest.REPORT_ONLY_FIRST_FAILURE)


def test_suite():
    suite = doctest.DocFileSuite(
        'plomino.txt',
        'plomino_accesscontrol.txt',
        # 'samples.txt',
        # 'plomino_usage.txt',
        # 'form-resources.txt',
        # 'searchableview.txt',
        globs={
            'TEST_USER_ID': TEST_USER_ID,
            'Browser': Browser,
            'transaction': transaction
        },
        optionflags=OPTIONFLAGS)
    return layered(suite, layer=PRODUCTS_CMFPLOMINO_FUNCTIONAL_TESTING)
コード例 #37
0
ファイル: tests.py プロジェクト: Zojax/zojax.content.jsonrpc
def FunctionalDocFileSuite(*paths, **kw):
    layer = zojaxContentJSONRPCLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')
    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        root = functional.getRootFolder()
        setSite(root)

        # IIntIds
        root['ids'] = IntIds()

        root.getSiteManager().registerUtility(root['ids'], IIntIds)

        # catalog
        root['catalog'] = Catalog()
        root.getSiteManager().registerUtility(root['catalog'], ICatalog)

        # default content
        content = Content1('Content 1')
        event.notify(ObjectCreatedEvent(content))
        IOwnership(content).ownerId = 'zope.user'
        root['content11'] = content

        content = Content1('Content 2')
        event.notify(ObjectCreatedEvent(content))
        IOwnership(content).ownerId = 'zope.user'
        root['content12'] = content

        content = Content2('Content 3')
        event.notify(ObjectCreatedEvent(content))
        IOwnership(content).ownerId = 'zope.user'
        root['content21'] = content

        content = Content2('Content 4')
        event.notify(ObjectCreatedEvent(content))
        IOwnership(content).ownerId = 'zope.user'
        root['content22'] = content


    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')
    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old|doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #38
0
"""
A file to ease a bit the testing framework
"""
import doctest
doctest.set_unittest_reportflags(doctest.REPORT_NDIFF)

コード例 #39
0
def FunctionalDocFileSuite(*paths, **kw):
    layer = AcknowledgementLayer

    globs = kw.setdefault('globs', {})
    globs['http'] = functional.HTTPCaller()
    globs['getRootFolder'] = functional.getRootFolder
    globs['sync'] = functional.sync

    kw['package'] = doctest._normalize_module(kw.get('package'))

    kwsetUp = kw.get('setUp')

    def setUp(test):
        functional.FunctionalTestSetup().setUp()

        newInteraction()

        def fake_utcnow(self):
            return datetime.datetime(2015, 7, 30, 8, 0, 0)

        curse(datetime.datetime, 'utcnow', classmethod(fake_utcnow))

        root = functional.getRootFolder()
        setSite(root)
        sm = root.getSiteManager()

        # IIntIds
        root['intids'] = IntIds()
        sm.registerUtility(root['intids'], IIntIds)
        root['intids'].register(root)

        # catalog
        root['catalog'] = Catalog()
        sm.registerUtility(root['catalog'], ICatalog)

        # PluggableAuthentication
        pau = PluggableAuthentication(u'')
        event.notify(ObjectCreatedEvent(pau))
        sm[u'auth'] = pau
        sm.registerUtility(pau, IAuthentication)

        # Credentials Plugin
        defaultCreds.install()
        defaultCreds.activate()

        # people
        people = PersonalSpaceManager(title=u'People')
        event.notify(ObjectCreatedEvent(people))
        root['people'] = people
        sm.registerUtility(root['people'], IPersonalSpaceManager)

        user = sm.getUtility(IAuthentication).getPrincipal('zope.mgr')
        people.assignPersonalSpace(user)

        user = sm.getUtility(IAuthentication).getPrincipal('zope.user')
        people.assignPersonalSpace(user)

        # default content
        content = Content(u'Content1', u'Some Content1')
        event.notify(ObjectCreatedEvent(content))
        IOwnership(content).ownerId = 'zope.user'
        root['content1'] = content

        content = Content(u'Content2', u'Some Content2')
        event.notify(ObjectCreatedEvent(content))
        IOwnership(content).ownerId = 'zope.user'
        root['content2'] = content

        endInteraction()

    kw['setUp'] = setUp

    kwtearDown = kw.get('tearDown')

    def tearDown(test):
        setSite(None)
        functional.FunctionalTestSetup().tearDown()
        # datetime_patcher.stop()

    kw['tearDown'] = tearDown

    if 'optionflags' not in kw:
        old = doctest.set_unittest_reportflags(0)
        doctest.set_unittest_reportflags(old)
        kw['optionflags'] = (old | doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE)

    suite = doctest.DocFileSuite(*paths, **kw)
    suite.layer = layer
    return suite
コード例 #40
0
ファイル: __init__.py プロジェクト: tristanlatr/epydoc
def main():
    try:
        addflag = doctest.register_optionflag
    except:
        print(
            "\n"
            "The regression test suite requires a more recent version of\n"
            "doctest (e.g., the version that ships with Python 2.4 or 2.5).\n"
            "Please place a new version of doctest on your path before \n"
            "running the test suite.\n")
        return

    py_versions = [(2, 4), (2, 5), (2, 7), (3, 0), (3, 4), (3, 5), (3, 6),
                   (3, 7)]

    # converts tuple to dotted version string
    def t2v(t):
        return '.'.join([str(x) for x in t])

    # Define PYTHON#.# and PYMIN#.# option flags
    py_min_flags = [(addflag('PYTHON%s' % t2v(x)), x)
                    for x in py_versions] + [(addflag('PYMIN%s' % t2v(x)), x)
                                             for x in py_versions]

    # Define PYMAX#.# option flags
    py_max_flags = [(addflag('PYMAX%s' % t2v(x)), x) for x in py_versions]

    class DocTestParser(doctest.DocTestParser):
        """
        Custom doctest parser that adds support for required-python flags
        +PYTHON2.4, +PYTHON2.4, +PYTHON2.7, +PYTHON3.0, etc...
        """
        def parse(self, string, name='<string>'):
            pieces = doctest.DocTestParser.parse(self, string, name)
            for i, val in enumerate(pieces):
                if (isinstance(val, doctest.Example)
                        and not self.py_version_suitable(val)):
                    pieces[i] = doctest.Example('1', '1')
            return pieces

        def py_version_suitable(self, example):
            for item in py_min_flags:
                if (example.options.get(item[0], False)
                        and sys.version_info < item[1]):
                    return False
            for item in py_max_flags:
                if (example.options.get(item[0], False)
                        and sys.version_info > item[1]):
                    return False
            return True

    # Turn on debugging.
    epydoc.DEBUG = True

    # Options for doctest:
    options = doctest.ELLIPSIS
    doctest.set_unittest_reportflags(doctest.REPORT_UDIFF)

    # Use a custom parser
    parser = DocTestParser()

    # Find all test cases.
    tests = []
    here = os.path.dirname(__file__)
    testdirs = [here, os.path.join(here, 'py2' if six.PY2 else 'py3')]
    for testdir in testdirs:
        for filename in os.listdir(testdir):
            filepath = os.path.join(testdir, filename)
            if (filename.endswith('.doctest')
                    and check_requirements(filepath)):
                relpath = os.path.relpath(filepath, here)
                tests.append(
                    doctest.DocFileSuite(relpath,
                                         optionflags=options,
                                         parser=parser))

    # Run all test cases.
    unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests))
コード例 #41
0
ファイル: _doctest.py プロジェクト: jamesjer/zope.testrunner
 def global_shutdown(self):
     doctest.set_unittest_reportflags(self.old_reporting_flags)
コード例 #42
0
ファイル: nodes.py プロジェクト: xxoolm/Ryven
 def update_event(self, inp=-1):
     self.set_output_val(0, doctest.set_unittest_reportflags(self.input(0)))
コード例 #43
0
def main():
    try:
        doctest.register_optionflag
    except:
        print("\n"
              "The regression test suite requires a more recent version of\n"
              "doctest (e.g., the version that ships with Python 2.7).\n"
              "Please place a new version of doctest on your path before \n"
              "running the test suite.\n")
        return

    PY24 = doctest.register_optionflag('PYTHON2.4')
    """Flag indicating that a doctest example requires Python 2.4+"""

    PY25 = doctest.register_optionflag('PYTHON2.5')
    """Flag indicating that a doctest example requires Python 2.5+"""

    PY2ONLY = doctest.register_optionflag('PYTHON2ONLY')
    """Flag indicating that a doctest example requires Python 2.x, not 3"""
    class DocTestParser(doctest.DocTestParser):
        """
        Custom doctest parser that adds support for two new flags
        +PYTHON2.4 and +PYTHON2.5.
        """
        def parse(self, string, name='<string>'):
            if sys.version_info > (3, 0):
                # HACK: Convert <u'string'> to <'strings'>
                string = string.replace("u'", "'")
                # HACK: Convert exception class names
                string = string.replace(
                    'StructuringError:',
                    'epydoc.markup.epytext.StructuringError:')
                string = string.replace(
                    'InvalidDottedName:',
                    'epydoc.apidoc.DottedName.InvalidDottedName:')
            pieces = doctest.DocTestParser.parse(self, string, name)
            for i, val in enumerate(pieces):
                if (isinstance(val, doctest.Example) and
                    ((val.options.get(PY24, False) and sys.version_info[:2] <
                      (2, 4)) or
                     (val.options.get(PY25, False) and sys.version_info[:2] <
                      (2, 5)) or (val.options.get(PY2ONLY, False)
                                  and sys.version_info[:2] >= (3, 0)))):
                    pieces[i] = doctest.Example('1', '1')
            return pieces

    # Turn on debugging.
    epydoc.DEBUG = True

    # Options for doctest:
    options = doctest.ELLIPSIS
    doctest.set_unittest_reportflags(doctest.REPORT_UDIFF)

    # Use a custom parser
    parser = DocTestParser()

    # Find all test cases.
    tests = []
    testdir = os.path.join(os.path.split(__file__)[0])
    if testdir == '': testdir = '.'
    for filename in os.listdir(testdir):
        if (filename.endswith('.doctest')
                and check_requirements(os.path.join(testdir, filename))):
            tests.append(
                doctest.DocFileSuite(filename,
                                     optionflags=options,
                                     parser=parser))

    # Run all test cases.
    result = unittest.TextTestRunner(verbosity=2).run(
        unittest.TestSuite(tests))
    if result.wasSuccessful():
        return 0
    return 1