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


Python doctest.DocTestFinder方法代码示例

本文整理汇总了Python中doctest.DocTestFinder方法的典型用法代码示例。如果您正苦于以下问题:Python doctest.DocTestFinder方法的具体用法?Python doctest.DocTestFinder怎么用?Python doctest.DocTestFinder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在doctest的用法示例。


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

示例1: _run_object_doctest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def _run_object_doctest(obj, module):
    # Direct doctest output (normally just errors) to real stdout; doctest
    # output shouldn't be compared by regrtest.
    save_stdout = sys.stdout
    sys.stdout = test.test_support.get_original_stdout()
    try:
        finder = doctest.DocTestFinder(verbose=verbose, recurse=False)
        runner = doctest.DocTestRunner(verbose=verbose)
        # Use the object's fully qualified name if it has one
        # Otherwise, use the module's name
        try:
            name = "%s.%s" % (obj.__module__, obj.__name__)
        except AttributeError:
            name = module.__name__
        for example in finder.find(obj, name, module):
            runner.run(example)
        f, t = runner.failures, runner.tries
        if f:
            raise test.test_support.TestFailed("%d of %d doctests failed" % (f, t))
    finally:
        sys.stdout = save_stdout
    if verbose:
        print 'doctest (%s) ... %d tests with zero failures' % (module.__name__, t)
    return f, t 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_zipimport_support.py

示例2: configure

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def configure(self, options, config):
        """Configure plugin.
        """
        Plugin.configure(self, options, config)
        self.doctest_result_var = options.doctest_result_var
        self.doctest_tests = options.doctest_tests
        self.extension = tolist(options.doctestExtension)
        self.fixtures = options.doctestFixtures
        self.finder = doctest.DocTestFinder()
        self.optionflags = 0
        if options.doctestOptions:
            flags = ",".join(options.doctestOptions).split(',')
            for flag in flags:
                try:
                    if flag.startswith('+'):
                        self.optionflags |= getattr(doctest, flag[1:])
                    elif flag.startswith('-'):
                        self.optionflags &= ~getattr(doctest, flag[1:])
                    else:
                        raise ValueError(
                            "Must specify doctest options with starting " +
                            "'+' or '-'.  Got %s" % (flag,))
                except AttributeError:
                    raise ValueError("Unknown doctest option %s" %
                                     (flag[1:],)) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:27,代码来源:doctests.py

示例3: _run_object_doctest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def _run_object_doctest(obj, module):
    finder = doctest.DocTestFinder(verbose=verbose, recurse=False)
    runner = doctest.DocTestRunner(verbose=verbose)
    # Use the object's fully qualified name if it has one
    # Otherwise, use the module's name
    try:
        name = "%s.%s" % (obj.__module__, obj.__qualname__)
    except AttributeError:
        name = module.__name__
    for example in finder.find(obj, name, module):
        runner.run(example)
    f, t = runner.failures, runner.tries
    if f:
        raise test.support.TestFailed("%d of %d doctests failed" % (f, t))
    if verbose:
        print ('doctest (%s) ... %d tests with zero failures' % (module.__name__, t))
    return f, t 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_zipimport_support.py

示例4: _run_object_doctest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def _run_object_doctest(obj, module):
    finder = doctest.DocTestFinder(verbose=verbose, recurse=False)
    runner = doctest.DocTestRunner(verbose=verbose)
    # Use the object's fully qualified name if it has one
    # Otherwise, use the module's name
    try:
        name = "%s.%s" % (obj.__module__, obj.__name__)
    except AttributeError:
        name = module.__name__
    for example in finder.find(obj, name, module):
        runner.run(example)
    f, t = runner.failures, runner.tries
    if f:
        raise test.support.TestFailed("%d of %d doctests failed" % (f, t))
    if verbose:
        print ('doctest (%s) ... %d tests with zero failures' % (module.__name__, t))
    return f, t 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:test_zipimport_support.py

示例5: configure

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def configure(self, options, config):
        # it is overriden in order to fix doctest options discovery

        Plugin.configure(self, options, config)
        self.doctest_result_var = options.doctest_result_var
        self.doctest_tests = options.doctest_tests
        self.extension = tolist(options.doctestExtension)
        self.fixtures = options.doctestFixtures
        self.finder = doctest.DocTestFinder()

        #super(DoctestPluginHelper, self).configure(options, config)
        self.optionflags = 0
        self.options = {}

        if options.doctestOptions:
            stroptions = ",".join(options.doctestOptions).split(',')
            for stroption in stroptions:
                try:
                    if stroption.startswith('+'):
                        self.optionflags |= doctest.OPTIONFLAGS_BY_NAME[stroption[1:]]
                        continue
                    elif stroption.startswith('-'):
                        self.optionflags &= ~doctest.OPTIONFLAGS_BY_NAME[stroption[1:]]
                        continue
                    try:
                        key,value=stroption.split('=')
                    except ValueError:
                        pass
                    else:
                        if not key in self.OPTION_BY_NAME:
                            raise ValueError()
                        self.options[key]=value
                        continue
                except (AttributeError, ValueError, KeyError):
                    raise ValueError("Unknown doctest option {}".format(stroption))
                else:
                    raise ValueError("Doctest option is not a flag or a key/value pair: {} ".format(stroption)) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:39,代码来源:doctest_nose_plugin.py

示例6: displayhook

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def displayhook(): r"""
Test that changing sys.displayhook doesn't matter for doctest.

    >>> import sys
    >>> orig_displayhook = sys.displayhook
    >>> def my_displayhook(x):
    ...     print('hi!')
    >>> sys.displayhook = my_displayhook
    >>> def f():
    ...     '''
    ...     >>> 3
    ...     3
    ...     '''
    >>> test = doctest.DocTestFinder().find(f)[0]
    >>> r = doctest.DocTestRunner(verbose=False).run(test)
    >>> post_displayhook = sys.displayhook

    We need to restore sys.displayhook now, so that we'll be able to test
    results.

    >>> sys.displayhook = orig_displayhook

    Ok, now we can check that everything is ok.

    >>> r
    TestResults(failed=0, attempted=1)
    >>> post_displayhook is my_displayhook
    True
""" 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:31,代码来源:test_doctest.py

示例7: configure

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def configure(self, options, config):
        Plugin.configure(self, options, config)
        # Pull standard doctest plugin out of config; we will do doctesting
        config.plugins.plugins = [p for p in config.plugins.plugins
                                  if p.name != 'doctest']
        self.doctest_tests = options.doctest_tests
        self.extension = tolist(options.doctestExtension)

        self.parser = doctest.DocTestParser()
        self.finder = DocTestFinder()
        self.checker = IPDoctestOutputChecker()
        self.globs = None
        self.extraglobs = None 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:ipdoctest.py

示例8: runDocTests

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def runDocTests():
    finder = doctest.DocTestFinder(exclude_empty=False)
    suite = doctest.DocTestSuite(test_finder=finder) 
开发者ID:SpectoLabs,项目名称:hoverpy,代码行数:5,代码来源:run.py

示例9: non_Python_modules

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def non_Python_modules(): r"""

Finding Doctests in Modules Not Written in Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DocTestFinder can also find doctests in most modules not written in Python.
We'll use builtins as an example, since it almost certainly isn't written in
plain ol' Python and is guaranteed to be available.

    >>> import builtins
    >>> tests = doctest.DocTestFinder().find(builtins)
    >>> 790 < len(tests) < 810 # approximate number of objects with docstrings
    True
    >>> real_tests = [t for t in tests if len(t.examples) > 0]
    >>> len(real_tests) # objects that actually have doctests
    8
    >>> for t in real_tests:
    ...     print('{}  {}'.format(len(t.examples), t.name))
    ...
    1  builtins.bin
    3  builtins.float.as_integer_ratio
    2  builtins.float.fromhex
    2  builtins.float.hex
    1  builtins.hex
    1  builtins.int
    2  builtins.int.bit_length
    1  builtins.oct

Note here that 'bin', 'oct', and 'hex' are functions; 'float.as_integer_ratio',
'float.hex', and 'int.bit_length' are methods; 'float.fromhex' is a classmethod,
and 'int' is a type.
""" 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:33,代码来源:test_doctest.py

示例10: test

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def test(self):
        """just there to trigger test execution"""
        self.skipped_test('doctest module has no DocTestSuite class')


# DocTestFinder was introduced in python2.4 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:8,代码来源:testlib.py

示例11: __init__

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def __init__(self, *args, **kwargs):
            self.skipped = kwargs.pop('skipped', ())
            doctest.DocTestFinder.__init__(self, *args, **kwargs) 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:5,代码来源:testlib.py

示例12: _get_test

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def _get_test(self, obj, name, module, globs, source_lines):
            """override default _get_test method to be able to skip tests
            according to skipped attribute's value

            Note: Python (<=2.4) use a _name_filter which could be used for that
                  purpose but it's no longer available in 2.5
                  Python 2.5 seems to have a [SKIP] flag
            """
            if getattr(obj, '__name__', '') in self.skipped:
                return None
            return doctest.DocTestFinder._get_test(self, obj, name, module,
                                                   globs, source_lines) 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:14,代码来源:testlib.py

示例13: __call__

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def __call__(self, result=None, runcondition=None, options=None):
        try:
            finder = DocTestFinder(skipped=self.skipped)
            if sys.version_info >= (2, 4):
                suite = doctest.DocTestSuite(self.module, test_finder=finder)
            else:
                suite = doctest.DocTestSuite(self.module)
        except AttributeError:
            suite = SkippedSuite()
        return suite.run(result) 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:12,代码来源:testlib.py

示例14: run_doctest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def run_doctest(obj, state, check=True):
    finder = doctest.DocTestFinder(verbose=state["verbose"], recurse=False)
    runner = doctest.DocTestRunner(verbose=state["verbose"])

    for test in finder.find(obj, obj.__qualname__, globs=state["globs"]):
        output = io.StringIO()
        results = runner.run(test, out=output.write)
        if results.failed and check:
            raise Exception(output.getvalue()) 
开发者ID:intel,项目名称:dffml,代码行数:11,代码来源:test_docstrings.py

示例15: non_Python_modules

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestFinder [as 别名]
def non_Python_modules(): r"""

Finding Doctests in Modules Not Written in Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DocTestFinder can also find doctests in most modules not written in Python.
We'll use builtins as an example, since it almost certainly isn't written in
plain ol' Python and is guaranteed to be available.

    >>> import builtins
    >>> tests = doctest.DocTestFinder().find(builtins)
    >>> 790 < len(tests) < 800 # approximate number of objects with docstrings
    True
    >>> real_tests = [t for t in tests if len(t.examples) > 0]
    >>> len(real_tests) # objects that actually have doctests
    8
    >>> for t in real_tests:
    ...     print('{}  {}'.format(len(t.examples), t.name))
    ...
    1  builtins.bin
    3  builtins.float.as_integer_ratio
    2  builtins.float.fromhex
    2  builtins.float.hex
    1  builtins.hex
    1  builtins.int
    2  builtins.int.bit_length
    1  builtins.oct

Note here that 'bin', 'oct', and 'hex' are functions; 'float.as_integer_ratio',
'float.hex', and 'int.bit_length' are methods; 'float.fromhex' is a classmethod,
and 'int' is a type.
""" 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:33,代码来源:test_doctest.py


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