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


Python StringIO.getvalue方法代碼示例

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


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

示例1: runTest

# 需要導入模塊: from StringIO import StringIO [as 別名]
# 或者: from StringIO.StringIO import getvalue [as 別名]
def runTest(self):
        test = self._dt_test
        old = sys.stdout
        new = StringIO()
        optionflags = self._dt_optionflags

        if not (optionflags & REPORTING_FLAGS):
            # The option flags don't include any reporting flags,
            # so add the default reporting flags
            optionflags |= _unittest_reportflags

        runner = DocTestRunner(optionflags=optionflags,
                               checker=self._dt_checker, verbose=False)

        try:
            runner.DIVIDER = "-"*70
            failures, tries = runner.run(
                test, out=new.write, clear_globs=False)
        finally:
            sys.stdout = old

        if failures:
            raise self.failureException(self.format_failure(new.getvalue())) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:25,代碼來源:doctest.py

示例2: _exception_traceback

# 需要導入模塊: from StringIO import StringIO [as 別名]
# 或者: from StringIO.StringIO import getvalue [as 別名]
def _exception_traceback(exc_info):
    excout = StringIO()
    exc_type, exc_val, exc_tb = exc_info
    traceback.print_exception(exc_type, exc_val, exc_tb, file=excout)
    return excout.getvalue() 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:7,代碼來源:doctest_driver.py

示例3: getvalue

# 需要導入模塊: from StringIO import StringIO [as 別名]
# 或者: from StringIO.StringIO import getvalue [as 別名]
def getvalue(self):
        result = StringIO.getvalue(self)
        if result and not result.endswith("\n"):
            result += "\n"
        if hasattr(self, "softspace"):
            del self.softspace
        return result 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:9,代碼來源:doctest_driver.py

示例4: _check_output

# 需要導入模塊: from StringIO import StringIO [as 別名]
# 或者: from StringIO.StringIO import getvalue [as 別名]
def _check_output(self, example):
        want = example.want
        optionflags = self._get_optionflags(example)
        got = sys.stdout.getvalue()
        sys.stdout.truncate(0)
        if not self.checker.check_output(want, got, optionflags):
            self.runner.report_failure(self.save_stdout.write, 
                                       self.test, example, got)
            return False
        else:
            return True 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:13,代碼來源:doctest_driver.py

示例5: _exception_traceback

# 需要導入模塊: from StringIO import StringIO [as 別名]
# 或者: from StringIO.StringIO import getvalue [as 別名]
def _exception_traceback(exc_info):
    """
    Return a string containing a traceback message for the given
    exc_info tuple (as returned by sys.exc_info()).
    """
    # Get a traceback message.
    excout = StringIO()
    exc_type, exc_val, exc_tb = exc_info
    traceback.print_exception(exc_type, exc_val, exc_tb, file=excout)
    return excout.getvalue()

# Override some StringIO methods. 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:14,代碼來源:doctest24.py

示例6: getvalue

# 需要導入模塊: from StringIO import StringIO [as 別名]
# 或者: from StringIO.StringIO import getvalue [as 別名]
def getvalue(self):
        result = StringIO.getvalue(self)
        # If anything at all was written, make sure there's a trailing
        # newline.  There's no way for the expected output to indicate
        # that a trailing newline is missing.
        if result and not result.endswith("\n"):
            result += "\n"
        # Prevent softspace from screwing up the next test case, in
        # case they used print with a trailing comma in an example.
        if hasattr(self, "softspace"):
            del self.softspace
        return result 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:14,代碼來源:doctest24.py


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