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


Python builtin.print_函数代码示例

本文整理汇总了Python中py.builtin.print_函数的典型用法代码示例。如果您正苦于以下问题:Python print_函数的具体用法?Python print_怎么用?Python print_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _run

 def _run(self, *cmdargs):
     cmdargs = [str(x) for x in cmdargs]
     p1 = self.tmpdir.join("stdout")
     p2 = self.tmpdir.join("stderr")
     print_("running:", ' '.join(cmdargs))
     print_("     in:", str(py.path.local()))
     f1 = codecs.open(str(p1), "w", encoding="utf8")
     f2 = codecs.open(str(p2), "w", encoding="utf8")
     try:
         now = time.time()
         popen = self.popen(cmdargs, stdout=f1, stderr=f2,
             close_fds=(sys.platform != "win32"))
         ret = popen.wait()
     finally:
         f1.close()
         f2.close()
     f1 = codecs.open(str(p1), "r", encoding="utf8")
     f2 = codecs.open(str(p2), "r", encoding="utf8")
     try:
         out = f1.read().splitlines()
         err = f2.read().splitlines()
     finally:
         f1.close()
         f2.close()
     self._dump_lines(out, sys.stdout)
     self._dump_lines(err, sys.stderr)
     return RunResult(ret, out, err, time.time()-now)
开发者ID:JanBednarik,项目名称:pytest,代码行数:27,代码来源:pytester.py

示例2: fnmatch_lines

    def fnmatch_lines(self, lines2):
        if isinstance(lines2, str):
            lines2 = py.code.Source(lines2)
        if isinstance(lines2, py.code.Source):
            lines2 = lines2.strip().lines

        from fnmatch import fnmatch
        __tracebackhide__ = True
        lines1 = self.lines[:]
        nextline = None
        extralines = []
        for line in lines2:
            nomatchprinted = False
            while lines1:
                nextline = lines1.pop(0)
                if line == nextline:
                    print_("exact match:", repr(line))
                    break 
                elif fnmatch(nextline, line):
                    print_("fnmatch:", repr(line))
                    print_("   with:", repr(nextline))
                    break
                else:
                    if not nomatchprinted:
                        print_("nomatch:", repr(line))
                        nomatchprinted = True
                    print_("    and:", repr(nextline))
                extralines.append(nextline)
            else:
                if line != nextline:
                    #__tracebackhide__ = True
                    raise AssertionError("expected line not found: %r" % line)
        extralines.extend(lines1)
        return extralines 
开发者ID:bigmlcom,项目名称:pylibs,代码行数:34,代码来源:pytest_pytester.py

示例3: test_stderr

 def test_stderr(self):
     cap = capture.FDCapture(2)
     cap.start()
     print_("hello", file=sys.stderr)
     s = cap.snap()
     cap.done()
     assert s == "hello\n"
开发者ID:eli-b,项目名称:pytest,代码行数:7,代码来源:test_capture.py

示例4: fnmatch_lines

    def fnmatch_lines(self, lines2):
        if isinstance(lines2, str):
            lines2 = py.code.Source(lines2)
        if isinstance(lines2, py.code.Source):
            lines2 = lines2.strip().lines

        from fnmatch import fnmatch

        lines1 = self.lines[:]
        nextline = None
        extralines = []
        __tracebackhide__ = True
        for line in lines2:
            nomatchprinted = False
            while lines1:
                nextline = lines1.pop(0)
                if line == nextline:
                    print_("exact match:", repr(line))
                    break
                elif fnmatch(nextline, line):
                    print_("fnmatch:", repr(line))
                    print_("   with:", repr(nextline))
                    break
                else:
                    if not nomatchprinted:
                        print_("nomatch:", repr(line))
                        nomatchprinted = True
                    print_("    and:", repr(nextline))
                extralines.append(nextline)
            else:
                assert line == nextline
开发者ID:pombredanne,项目名称:tox,代码行数:31,代码来源:conftest.py

示例5: _run

    def _run(self, *cmdargs):
        cmdargs = [str(x) for x in cmdargs]
        p1 = self.tmpdir.join("stdout")
        p2 = self.tmpdir.join("stderr")
        print_("running", cmdargs, "curdir=", py.path.local())
        f1 = p1.open("wb")
        f2 = p2.open("wb")
        now = time.time()
        popen = self.popen(cmdargs, stdout=f1, stderr=f2, close_fds=(sys.platform != "win32"))
        ret = popen.wait()
        f1.close()
        f2.close()
        out = p1.read("rb")
        out = getdecoded(out).splitlines()
        err = p2.read("rb")
        err = getdecoded(err).splitlines()

        def dump_lines(lines, fp):
            try:
                for line in lines:
                    py.builtin.print_(line, file=fp)
            except UnicodeEncodeError:
                print("couldn't print to %s because of encoding" % (fp,))

        dump_lines(out, sys.stdout)
        dump_lines(err, sys.stderr)
        return RunResult(ret, out, err, time.time() - now)
开发者ID:chrischeyne,项目名称:python-virtualenv,代码行数:27,代码来源:pytester.py

示例6: fnmatch_lines_random

 def fnmatch_lines_random(self, lines2):
     lines2 = self._getlines(lines2)
     for line in lines2:
         for x in self.lines:
             if line == x or fnmatch(x, line):
                 print_("matched: ", repr(line))
                 break
         else:
             raise ValueError("line %r not found in output" % line)
开发者ID:chrischeyne,项目名称:python-virtualenv,代码行数:9,代码来源:pytester.py

示例7: fnmatch_lines_random

    def fnmatch_lines_random(self, lines2):
        """Check lines exist in the output.

        The argument is a list of lines which have to occur in the
        output, in any order.  Each line can contain glob whildcards.

        """
        lines2 = self._getlines(lines2)
        for line in lines2:
            for x in self.lines:
                if line == x or fnmatch(x, line):
                    print_("matched: ", repr(line))
                    break
            else:
                raise ValueError("line %r not found in output" % line)
开发者ID:JanBednarik,项目名称:pytest,代码行数:15,代码来源:pytester.py

示例8: test_dupfile

def test_dupfile(tmpfile):
    flist = []
    for i in range(5):
        nf = capture.safe_text_dupfile(tmpfile, "wb")
        assert nf != tmpfile
        assert nf.fileno() != tmpfile.fileno()
        assert nf not in flist
        print_(i, end="", file=nf)
        flist.append(nf)
    for i in range(5):
        f = flist[i]
        f.close()
    tmpfile.seek(0)
    s = tmpfile.read()
    assert "01234" in repr(s)
    tmpfile.close()
开发者ID:eli-b,项目名称:pytest,代码行数:16,代码来源:test_capture.py

示例9: test_dupfile

def test_dupfile(tmpfile):
    flist = []
    for i in range(5):
        nf = py.io.dupfile(tmpfile, encoding="utf-8")
        assert nf != tmpfile
        assert nf.fileno() != tmpfile.fileno()
        assert nf not in flist
        print_(i, end="", file=nf)
        flist.append(nf)
    for i in range(5):
        f = flist[i]
        f.close()
    tmpfile.seek(0)
    s = tmpfile.read()
    assert "01234" in repr(s)
    tmpfile.close()
开发者ID:Coder206,项目名称:servo,代码行数:16,代码来源:test_capture.py

示例10: getrepowc

def getrepowc(tmpdir, reponame='basetestrepo', wcname='wc'):
    repo = tmpdir.mkdir(reponame)
    wcdir = tmpdir.mkdir(wcname)
    repo.ensure(dir=1)
    py.process.cmdexec('svnadmin create "%s"' %
            svncommon._escape_helper(repo))
    py.process.cmdexec('svnadmin load -q "%s" <"%s"' %
            (svncommon._escape_helper(repo), repodump))
    print_("created svn repository", repo)
    wcdir.ensure(dir=1)
    wc = py.path.svnwc(wcdir)
    if py.std.sys.platform == 'win32':
        repourl = "file://" + '/' + str(repo).replace('\\', '/')
    else:
        repourl = "file://%s" % repo
    wc.checkout(repourl)
    print_("checked out new repo into", wc)
    return (repo, repourl, wc)
开发者ID:6br,项目名称:servo,代码行数:18,代码来源:conftest.py

示例11: _run

 def _run(self, *cmdargs):
     cmdargs = [str(x) for x in cmdargs]
     p1 = py.path.local("stdout")
     p2 = py.path.local("stderr")
     print_("running", cmdargs, "curdir=", py.path.local())
     f1 = p1.open("w")
     f2 = p2.open("w")
     popen = self.popen(cmdargs, stdout=f1, stderr=f2, 
         close_fds=(sys.platform != "win32"))
     ret = popen.wait()
     f1.close()
     f2.close()
     out, err = p1.readlines(cr=0), p2.readlines(cr=0)
     if err:
         for line in err: 
             py.builtin.print_(line, file=sys.stderr)
     if out:
         for line in out: 
             py.builtin.print_(line, file=sys.stdout)
     return RunResult(ret, out, err)
开发者ID:alkorzt,项目名称:pypy,代码行数:20,代码来源:pytest_pytester.py

示例12: assert_contains

 def assert_contains(self, entries):
     __tracebackhide__ = True
     i = 0
     entries = list(entries)
     backlocals = sys._getframe(1).f_locals
     while entries:
         name, check = entries.pop(0)
         for ind, call in enumerate(self.calls[i:]):
             if call._name == name:
                 print_("NAMEMATCH", name, call)
                 if eval(check, backlocals, call.__dict__):
                     print_("CHECKERMATCH", repr(check), "->", call)
                 else:
                     print_("NOCHECKERMATCH", repr(check), "-", call)
                     continue
                 i += ind + 1
                 break
             print_("NONAMEMATCH", name, "with", call)
         else:
             pytest.fail("could not find %r check %r" % (name, check))
开发者ID:JanBednarik,项目名称:pytest,代码行数:20,代码来源:pytester.py

示例13: test_print_simple

def test_print_simple():
    from py.builtin import print_
    py.test.raises(TypeError, "print_(hello=3)")
    f = py.io.TextIO()
    print_("hello", "world", file=f)
    s = f.getvalue()
    assert s == "hello world\n"

    f = py.io.TextIO()
    print_("hello", end="", file=f)
    s = f.getvalue()
    assert s == "hello"

    f = py.io.TextIO()
    print_("xyz", "abc", sep="", end="", file=f)
    s = f.getvalue()
    assert s == "xyzabc"

    class X:
        def __repr__(self): return "rep"
    f = py.io.TextIO()
    print_(X(), file=f)
    assert f.getvalue() == "rep\n"
开发者ID:6br,项目名称:servo,代码行数:23,代码来源:test_builtin.py

示例14: write_log_entry

 def write_log_entry(self, testpath, shortrepr, longrepr):
     print_("%s %s" % (shortrepr, testpath), file=self.logfile)
     for line in longrepr.splitlines():
         print_(" %s" % line, file=self.logfile)
开发者ID:bigmlcom,项目名称:pylibs,代码行数:4,代码来源:pytest_resultlog.py

示例15: write_log_entry

 def write_log_entry(self, testpath, lettercode, longrepr):
     print_("%s %s" % (lettercode, testpath), file=self.logfile)
     for line in longrepr.splitlines():
         print_(" %s" % line, file=self.logfile)
开发者ID:hoprocker,项目名称:mylons,代码行数:4,代码来源:resultlog.py


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