How to use the py.std function in py

To help you get started, we’ve selected a few py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytest-dev / pytest / py / apigen / linker.py View on Github external
def get_lazyhref(self, linkid):
        return '%s://%s' % (TEMPLINK_PROTO, linkid)

    def set_link(self, linkid, target):
        assert linkid not in self._linkid2target
        self._linkid2target[linkid] = target

    def get_target(self, tempurl, fromlocation=None):
        assert tempurl.startswith('%s://' % (TEMPLINK_PROTO,))
        linkid = '://'.join(tempurl.split('://')[1:])
        linktarget = self._linkid2target[linkid]
        if fromlocation is not None:
            linktarget = relpath(fromlocation, linktarget)
        return linktarget

    _reg_tempurl = py.std.re.compile('["\'](%s:\/\/[^"\s]*)["\']' % (
                                      TEMPLINK_PROTO,))
    def replace_dirpath(self, dirpath, stoponerrors=True):
        """ replace temporary links in all html files in dirpath and below """
        for fpath in dirpath.visit('*.html'):
            html = fpath.read()
            while 1:
                match = self._reg_tempurl.search(html)
                if not match:
                    break
                tempurl = match.group(1)
                try:
                    html = html.replace('"' + tempurl + '"',
                                        '"' + self.get_target(tempurl,
                                                fpath.relto(dirpath)) + '"')
                except KeyError:
                    if stoponerrors:
github pytest-dev / execnet / testing / test_gateway.py View on Github external
def test_deprecation(recwarn, monkeypatch):
    execnet.PopenGateway().exit()
    assert recwarn.pop(DeprecationWarning)
    monkeypatch.setattr(py.std.socket, 'socket', lambda *args: 0/0)
    py.test.raises(Exception, 'execnet.SocketGateway("localhost", 8811)')
    assert recwarn.pop(DeprecationWarning)
    monkeypatch.setattr(py.std.subprocess, 'Popen', lambda *args,**kwargs: 0/0)
    py.test.raises(Exception, 'execnet.SshGateway("not-existing")')
    assert recwarn.pop(DeprecationWarning)
github pytest-dev / pytest / _py / rest / convert.py View on Github external
def convert_dot(fn, new_extension):
    if not py.path.local.sysfind("dot"):
        raise SystemExit("ERROR: dot not found")
    result = fn.new(ext=new_extension)
    print(result)
    arg = "-T%s" % (format_to_dotargument[new_extension], )
    py.std.os.system('dot "%s" "%s" > "%s"' % (arg, fn, result))
    if new_extension == "eps":
        ps = result.new(ext="ps")
        result.move(ps)
        ps2eps(ps)
        ps.remove()
    elif new_extension == "pdf":
        # convert to eps file first, to get the bounding box right
        eps = result.new(ext="eps")
        ps = result.new(ext="ps")
        result.move(ps)
        ps2eps(ps)
        eps2pdf(eps)
        ps.remove()
        eps.remove()
    return result
github pytest-dev / pytest / _py / rest / latex.py View on Github external
publish_cmdline(writer_name='latex', argv=options)
    i = 0
    while i < 10: # there should never be as many as five reruns, but to be sure
        try:
            latexoutput = py.process.cmdexec('pdflatex "%s"' % (tex, ))
        except ExecutionFailed:
            e = py.std.sys.exc_info()[1]
            print("ERROR: pdflatex execution failed")
            print("pdflatex stdout:")
            print(e.out)
            print("pdflatex stderr:")
            print(e.err)
            raise SystemExit
        if debug:
            print(latexoutput)
        if py.std.re.search("LaTeX Warning:.*Rerun", latexoutput) is None:
            break
        i += 1
            
    old.chdir()
    #cleanup:
    if not debug:
        for ext in "log aux tex out".split():
            p = pdf.new(ext=ext)
            p.remove()
github pytest-dev / pytest / py / misc / testing / test_oskill.py View on Github external
def test_win_killsubprocess():
    if sys.platform == 'win32' and not py.path.local.sysfind('taskkill'):
        py.test.skip("you\'re using an older version of windows, which "
                     "doesn\'t support 'taskkill' - py.misc.killproc is not "
                     "available")
    try:
        import subprocess
    except ImportError:
        py.test.skip("no subprocess module")
    tmp = py.test.ensuretemp("test_win_killsubprocess")
    t = tmp.join("t.py")
    t.write("import time ; time.sleep(100)")
    proc = py.std.subprocess.Popen([sys.executable, str(t)])
    assert proc.poll() is None # no return value yet
    killproc(proc.pid)
    ret = proc.wait()
    assert ret != 0
github web-platform-tests / wpt / tools / py / py / _path / svnwc.py View on Github external
def url_from_path(path):
    fspath = path_to_fspath(path, False)
    quote = py.std.urllib.quote
    if ISWINDOWS:
        match = _reg_allow_disk.match(fspath)
        fspath = fspath.replace('\\', '/')
        if match.group(1):
            fspath = '/%s%s' % (match.group(1).replace('\\', '/'),
                                quote(fspath[len(match.group(1)):]))
        else:
            fspath = quote(fspath)
    else:
        fspath = quote(fspath)
    if path.rev != -1:
        fspath = '%s@%s' % (fspath, path.rev)
    else:
        fspath = '%s@HEAD' % (fspath,)
    return 'file://%s' % (fspath,)
github web-platform-tests / wpt / tools / py / testing / path / test_local.py View on Github external
try:
            fd, name = tempfile.mkstemp()
            py.std.os.close(fd)
        except AttributeError:
            name = tempfile.mktemp()
            open(name, 'w').close()
        try:
            mtime = int(time.time())-100
            path = local(name)
            assert path.mtime() != mtime
            path.setmtime(mtime)
            assert path.mtime() == mtime
            path.setmtime()
            assert path.mtime() != mtime
        finally:
            py.std.os.remove(name)
github pytest-dev / pytest / py / _compat / dep_subprocess.py View on Github external
import py
py.log._apiwarn("1.1", "py.compat.subprocess deprecated, use standard library version.",
stacklevel="apipkg")
subprocess = py.std.subprocess
github pytest-dev / pytest / testing / root / test_xmlgen.py View on Github external
def __str__(self):
            x = self.__unicode__()
            if py.std.sys.version_info[0] < 3:
                return x.encode('utf-8')
            return x
    y = py.xml.escape(uvalue)
github mozillazg / pypy / _pytest / genscript.py View on Github external
def find_toplevel(name):
    for syspath in py.std.sys.path:
        base = py.path.local(syspath)
        lib = base/name
        if lib.check(dir=1):
            return lib
        mod = base.join("%s.py" % name)
        if mod.check(file=1):
            return mod
    raise LookupError(name)