當前位置: 首頁>>代碼示例>>Python>>正文


Python doctest.py方法代碼示例

本文整理匯總了Python中doctest.py方法的典型用法代碼示例。如果您正苦於以下問題:Python doctest.py方法的具體用法?Python doctest.py怎麽用?Python doctest.py使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在doctest的用法示例。


在下文中一共展示了doctest.py方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: wantFile

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import py [as 別名]
def wantFile(self, file):
        """Override to select all modules and any file ending with
        configured doctest extension.
        """
        # always want .py files
        if file.endswith('.py'):
            return True
        # also want files that match my extension
        if (self.extension
            and anyp(file.endswith, self.extension)
            and (not self.conf.exclude
                 or not filter(None, 
                               [exc.search(file)
                                for exc in self.conf.exclude]))):
            return True
        return None 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:18,代碼來源:doctests.py

示例2: test_lineendings

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import py [as 別名]
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...     f.write('Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> with open(fn, 'wb') as f:
    ...     f.write('Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    >>> doctest.testfile(fn, module_relative=False, verbose=False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

"""

# old_test1, ... used to live in doctest.py, but cluttered it.  Note
# that these use the deprecated doctest.Tester, so should go away (or
# be rewritten) someday. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:33,代碼來源:test_doctest.py

示例3: matches

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import py [as 別名]
def matches(self, name):
        # FIXME this seems wrong -- nothing is ever going to
        # fail this test, since we're given a module NAME not FILE
        if name == '__init__.py':
            return False
        # FIXME don't think we need include/exclude checks here?
        return ((self.doctest_tests or not self.conf.testMatch.search(name)
                 or (self.conf.include 
                     and filter(None,
                                [inc.search(name)
                                 for inc in self.conf.include])))
                and (not self.conf.exclude 
                     or not filter(None,
                                   [exc.search(name)
                                    for exc in self.conf.exclude]))) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:17,代碼來源:doctests.py

示例4: test_lineendings

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import py [as 別名]
def test_lineendings(): r"""
*nix systems use \n line endings, while Windows systems use \r\n.  Python
handles this using universal newline mode for reading files.  Let's make
sure doctest does so (issue 8473) by creating temporary test files using each
of the two line disciplines.  One of the two will be the "wrong" one for the
platform the test is run on.

Windows line endings first:

    >>> import tempfile, os
    >>> fn = tempfile.mktemp()
    >>> open(fn, 'w').write('Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
    >>> doctest.testfile(fn, False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

And now *nix line endings:

    >>> fn = tempfile.mktemp()
    >>> open(fn, 'w').write('Test:\n\n  >>> x = 1 + 1\n\nDone.\n')
    >>> doctest.testfile(fn, False)
    TestResults(failed=0, attempted=1)
    >>> os.remove(fn)

"""

# old_test1, ... used to live in doctest.py, but cluttered it.  Note
# that these use the deprecated doctest.Tester, so should go away (or
# be rewritten) someday. 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:31,代碼來源:test_doctest.py

示例5: debug_script

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import py [as 別名]
def debug_script(src, pm=False, globs=None):
    "Debug a test script.  `src` is the script, as a string."
    import pdb

    # Note that tempfile.NameTemporaryFile() cannot be used.  As the
    # docs say, a file so created cannot be opened by name a second time
    # on modern Windows boxes, and execfile() needs to open it.
    srcfilename = tempfile.mktemp(".py", "doctestdebug")
    with open(srcfilename, 'w') as fp:
        fp.write(src)

    try:
        if globs:
            globs = globs.copy()
        else:
            globs = {}

        if pm:
            try:
                execfile(srcfilename, globs, globs)
            except:
                print(sys.exc_info()[1])
                pdb.post_mortem(sys.exc_info()[2])
        else:
            # Note that %r is vital here.  '%s' instead can, e.g., cause
            # backslashes to get treated as metacharacters on Windows.
            pdb.run("execfile(%r)" % srcfilename, globs, globs)

    finally:
        os.remove(srcfilename) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:32,代碼來源:_doctest.py

示例6: run_test_file_with_config

# 需要導入模塊: import doctest [as 別名]
# 或者: from doctest import py [as 別名]
def run_test_file_with_config(filename, globs, optionflags):
    """Modified from doctest.py to use custom checker."""
    text, filename = _load_testfile(filename)
    name = os.path.basename(filename)
    if globs is None:
        globs = {}
    else:
        globs = globs.copy()
    if '__name__' not in globs:
        globs['__name__'] = '__main__'
    checker = Py23DocChecker()
    runner = TestRunner(checker=checker, verbose=None, optionflags=optionflags)
    parser = doctest.DocTestParser()
    test = parser.get_doctest(text, globs, name, filename, 0)
    flags = (
        print_function.compiler_flag
        | absolute_import.compiler_flag
        | division.compiler_flag
    )
    runner.run(test, flags)
    results = runner.summarize()
    if doctest.master is None:
        doctest.master = runner
    else:
        doctest.master.merge(runner)
    return results 
開發者ID:guildai,項目名稱:guildai,代碼行數:28,代碼來源:_test.py


注:本文中的doctest.py方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。