Back to index

plone3  3.1.7
testDocTests.py
Go to the documentation of this file.
00001 # setup tests with all doctests found in docs/
00002 
00003 from plone.app.customerize import docs
00004 from plone.app.customerize.tests import layer
00005 from Testing.ZopeTestCase import FunctionalDocFileSuite
00006 from Products.PloneTestCase import PloneTestCase
00007 from Products.Five.testbrowser import Browser
00008 from unittest import TestSuite
00009 from os.path import join, split, abspath, dirname
00010 from os import walk
00011 from re import compile
00012 from sys import argv
00013 
00014 
00015 PloneTestCase.setupPloneSite()
00016 
00017 from zope.testing import doctest
00018 OPTIONFLAGS = (doctest.REPORT_ONLY_FIRST_FAILURE |
00019                doctest.ELLIPSIS |
00020                doctest.NORMALIZE_WHITESPACE)
00021 
00022 class CustomerizeFunctionalTestCase(PloneTestCase.FunctionalTestCase):
00023 
00024     layer = layer.PloneCustomerize
00025     
00026     def afterSetUp(self):
00027         """ set up the tests """
00028         pass
00029 
00030     def getBrowser(self, loggedIn=False):
00031         """ instantiate and return a testbrowser for convenience """
00032         browser = Browser()
00033         if loggedIn:
00034             user = PloneTestCase.default_user
00035             pwd = PloneTestCase.default_password
00036             browser.addHeader('Authorization', 'Basic %s:%s' % (user, pwd))
00037         return browser
00038 
00039 # we check argv to enable testing of explicitely named doctests
00040 if '-t' in argv:
00041     pattern = compile('.*\.(txt|rst)$')
00042 else:
00043     pattern = compile('^test.*\.(txt|rst)$')
00044 
00045 def test_suite():
00046     suite = TestSuite()
00047     docs_dir = abspath(dirname(docs.__file__)) + '/'
00048     for path, dirs, files in walk(docs_dir):
00049         for name in files:
00050             relative = join(path, name)[len(docs_dir):]
00051             if not '.svn' in split(path) and pattern.search(name):
00052                 suite.addTest(FunctionalDocFileSuite(relative,
00053                     optionflags=OPTIONFLAGS,
00054                     package=docs.__name__,
00055                     test_class=CustomerizeFunctionalTestCase))
00056     return suite