def test_main(): suite = unittest.TestSuite([ doctest.DocFileTest('test_mapping.doctest', encoding='utf-8'), doctest.DocFileTest('test_engine_simple.doctest', encoding='utf-8'), unittest.defaultTestLoader.loadTestsFromName(__name__) ]) unittest.TextTestRunner(verbosity=2).run(suite)
def handleFile(self, event): """Load doctests from text files and modules""" path = event.path _root, ext = os.path.splitext(path) if ext in self.extensions: suite = doctest.DocFileTest(path, module_relative=False) event.extraTests.append(suite) return elif not util.valid_module_name(os.path.basename(path)): return name = util.name_from_path(path) try: module = util.module_from_name(name) except Exception: # XXX log warning here? return if hasattr(module, '__test__') and not module.__test__: return try: suite = doctest.DocTestSuite(module) except ValueError: # doctest, very annoyingly, raises ValueError when # a module has no tests. return event.extraTests.append(suite)
def doDoctestSuite(self, module): log = [] doctest.DocFileTest('xyz.txt', package=module, module_relative=True, globs=locals()).run() self.assertEqual(log, [True])
def handleFile(self, event): """Load doctests from text files and modules""" path = event.path _root, ext = os.path.splitext(path) if ext in self.extensions: optionflags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_UDIFF # +REPORT_ONLY_FIRST_FAILURE suite = doctest.DocFileTest(path, module_relative=False, optionflags=optionflags) event.extraTests.append(suite) return elif not util.valid_module_name(os.path.basename(path)): return name, package_path = util.name_from_path(path) util.ensure_importable(package_path) try: module = util.module_from_name(name) except Exception: # XXX log warning here? return if hasattr(module, '__test__') and not module.__test__: return try: suite = doctest.DocTestSuite(module) except ValueError: # with python <= 3.5, doctest, very annoyingly, raises ValueError # when a module has no tests. return event.extraTests.append(suite)
def handleFile(self, event): path = event.path[len(TOPDIR)+1:] if len(self.patterns) > 0: for pattern in self.patterns: if re.search(pattern, path): break else: # Skip this doctest. return base, ext = os.path.splitext(path) if ext != '.rst': return # Look to see if the package defines a test layer, otherwise use the # default layer. First turn the file system path into a dotted Python # module path. parent = os.path.dirname(path) dotted = 'mailman.' + DOT.join(parent.split(os.path.sep)) try: module = importlib.import_module(dotted) except ImportError: layer = SMTPLayer else: layer = getattr(module, 'layer', SMTPLayer) test = doctest.DocFileTest( path, package='mailman', optionflags=FLAGS, setUp=setup, tearDown=teardown) test.layer = layer # Suppress the extra "Doctest: ..." line. test.shortDescription = lambda: None event.extraTests.append(test)
def test_startups(): class StoppingCase(doctest.DocFileCase): def runTest(self): test = self._dt_test old = sys.stdout new = StringIO() optionflags = self._dt_optionflags if not (optionflags & doctest.REPORTING_FLAGS): optionflags |= doctest._unittest_reportflags runner = StoppingRunner(optionflags=optionflags, checker=self._dt_checker, verbose=False) try: runner.DIVIDER = "-" * 70 try: failures, tries = runner.run(test, out=new.write, clear_globs=False) except StopTests: failures = 1 finally: sys.stdout = old if failures: raise self.failureException(self.format_failure( new.getvalue())) test = doctest.DocFileTest( 'startups.txt', optionflags=doctest.ELLIPSIS, package='osaf', ) test.__class__ = StoppingCase # ugh return test
def handleFile(self, event): """Load doctests from text files and modules""" path = event.path _root, ext = os.path.splitext(path) if ext in self.extensions: suite = doctest.DocFileTest(path, module_relative=False) event.extraTests.append(suite) return elif not util.valid_module_name(os.path.basename(path)): return name, package_path = util.name_from_path(path) # ignore top-level setup.py which cannot be imported if name == "setup": return util.ensure_importable(package_path) try: module = util.module_from_name(name) except Exception: # XXX log warning here? return if hasattr(module, "__test__") and not module.__test__: return try: suite = doctest.DocTestSuite(module) except ValueError: # with python <= 3.5, doctest, very annoyingly, raises ValueError # when a module has no tests. return event.extraTests.append(suite)
def _run_one_doctest(self, path): test = doctest.DocFileTest(path) old_dir = os.getcwd() os.chdir(dirname(path)) try: test.runTest() finally: os.chdir(old_dir)
def maybe_load_doctest(path): if path.endswith(".doctest"): return doctest.DocFileTest(path, module_relative=False) elif path.endswith("test_password_manager.special_doctest"): # TODO: get rid of this import mechanize tests = [] common_globs = {"mechanize": mechanize} for globs in [ { "mgr_class": mechanize.HTTPPasswordMgr }, { "mgr_class": mechanize.HTTPProxyPasswordMgr }, ]: globs.update(common_globs) tests.append( doctest.DocFileTest(path, module_relative=False, globs=globs)) return suite.TestSuite(tests) return None
def handleFile(self, event): path = event.path[len(TOPDIR)+1:] if len(self.patterns) > 0: for pattern in self.patterns: if re.search(pattern, path): break else: # Skip this doctest. return base, ext = os.path.splitext(path) if ext != '.rst': return test = doctest.DocFileTest( path, package='dirtbike', optionflags=FLAGS) # Suppress the extra "Doctest: ..." line. test.shortDescription = lambda: None event.extraTests.append(test)
def get_tests(): import cuddlefish import cuddlefish.tests tests = [] packages = [cuddlefish, cuddlefish.tests] for package in packages: path = os.path.abspath(package.__path__[0]) pynames = glob.glob(os.path.join(path, '*.py')) for filename in pynames: basename = os.path.basename(filename) module_name = os.path.splitext(basename)[0] full_name = "%s.%s" % (package.__name__, module_name) module = __import__(full_name, fromlist=[package.__name__]) loader = unittest.TestLoader() suite = loader.loadTestsFromModule(module) for test in suite: tests.append(test) finder = doctest.DocTestFinder() doctests = finder.find(module) for test in doctests: if len(test.examples) > 0: tests.append(doctest.DocTestCase(test)) md_dir = os.path.join(env_root, 'dev-guide') doctest_opts = (doctest.NORMALIZE_WHITESPACE | doctest.REPORT_UDIFF) for dirpath, dirnames, filenames in os.walk(md_dir): for filename in filenames: if filename.endswith('.md'): absname = os.path.join(dirpath, filename) tests.append(doctest.DocFileTest( absname, module_relative=False, optionflags=doctest_opts )) return tests
def test_api(self): test = doctest.DocFileTest("api.doctests") test.runTest()
def test_api(self): if sys.version_info[:2] < (2,4): raise TestSkipped("no DocFileTest in Python <=2.3") test = doctest.DocFileTest("api.doctests") test.runTest()
def test_api3(self): """API tests for Python 3 syntax""" test = doctest.DocFileTest("api3.doctests") test.runTest()
def test_api2(self): """API tests for Python 2 syntax""" if sys.version_info[:2] < (2, 4): raise TestSkipped("no DocFileTest in Python <=2.3") test = doctest.DocFileTest("api2.doctests") test.runTest()
def update_event(self, inp=-1): self.set_output_val(0, doctest.DocFileTest(self.input(0), self.input(1), self.input(2), self.input(3), self.input(4), self.input(5)))