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


Python doctest.DocTestCase方法代码示例

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


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

示例1: setUp

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def setUp(self):
        """Modified test setup that syncs with ipython namespace"""
        #print "setUp test", self._dt_test.examples # dbg
        if isinstance(self._dt_test.examples[0], IPExample):
            # for IPython examples *only*, we swap the globals with the ipython
            # namespace, after updating it with the globals (which doctest
            # fills with the necessary info from the module being tested).
            self.user_ns_orig = {}
            self.user_ns_orig.update(_ip.user_ns)
            _ip.user_ns.update(self._dt_test.globs)
            # We must remove the _ key in the namespace, so that Python's
            # doctest code sets it naturally
            _ip.user_ns.pop('_', None)
            _ip.user_ns['__builtins__'] = builtin_mod
            self._dt_test.globs = _ip.user_ns

        super(DocTestCase, self).setUp() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:ipdoctest.py

示例2: makeTest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def makeTest(self, obj, parent):
        """Look for doctests in the given object, which will be a
        function, method or class.
        """
        #print 'Plugin analyzing:', obj, parent  # dbg
        # always use whitespace and ellipsis options
        optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS

        doctests = self.finder.find(obj, module=getmodule(parent))
        if doctests:
            for test in doctests:
                if len(test.examples) == 0:
                    continue

                yield DocTestCase(test, obj=obj,
                                  optionflags=optionflags,
                                  checker=self.checker) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:ipdoctest.py

示例3: test_doctest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def test_doctest(self):
        """
        If we parse a doctest, we get all the fields we need.
        """
        test = """
        >>> f()
        42
        """

        def f():
            return 42

        parser = doctest.DocTestParser()
        dt = parser.get_doctest(test, {"f": f}, "doctest.name", "somefile.py", 20)
        dt.__module__ = "somefile"
        p = proto_test(doctest.DocTestCase(dt))
        # short description
        self.assertEqual(p.getDescription(2), "doctest.name")
        # long description
        description = p.getDescription(3)
        self.assertIn("doctest.name", description)
        self.assertIn("somefile.py", description)
        self.assertIn("20", description)
        # dotted name
        self.assertEqual(p.dotted_name, "doctest.name") 
开发者ID:CleanCut,项目名称:green,代码行数:27,代码来源:test_result.py

示例4: run

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def run(names, optionflags, verbosity):
    suite = unittest.TestSuite()
    for name in names:
        try:
            for test in find(name):
                suite.addTest(DocTestCase(test, optionflags))
        except ValueError, e:
            print >>sys.stderr, ('%s: Error processing %s -- %s' %
                                 (sys.argv[0], name, e)) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:11,代码来源:doctest_driver.py

示例5: check_output

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def check_output(self, want, got, optionflags):
        ret = doctest.OutputChecker.check_output(self, want, got,
                                                 optionflags)
        if not ret:
            if "#random" in want:
                return True

            # it would be useful to normalize endianness so that
            # bigendian machines don't fail all the tests (and there are
            # actually some bigendian examples in the doctests). Let's try
            # making them all little endian
            got = got.replace("'>", "'<")
            want = want.replace("'>", "'<")

            # try to normalize out 32 and 64 bit default int sizes
            for sz in [4, 8]:
                got = got.replace("'<i%d'" % sz, "int")
                want = want.replace("'<i%d'" % sz, "int")

            ret = doctest.OutputChecker.check_output(self, want,
                    got, optionflags)

        return ret


# Subclass nose.plugins.doctests.DocTestCase to work around a bug in
# its constructor that blocks non-default arguments from being passed
# down into doctest.DocTestCase 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:noseclasses.py

示例6: __init__

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
                 checker=None, obj=None, result_var='_'):
        self._result_var = result_var
        self._nose_obj = obj
        doctest.DocTestCase.__init__(self, test,
                                     optionflags=optionflags,
                                     setUp=setUp, tearDown=tearDown,
                                     checker=checker) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:noseclasses.py

示例7: loadTestsFromModule

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def loadTestsFromModule(self, module):
        """Load doctests from the module.
        """
        log.debug("loading from %s", module)
        if not self.matches(module.__name__):
            log.debug("Doctest doesn't want module %s", module)
            return
        try:
            tests = self.finder.find(module)
        except AttributeError:
            log.exception("Attribute error loading from %s", module)
            # nose allows module.__test__ = False; doctest does not and throws
            # AttributeError
            return
        if not tests:
            log.debug("No tests found in %s", module)
            return
        tests.sort()
        module_file = src(module.__file__)
        # FIXME this breaks the id plugin somehow (tests probably don't
        # get wrapped in result proxy or something)
        cases = []
        for test in tests:
            if not test.examples:
                continue
            if not test.filename:
                test.filename = module_file
            cases.append(DocTestCase(test,
                                     optionflags=self.optionflags,
                                     result_var=self.doctest_result_var))
        if cases:
            yield self.suiteClass(cases, context=module, can_split=False) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:34,代码来源:doctests.py

示例8: makeTest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def makeTest(self, obj, parent):
        """Look for doctests in the given object, which will be a
        function, method or class.
        """
        name = getattr(obj, '__name__', 'Unnammed %s' % type(obj))
        doctests = self.finder.find(obj, module=getmodule(parent), name=name)
        if doctests:
            for test in doctests:
                if len(test.examples) == 0:
                    continue
                yield DocTestCase(test, obj=obj, optionflags=self.optionflags,
                                  result_var=self.doctest_result_var) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:14,代码来源:doctests.py

示例9: __init__

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
                 checker=None, obj=None, result_var='_'):
        self._result_var = result_var
        self._nose_obj = obj
        super(DocTestCase, self).__init__(
            test, optionflags=optionflags, setUp=setUp, tearDown=tearDown,
            checker=checker) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:9,代码来源:doctests.py

示例10: setUp

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def setUp(self):
        if self._result_var is not None:
            self._old_displayhook = sys.displayhook
            sys.displayhook = self._displayhook
        super(DocTestCase, self).setUp() 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:7,代码来源:doctests.py

示例11: tearDown

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def tearDown(self):
        super(DocTestCase, self).tearDown()
        if self._result_var is not None:
            sys.displayhook = self._old_displayhook
            delattr(builtin_mod, self._result_var) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:7,代码来源:doctests.py

示例12: make_doctest

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def make_doctest(filename):
        filename = _get_caller_relative_path(filename)
        doctests = read_file(filename)
        doctests = _fix_unicode(r'\1\2', doctests)
        doctests = _fix_exceptions(r'\1 as \2', doctests)
        return doctest.DocTestCase(
            doctest_parser.get_doctest(
                doctests, {}, os.path.basename(filename), filename, 0)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:common_imports.py

示例13: check_output

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def check_output(self, want, got, optionflags):
        ret = doctest.OutputChecker.check_output(self, want, got,
                                                 optionflags)
        if not ret:
            if "#random" in want:
                return True

            # it would be useful to normalize endianness so that
            # bigendian machines don't fail all the tests (and there are
            # actually some bigendian examples in the doctests). Let's try
            # making them all little endian
            got = got.replace("'>", "'<")
            want= want.replace("'>", "'<")

            # try to normalize out 32 and 64 bit default int sizes
            for sz in [4, 8]:
                got = got.replace("'<i%d'"%sz, "int")
                want= want.replace("'<i%d'"%sz, "int")

            ret = doctest.OutputChecker.check_output(self, want,
                    got, optionflags)

        return ret


# Subclass nose.plugins.doctests.DocTestCase to work around a bug in
# its constructor that blocks non-default arguments from being passed
# down into doctest.DocTestCase 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:30,代码来源:noseclasses.py

示例14: __init__

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
                 checker=None, obj=None, result_var='_'):
        self._result_var = result_var
        doctests.DocTestCase.__init__(self, test,
                                      optionflags=optionflags,
                                      setUp=setUp, tearDown=tearDown,
                                      checker=checker)
        # Now we must actually copy the original constructor from the stdlib
        # doctest class, because we can't call it directly and a bug in nose
        # means it never gets passed the right arguments.

        self._dt_optionflags = optionflags
        self._dt_checker = checker
        self._dt_test = test
        self._dt_test_globs_ori = test.globs
        self._dt_setUp = setUp
        self._dt_tearDown = tearDown

        # XXX - store this runner once in the object!
        runner = IPDocTestRunner(optionflags=optionflags,
                                 checker=checker, verbose=False)
        self._dt_runner = runner


        # Each doctest should remember the directory it was loaded from, so
        # things like %run work without too many contortions
        self._ori_dir = os.path.dirname(test.filename)

    # Modified runTest from the default stdlib 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:31,代码来源:ipdoctest.py

示例15: tearDown

# 需要导入模块: import doctest [as 别名]
# 或者: from doctest import DocTestCase [as 别名]
def tearDown(self):

        # Undo the test.globs reassignment we made, so that the parent class
        # teardown doesn't destroy the ipython namespace
        if isinstance(self._dt_test.examples[0], IPExample):
            self._dt_test.globs = self._dt_test_globs_ori
            _ip.user_ns.clear()
            _ip.user_ns.update(self.user_ns_orig)

        # XXX - fperez: I am not sure if this is truly a bug in nose 0.11, but
        # it does look like one to me: its tearDown method tries to run
        #
        # delattr(__builtin__, self._result_var)
        #
        # without checking that the attribute really is there; it implicitly
        # assumes it should have been set via displayhook.  But if the
        # displayhook was never called, this doesn't necessarily happen.  I
        # haven't been able to find a little self-contained example outside of
        # ipython that would show the problem so I can report it to the nose
        # team, but it does happen a lot in our code.
        #
        # So here, we just protect as narrowly as possible by trapping an
        # attribute error whose message would be the name of self._result_var,
        # and letting any other error propagate.
        try:
            super(DocTestCase, self).tearDown()
        except AttributeError as exc:
            if exc.args[0] != self._result_var:
                raise


# A simple subclassing of the original with a different class name, so we can
# distinguish and treat differently IPython examples from pure python ones. 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:35,代码来源:ipdoctest.py


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