def test_suite(): suite = unittest.TestSuite() my_dir = os.path.dirname(__file__) docs = os.path.join('..', '..', '..', 'docs') registerConfiguration = PLONEBLUEPRINTS_FUNCTIONAL_TESTING \ .baseResolutionOrder[1].registerConfiguration for filename in os.listdir(os.path.join(my_dir, docs)): path = os.path.join(docs, filename) globs = { 'registerConfiguration': registerConfiguration, 'ITransmogrifier': ITransmogrifier, 'api': api, 'logger': InstalledHandler('logger', level=logging.INFO) } flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS suite.addTests([ layered(doctest.DocFileSuite(path, globs=globs, optionflags=flags), layer=PLONEBLUEPRINTS_FUNCTIONAL_TESTING) ]) return suite
def additional_tests(): "Run the doc tests (README.txt and docs/*, if any exist)" doctest_files = [ os.path.abspath( pkg_resources.resource_filename('lazr.uri', 'README.txt')) ] if pkg_resources.resource_exists('lazr.uri', 'docs'): for name in pkg_resources.resource_listdir('lazr.uri', 'docs'): if name.endswith('.txt'): doctest_files.append( os.path.abspath( pkg_resources.resource_filename( 'lazr.uri', 'docs/%s' % name))) kwargs = dict( module_relative=False, optionflags=DOCTEST_FLAGS, globs={"print_function": print_function}, ) atexit.register(pkg_resources.cleanup_resources) return unittest.TestSuite((doctest.DocFileSuite(*doctest_files, **kwargs)))
def test_suite(): """ Suite """ suite = unittest.TestSuite() suite.addTests([ layered(doctest.DocFileSuite('interfaces.py', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), layered(doctest.DocFileSuite('content/interfaces.py', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), layered(doctest.DocFileSuite('controlpanel/interfaces.py', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), layered(doctest.DocFileSuite('widgets/interfaces.py', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), layered(doctest.DocFileSuite('storage/interfaces.py', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), layered(doctest.DocFileSuite('widgets/simple/interfaces.py', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), layered(doctest.DocFileSuite('docs/exportimport.txt', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), layered(doctest.DocFileSuite('README.txt', optionflags=OPTIONFLAGS, package='eea.progressbar'), layer=FUNCTIONAL_TESTING), ]) return suite
def setUp(self): """ Create a TestSuite of doctests """ self.doctest_suite = unittest.TestSuite() path, name, ext = magni.utils.split_path(__file__) magni_base_path = path.rsplit(os.sep, 2)[0] exclude_patterns = ['__pycache__', 'tests'] for dirpath, dirnames, filenames in os.walk(magni_base_path): for filename in filenames: if filename[-3:] == '.py' and not any([ exclude_pattern in dirpath for exclude_pattern in exclude_patterns ]): self.doctest_suite.addTest( doctest.DocFileSuite(os.path.join(dirpath, filename), module_relative=False))
def get_suite(): suite = unittest.TestSuite() names = [ # 'contents.rst', # 'sequences.rst', # 'contrib%sfetch.rst' % os.path.sep, @CTB does not work on my system? # 'recipes%spygrdata_recipes.rst' % os.path.sep, # 'recipes%salignment_recipes.rst' % os.path.sep, ] # needs relative paths for some reason doctestpath = os.path.join('..', 'doc', 'rest') paths = [os.path.join(doctestpath, name) for name in names] for path in paths: docsuite = doctest.DocFileSuite(path) suite.addTest(docsuite) return suite
def build_suite(suite, names): # Determine the root directory of the source code files. This is # used for finding doctest files specified relative to that root. project_root = os.path.join(os.path.dirname(__file__), "..", "..") project_root = os.path.abspath(project_root) # Load test cases from specified names. loader = unittest.defaultTestLoader for name in names: if name.startswith("."): name = "dragonfire.test" + name suite.addTests(loader.loadTestsFromName(name)) elif name.startswith("doc:"): path = name[4:] path = os.path.join(project_root, *path.split("/")) path = os.path.abspath(path) suite.addTests(doctest.DocFileSuite(path)) else: raise Exception("Invalid test name: %r." % (name,)) return suite
def load_tests(loader, basic_tests, pattern): """This module creates its own test suite with DocFileSuite.""" dir_ = os.path.dirname(__file__) if os.path.isdir(dir_): candidates = os.listdir(dir_) else: candidates = [] scripts = [ candidate for candidate in candidates if candidate.endswith('.txt') ] # since this module doesn't define tests, we ignore basic_tests suite = doctest.DocFileSuite(*scripts, setUp=tests.isolated_doctest_setUp, tearDown=tests.isolated_doctest_tearDown) # DocFileCase reduces the test id to the base name of the tested file, we # want the module to appears there. for t in tests.iter_suite_tests(suite): t.id = make_new_test_id(t) return suite
def load_tests(): # create a test suite suite = unittest.TestSuite() startDir = abspath(join(HERE, 'test')) # unittest2 discovery suite = unittest.TestLoader().discover(startDir, pattern='test*.py', top_level_dir=None) # add doctests for test in doctests: suite.addTest( doctest.DocFileSuite(join(HERE, test), module_relative=False, optionflags=DOCTEST_FLAGS, setUp=setUp, tearDown=tearDown)) return suite
def test_suite(): return unittest.TestSuite([ doctest.DocFileSuite( filename, setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown, optionflags=optionflags, globs={ 'interact': interact, 'pprint': pprint }, checker=renormalizing.RENormalizing([ zc.buildout.testing.normalize_path, (re.compile(r'http://localhost:\d+'), 'http://test.server'), # Clean up the variable hashed filenames to avoid spurious # test failures (re.compile(r'[a-f0-9]{32}'), ''), ]), ) for filename in TESTFILES ])
def load_tests(basic_tests, module, loader): """This module creates its own test suite with DocFileSuite.""" dir_ = os.path.dirname(__file__) if os.path.isdir(dir_): candidates = os.listdir(dir_) else: candidates = [] scripts = [candidate for candidate in candidates if candidate.endswith('.txt')] # since this module doesn't define tests, we ignore basic_tests suite = doctest.DocFileSuite(*scripts) # DocFileCase reduces the test id to the base name of the tested file, we # want the module to appears there. for t in tests.iter_suite_tests(suite): def make_new_test_id(): new_id = '%s.DocFileTest(%s)' % ( __name__, t) return lambda: new_id t.id = make_new_test_id() return suite
def load_tests(loader, tests, pattern): # Force time zone to EST/EDT to make localtime tests work. os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0' time.tzset() # The different floating-point formatting rules in 2.6 and prior # ruin our doctests. tests = [] if sys.version_info >= (2, 7): tests.extend([ doctest.DocFileSuite('../doc/%s' % os.path.basename(path)) for path in glob(os.path.dirname(__file__) + '/../doc/*.rst') if os.path.split(path)[-1] != 'index.rst' # skips time-dependent doctest in index.rst ]) return unittest.TestSuite(tests)
def assembleAndRunDocTests(path): """ This function assembles all the pattern files together into a single temporary file. This is done in order to avoide entering duplicate code in each pattern file. """ filenames = sorted(glob.glob(path)) text = StringIO() [text.write(open(filename).read()) for filename in filenames] fileHandle, tempFilename = tempfile.mkstemp( suffix=".txt", prefix="assembled-patterns-doctests-tmp", text=True) os.write(fileHandle, text.getvalue()) suites = [ doctest.DocFileSuite(tempFilename, module_relative=False, optionflags=doctest.ELLIPSIS) ] runner = unittest.TextTestRunner(verbosity=2) runner.run(unittest.TestSuite(suites)) os.unlink(tempFilename)
def get_suite(): suite = unittest.TestSuite() file_names = [] module_names = [data, hdflib] # needs relative paths for some reason full_path = lambda name: os.path.join('../docs/rest', name) file_paths = map(full_path, file_names) for file_path in file_paths: rest_suite = doctest.DocFileSuite(file_path) suite.addTest(rest_suite) for mod in module_names: docsuite = doctest.DocTestSuite(mod) suite.addTest(docsuite) return suite
def suite(): suite = trytond.tests.test_tryton.suite() from trytond.modules.product.tests import test_product for test in test_product.suite(): if test not in suite and not isinstance(test, doctest.DocTestCase): suite.addTest(test) from trytond.modules.currency.tests import test_currency for test in test_currency.suite(): if test not in suite and not isinstance(test, doctest.DocTestCase): suite.addTest(test) suite.addTests( unittest.TestLoader().loadTestsFromTestCase(CarrierWeightTestCase)) suite.addTests( doctest.DocFileSuite( 'scenario_carrier_percentage_with_purchase_shipment_cost.rst', setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8', optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite
def test_suite(): """Create a test suite of all doctests.""" s = unittest.TestSuite() # Standard options for DocTests opt = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_ONLY_FIRST_FAILURE | doctest.IGNORE_EXCEPTION_DETAIL) globs = { 'points': [1, 2, 3, 4, 5, 6, 7], 'distance': lambda a, b: abs(b - a), } s.addTests(unittest.makeSuite(MedoidsTest)) s.addTests(doctest.DocTestSuite(medoids, optionflags=opt, extraglobs=globs)) s.addTests(doctest.DocFileSuite('./README.rst', optionflags=opt)) return unittest.TestSuite(s)
def test_suite(): suite = unittest.TestSuite(( doctest.DocFileSuite( '../README.txt', setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown, optionflags=optionflags, globs=dict(test_dir=test_dir), checker=renormalizing.RENormalizing([ # If want to clean up the doctest output you # can register additional regexp normalizers # here. The format is a two-tuple with the RE # as the first item and the replacement as the # second item, e.g. # (re.compile('my-[rR]eg[eE]ps'), 'my-regexps') zc.buildout.testing.normalize_path, ]), ), )) return suite
def test_suite(): suite = unittest.TestSuite() suite.addTests([ unittest.makeSuite(TestUtilsOpt), unittest.makeSuite(TestUtils), unittest.makeSuite(TestBatch), unittest.makeSuite(TestBrowser), unittest.makeSuite(TestQuantumBatch), doctest.DocFileSuite('batching.rst', package='plone.batching', optionflags=doctest.ELLIPSIS | doctest.REPORT_ONLY_FIRST_FAILURE, setUp=setUp, tearDown=tearDown), # doctest.DocFileSuite('../../docs/usage.rst', # package='plone.batching', # optionflags=doctest.ELLIPSIS | # doctest.REPORT_ONLY_FIRST_FAILURE, # setUp=setUp, tearDown=tearDown), ]) return suite
def additional_tests(): # Invoked by setuptools when running "setup.py test" import doctest import glob import interval import os import unittest from . import helpers s = unittest.TestSuite() s.addTest(doctest.DocTestSuite(interval)) s.addTest(doctest.DocTestSuite(helpers)) # On Python >= 2.7 the repr of floats has been improved. We test # the examples in the narrative docs only with Python versions # having the new repr. if repr(1 / 3.0) == '0.3333333333333333': docfiles = glob.glob( os.path.join(os.path.dirname(__file__), '..', '*', '*.rst')) s.addTest(doctest.DocFileSuite(module_relative=False, *docfiles)) return s
def test_suite(): """Simple tes suite""" globs = {} try: from pprint import pprint globs["pprint"] = pprint except Exception: pass try: from interlude import interact globs["interact"] = interact except Exception: pass return unittest.TestSuite([ doctest.DocFileSuite(file, optionflags=optionflags, globs=globs) for file in TESTFILES ])
def test_suite(): suite = unittest.TestSuite(( doctest.DocFileSuite( 'README.txt', setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown, optionflags=optionflags, checker=renormalizing.RENormalizing([ # If want to clean up the doctest output you # can register additional regexp normalizers # here. The format is a two-tuple with the RE # as the first item and the replacement as the # second item, e.g. # (re.compile('my-[rR]eg[eE]ps'), 'my-regexps') normalize_path, (re.compile(r'http://localhost:\d+'), 'http://test.server'), (re.compile("Not found: .*buildouttests/[a-zA-Z0-9.]+/\n"), ''), ]), ))) return suite
def test_suite(): optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS globs = { 'DummySite': DummySite, 'setSite': setSite, 'getSite': getSite, 'TEST_DSN': TEST_DSN, 'TEST_DSN1': TEST_DSN1, 'TEST_DSN2': TEST_DSN2, 'TEST_TWOPHASE': TEST_TWOPHASE, } suite = unittest.TestSuite() suite.addTest(doctest.DocFileSuite( 'README.rst', optionflags=optionflags, setUp=setUpReadMe, tearDown=tearDownReadMe, globs=globs)) return suite
def tutorial_test_suite(): tutorial = [ 'introduction', 'repo', 'object-store', 'conclusion', ] tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial] def setup(test): test.__old_cwd = os.getcwd() test.__dulwich_tempdir = tempfile.mkdtemp() os.chdir(test.__dulwich_tempdir) def teardown(test): shutil.rmtree(test.__dulwich_tempdir) os.chdir(test.__old_cwd) return doctest.DocFileSuite(setUp=setup, tearDown=teardown, *tutorial_files)
def loadTestsFromModule(self, module): """Return a suite of all tests cases contained in the given module. If the loader was initialized with a doctests argument, then this string is assigned as the module's docstring.""" # Start by loading any tests in the called module itself suite = super(self.__class__, self).loadTestsFromModule(module) # Now, load also tests referenced at construction time as companion # doctests that reside in standalone files for fname in self.dt_files: #print 'mod:',module # dbg #print 'fname:',fname # dbg suite.addTest(doctest.DocFileSuite(fname, module_relative=False)) # Add docstring tests from module, if given at construction time for mod in self.dt_modules: suite.addTest( doctest.DocTestSuite(mod, test_finder=self.test_finder)) return suite
def get_snippet_suites(): """Return list of DocFileSuites""" # We need to get the Simulator version so we can skip tests that are # broken for certain versions. saw_14 = SAW(PATH_14) version = saw_14.version saw_14.exit() del saw_14 out = [] # Loop over the available cases. for suffix, case_path in CASE_MAP.items(): # Filter files by suffix, which corresponds to the case. files = [x for x in SNIPPET_FILES if x.endswith(suffix + '.rst')] if len(files) > 0: # Recreate a list that excludes the broken file. For now, # we'll skip if the version is less than 21. if version < BROKEN_THRESHOLD: not_broken_files = [x for x in files if BROKEN not in x] if len(not_broken_files) != len(files): LOG.warning('The snippet {} is being skipped because the ' 'Simulator version is < {}'.format( BROKEN, BROKEN_THRESHOLD)) else: not_broken_files = files # Define global variables needed for the examples. g = {'CASE_PATH': case_path} if '2000' in suffix: # One example adds lines and depends on a .csv file. g['CANDIDATE_LINES'] = CANDIDATE_LINES # Create a DocFileSuite. out.append( doctest.DocFileSuite(*not_broken_files, module_relative=False, globs=g)) return out
def test(): """Run tt tests.""" _print_sys_info() suite = unittest.defaultTestLoader.discover(TESTS_DIR, pattern='test_*.py', top_level_dir=HERE) doctest_modules = [ tt.definitions.operands, tt.definitions.operators, tt.expressions.bexpr, tt.errors.arguments, tt.errors.evaluation, tt.errors.grammar, tt.errors.state, tt.errors.symbols, tt.satisfiability.picosat, tt.tables.truth_table, tt.transformations.bexpr, tt.trees.tree_node ] doctest_files = [ os.path.join(USER_GUIDE_DIR, 'expression_basics.rst'), os.path.join(USER_GUIDE_DIR, 'table_basics.rst') ] if sys.version_info.major >= 3: # only test the readme in Python 3 doctest_files.append(os.path.join(HERE, 'README.rst')) common_doctest_kwargs = dict(optionflags=doctest.IGNORE_EXCEPTION_DETAIL) for module in doctest_modules: suite.addTests(doctest.DocTestSuite(module, **common_doctest_kwargs)) for file in doctest_files: suite.addTests( doctest.DocFileSuite(file, module_relative=False, **common_doctest_kwargs)) runner = unittest.TextTestRunner() result = runner.run(suite) if not result.wasSuccessful(): raise TestFailureError
def suite(): test_suite = unittest.TestSuite() test_suite.addTests([ unittest.makeSuite(test_cls) for test_cls in ( TestDocutils, TestFormatEstimation, TestSimpleTableParser, TestGridTableParser, TestMarkdownParser, TestCompile, TestSelect, TestSelectAll, TestTable, TestUnion, TestJoin, TestColumnType, TestIterable, ) ]) test_suite.addTests(doctest.DocTestSuite(inline_table)) test_suite.addTests(doctest.DocFileSuite('README.rst')) return test_suite
def test_suite(): from unittest import TestSuite from Testing.ZopeTestCase.zopedoctest import ZopeDocFileSuite optionflags = doctest.REPORT_ONLY_FIRST_FAILURE | doctest.ELLIPSIS suites = [] scriptTests = [ 'search_treevocabulary.txt', 'simplevocabulary.txt', ] for test in scriptTests: suites.append( layered(doctest.DocFileSuite( test, optionflags=optionflags, globs={'createTestVocabulary': createTestVocabulary}, package='Products.ATVocabularyManager.doc', ), layer=AT_FUNCTIONAL_TESTING)) return TestSuite(suites)
def build_suite(suite, names): # Load test cases from specified names. loader = unittest.defaultTestLoader for name in names: if name.startswith("test_"): # Use full module names so the loader can import the files # correctly. name = "dragonfly.test." + name suite.addTests(loader.loadTestsFromName(name)) elif name.startswith("doc:"): # Skip doc tests for Python 3.x because of incompatible Unicode # string comparisons in some tests. # TODO Use pytest instead for its ALLOW_UNICODE doctest flag. if PY3: continue # Load doc tests using a relative path. path = os.path.join("..", "..", name[4:]) suite.addTests(doctest.DocFileSuite(path)) else: raise Exception("Invalid test name: %r." % (name, )) return suite
def test_suite(): """Get a testsuite of all doctests. """ suite = unittest.TestSuite() readme = doctest.DocFileSuite( 'README.txt', checker=checker, setUp=setUpStatic, package=grokcore.chameleon, globs=dict(getRootFolder=FunctionalLayer.getRootFolder, ), optionflags=FLAGS, ) readme.layer = FunctionalLayer suite.addTest(readme) suite.addTest( doctest.DocTestSuite( 'grokcore.chameleon.tests.templatefile', checker=checker, setUp=setUpStatic, optionflags=FLAGS, )) return suite
def test_suite(): from unittest import TestSuite, makeSuite import doctest optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS checker = RENormalizing([ # Python 3 includes module name in exceptions (re.compile(r"sqlalchemy.orm.exc.DetachedInstanceError:"), "DetachedInstanceError:"), # Python 3 drops the u'' prefix on unicode strings (re.compile(r"u('[^']*')"), r"\1"), # PyPy includes __builtin__ in front of classes defined in doctests (re.compile(r"__builtin__[.]Address"), "Address"), ]) suite = TestSuite() suite.addTest(makeSuite(ZopeSQLAlchemyTests)) suite.addTest(makeSuite(MultipleEngineTests)) if TEST_DSN.startswith('postgres') or TEST_DSN.startswith('oracle'): suite.addTest(makeSuite(RetryTests)) suite.addTest(doctest.DocFileSuite('README.txt', optionflags=optionflags, checker=checker, tearDown=tearDownReadMe, globs={'TEST_DSN': TEST_DSN, 'TEST_TWOPHASE': TEST_TWOPHASE})) return suite