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


Python NativeStringIO.getvalue方法代码示例

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


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

示例1: test_warningToFile

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
    def test_warningToFile(self):
        """
        L{twisted.python.log.showwarning} passes warnings with an explicit file
        target on to the underlying Python warning system.
        """
        # log.showwarning depends on _oldshowwarning being set, which only
        # happens in startLogging(), which doesn't happen if you're not
        # running under trial. So this test only passes by accident of runner
        # environment.
        if log._oldshowwarning is None:
            raise unittest.SkipTest("Currently this test only runs under trial.")
        message = "another unique message"
        category = FakeWarning
        filename = "warning-filename.py"
        lineno = 31

        output = StringIO()
        log.showwarning(message, category, filename, lineno, file=output)

        self.assertEqual(
            output.getvalue(),
            warnings.formatwarning(message, category, filename, lineno))

        # In Python 2.6, warnings.showwarning accepts a "line" argument which
        # gives the source line the warning message is to include.
        if sys.version_info >= (2, 6):
            line = "hello world"
            output = StringIO()
            log.showwarning(message, category, filename, lineno, file=output,
                            line=line)

            self.assertEqual(
                output.getvalue(),
                warnings.formatwarning(message, category, filename, lineno,
                                       line))
开发者ID:0004c,项目名称:VTK,代码行数:37,代码来源:test_log.py

示例2: test_warningToFile

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
    def test_warningToFile(self):
        """
        L{twisted.python.log.showwarning} passes warnings with an explicit file
        target on to the underlying Python warning system.
        """
        message = "another unique message"
        category = FakeWarning
        filename = "warning-filename.py"
        lineno = 31

        output = StringIO()
        log.showwarning(message, category, filename, lineno, file=output)

        self.assertEqual(
            output.getvalue(),
            warnings.formatwarning(message, category, filename, lineno))

        # In Python 2.6 and higher, warnings.showwarning accepts
        # a "line" argument which gives the source line the warning
        # message is to include.
        line = "hello world"
        output = StringIO()
        log.showwarning(message, category, filename, lineno, file=output,
                        line=line)

        self.assertEqual(
            output.getvalue(),
            warnings.formatwarning(message, category, filename, lineno,
                                   line))
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:31,代码来源:test_log.py

示例3: test_printingSmokeTest

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
 def test_printingSmokeTest(self):
     """
     None of the print* methods fail when called.
     """
     f = getDivisionFailure()
     out = NativeStringIO()
     f.printDetailedTraceback(out)
     self.assertStartsWith(out.getvalue(), '*--- Failure')
     out = NativeStringIO()
     f.printBriefTraceback(out)
     self.assertStartsWith(out.getvalue(), 'Traceback')
     out = NativeStringIO()
     f.printTraceback(out)
     self.assertStartsWith(out.getvalue(), 'Traceback')
开发者ID:AmirKhooj,项目名称:VTK,代码行数:16,代码来源:test_failure.py

示例4: test_printingNoVars

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
 def test_printingNoVars(self):
     """
     Calling C{Failure()} with no arguments does not capture any locals or
     globals, so L{printDetailedTraceback} cannot show them in its output.
     """
     out = NativeStringIO()
     f = getDivisionFailure()
     f.printDetailedTraceback(out)
     # There should be no variables in the detailed output.  Variables are
     # printed on lines with 2 leading spaces.
     linesWithVars = [line for line in out.getvalue().splitlines()
                      if line.startswith('  ')]
     self.assertEqual([], linesWithVars)
     self.assertIn(
         'Capture of Locals and Globals disabled', out.getvalue())
开发者ID:AmirKhooj,项目名称:VTK,代码行数:17,代码来源:test_failure.py

示例5: test_insufficient_args

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
    def test_insufficient_args(self):
        """
        Calling run() with no args will cause it to print help.
        """
        stringio = NativeStringIO()
        self.patch(sys, 'stdout', stringio)
        self.patch(os, 'getcwd', self.getcwd)
        self.patch(datetime, 'date', self.date)

        with self.assertRaises(SystemExit) as e:
            run(["inctestpkg", "--rc"])

        self.assertEqual(e.exception.args[0], 0)
        self.assertIn("Updating codebase", stringio.getvalue())

        self.assertEqual(self.packagedir.child("_version.py").getContent(),
                         b'''"""
Provides inctestpkg version information.
"""

# This file is auto-generated! Do not edit!
# Use `python -m incremental.update inctestpkg` to change this file.

from incremental import Version

__version__ = Version('inctestpkg', 16, 8, 0, release_candidate=1)
__all__ = ["__version__"]
''')
        self.assertEqual(self.packagedir.child("__init__.py").getContent(),
                         b"""
from incremental import Version
introduced_in = Version('inctestpkg', 16, 8, 0, release_candidate=1).short()
next_released_version = "inctestpkg 16.8.0rc1"
""")
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:36,代码来源:test_update.py

示例6: test_startLogging

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
 def test_startLogging(self):
     """
     startLogging() installs FileLogObserver and overrides sys.stdout and
     sys.stderr.
     """
     origStdout, origStderr = sys.stdout, sys.stderr
     self._startLoggingCleanup()
     # When done with test, reset stdout and stderr to current values:
     fakeFile = StringIO()
     observer = log.startLogging(fakeFile)
     self.addCleanup(observer.stop)
     log.msg("Hello!")
     self.assertIn("Hello!", fakeFile.getvalue())
     self.assertIsInstance(sys.stdout, log.StdioOnnaStick)
     self.assertEqual(sys.stdout.isError, False)
     encoding = getattr(origStdout, "encoding", None)
     if not encoding:
         encoding = sys.getdefaultencoding()
     self.assertEqual(sys.stdout.encoding, encoding)
     self.assertIsInstance(sys.stderr, log.StdioOnnaStick)
     self.assertEqual(sys.stderr.isError, True)
     encoding = getattr(origStderr, "encoding", None)
     if not encoding:
         encoding = sys.getdefaultencoding()
     self.assertEqual(sys.stderr.encoding, encoding)
开发者ID:0004c,项目名称:VTK,代码行数:27,代码来源:test_log.py

示例7: test_reporter

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
    def test_reporter(self):
        """
        Test for LimitedReporter.
        Use test file of indentation to test
        whether limited messages are returned when using LimitedReporter.

        Complete run on the test file will return two warnings:
        W0311 and W0312, but with limited report it returns only one.
        """
        moduleTestIndentation = "twistedchecker.functionaltests.indentation"
        pathTestIndentation = os.path.join(twistedchecker.abspath,
                                      "functionaltests", "indentation.py")
        # assert the test file exists
        self.assertTrue(os.path.exists(pathTestIndentation))
        streamTestResult = NativeStringIO()
        runner = Runner()
        runner.setOutput(streamTestResult)
        # defaultly, runner will use LimitedReporter as its output reporter
        # set allowed messages for it
        runner.linter.reporter.messagesAllowed = set(["W0311"])

        exitResult = self.assertRaises(
            SystemExit, runner.run, [moduleTestIndentation])

        # check the results to see only W0311 is reported
        resultTest = streamTestResult.getvalue()
        self.assertTrue("W0311" in resultTest)
        self.assertTrue("W0312" not in resultTest)
        self.assertEqual(4, exitResult.code)
开发者ID:twisted,项目名称:twistedchecker,代码行数:31,代码来源:test_limitedreporter.py

示例8: test_emitPrefix

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
    def test_emitPrefix(self):
        """
        FileLogObserver.emit() will add a timestamp and system prefix to its
        file output.
        """
        output = StringIO()
        flo = log.FileLogObserver(output)
        events = []

        def observer(event):
            # Capture the event for reference and pass it along to flo
            events.append(event)
            flo.emit(event)

        publisher = log.LogPublisher()
        publisher.addObserver(observer)

        publisher.msg("Hello!")
        self.assertEqual(len(events), 1)
        event = events[0]

        result = output.getvalue()
        prefix = "{time} [{system}] ".format(
            time=flo.formatTime(event["time"]), system=event["system"],
        )

        self.assertTrue(
            result.startswith(prefix),
            "{0!r} does not start with {1!r}".format(result, prefix)
        )
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:32,代码来源:test_log.py

示例9: test_startLogging

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
 def test_startLogging(self):
     """
     startLogging() installs FileLogObserver and overrides sys.stdout and
     sys.stderr.
     """
     origStdout, origStderr = sys.stdout, sys.stderr
     self._startLoggingCleanup()
     # When done with test, reset stdout and stderr to current values:
     fakeFile = StringIO()
     observer = log.startLogging(fakeFile)
     self.addCleanup(observer.stop)
     log.msg("Hello!")
     self.assertIn("Hello!", fakeFile.getvalue())
     self.assertIsInstance(sys.stdout, LoggingFile)
     self.assertEqual(sys.stdout.level, NewLogLevel.info)
     encoding = getattr(origStdout, "encoding", None)
     if not encoding:
         encoding = sys.getdefaultencoding()
     self.assertEqual(sys.stdout.encoding.upper(), encoding.upper())
     self.assertIsInstance(sys.stderr, LoggingFile)
     self.assertEqual(sys.stderr.level, NewLogLevel.error)
     encoding = getattr(origStderr, "encoding", None)
     if not encoding:
         encoding = sys.getdefaultencoding()
     self.assertEqual(sys.stderr.encoding.upper(), encoding.upper())
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:27,代码来源:test_log.py

示例10: UL

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
def UL(lst):
    io = StringIO()
    io.write("<ul>\n")
    for el in lst:
        io.write("<li> %s</li>\n" % el)
    io.write("</ul>")
    return io.getvalue()
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:9,代码来源:html.py

示例11: linkList

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
def linkList(lst):
    io = StringIO()
    io.write("<ul>\n")
    for hr, el in lst:
        io.write('<li> <a href="%s">%s</a></li>\n' % (hr, el))
    io.write("</ul>")
    return io.getvalue()
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:9,代码来源:html.py

示例12: test_removeSafelyRemoveFailsMoveSucceeds

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
    def test_removeSafelyRemoveFailsMoveSucceeds(self):
        """
        If an L{OSError} is raised while removing a path in
        L{util._removeSafely}, an attempt is made to move the path to a new
        name.
        """
        def dummyRemove():
            """
            Raise an C{OSError} to emulate the branch of L{util._removeSafely}
            in which path removal fails.
            """
            raise OSError()

        # Patch stdout so we can check the print statements in _removeSafely
        out = NativeStringIO()
        self.patch(sys, 'stdout', out)

        # Set up a trial directory with a _trial_marker
        directory = self.mktemp().encode("utf-8")
        os.mkdir(directory)
        dirPath = filepath.FilePath(directory)
        dirPath.child(b'_trial_marker').touch()
        # Ensure that path.remove() raises an OSError
        dirPath.remove = dummyRemove

        util._removeSafely(dirPath)
        self.assertIn("could not remove FilePath", out.getvalue())
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:29,代码来源:test_util.py

示例13: render

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
    def render(self, request):
        """
        Render me to a web client.

        Load my file, execute it in a special namespace (with 'request' and
        '__file__' global vars) and finish the request.  Output to the web-page
        will NOT be handled with print - standard output goes to the log - but
        with request.write.
        """
        request.setHeader(b"x-powered-by", networkString("Twisted/%s" % copyright.version))
        namespace = {'request': request,
                     '__file__': _coerceToFilesystemEncoding("", self.filename),
                     'registry': self.registry}
        try:
            execfile(self.filename, namespace, namespace)
        except IOError as e:
            if e.errno == 2: #file not found
                request.setResponseCode(http.NOT_FOUND)
                request.write(resource.NoResource("File not found.").render(request))
        except:
            io = NativeStringIO()
            traceback.print_exc(file=io)
            output = util._PRE(io.getvalue())
            if _PY3:
                output = output.encode("utf8")
            request.write(output)
        request.finish()
        return server.NOT_DONE_YET
开发者ID:Architektor,项目名称:PySnip,代码行数:30,代码来源:script.py

示例14: dump

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
        def dump():
            if not self._passed:
                dump = NativeStringIO()
                print("FAILED! dumping build db for debug", file=dump)
                builds = yield self.master.data.get(("builds",))
                for build in builds:
                    yield self.printBuild(build, dump, withLogs=True)

                raise self.failureException(dump.getvalue())
开发者ID:dinatale2,项目名称:buildbot,代码行数:11,代码来源:integration.py

示例15: test_suppresses

# 需要导入模块: from twisted.python.compat import NativeStringIO [as 别名]
# 或者: from twisted.python.compat.NativeStringIO import getvalue [as 别名]
 def test_suppresses(self):
     """
     Any warnings emitted by a call to a function passed to
     L{_collectWarnings} are not actually emitted to the warning system.
     """
     output = StringIO()
     self.patch(sys, 'stdout', output)
     _collectWarnings(lambda x: None, warnings.warn, "text")
     self.assertEqual(output.getvalue(), "")
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:11,代码来源:test_warning.py


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