How to use the py.path 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 tox-dev / tox / tests / unit / test_z_cmdline.py View on Github external
def test_log_pcall(self, mocksession):
        mocksession.logging_levels(quiet=Verbosity.DEFAULT, verbose=Verbosity.INFO)
        mocksession.config.logdir.ensure(dir=1)
        assert not mocksession.config.logdir.listdir()
        with mocksession.newaction("what", "something") as action:
            action.popen(["echo"])
            match = mocksession.report.getnext("logpopen")
            log_name = py.path.local(match[1].split(">")[-1].strip()).relto(
                mocksession.config.logdir
            )
            assert log_name == "what-0.log"
github pytest-dev / pytest / py / _process / forkedfunc.py View on Github external
def __init__(self, fun, args=None, kwargs=None, nice_level=0):
        if args is None:
            args = []
        if kwargs is None:
            kwargs = {}
        self.fun = fun
        self.args = args
        self.kwargs = kwargs
        self.tempdir = tempdir = py.path.local.mkdtemp()
        self.RETVAL = tempdir.ensure('retval')
        self.STDOUT = tempdir.ensure('stdout')
        self.STDERR = tempdir.ensure('stderr')

        pid = os.fork()
        if pid: # in parent process
            self.pid = pid
        else: # in child process
            self._child(nice_level)
github touilleMan / godot-python / tests / _lib_vendors / py / _path / local.py View on Github external
def get_temproot(cls):
        """ return the system's temporary directory
            (where tempfiles are usually created in)
        """
        return py.path.local(py.std.tempfile.gettempdir())
    get_temproot = classmethod(get_temproot)
github microsoft / ptvsd / tests / debug / session.py View on Github external
def spawn_debuggee(self, args, cwd=None, exe=sys.executable, debug_me=None):
        assert self.debuggee is None
        assert not len(self.captured_output - {"stdout", "stderr"})

        args = [exe] + [
            compat.filename_str(s.strpath if isinstance(s, py.path.local) else s)
            for s in args
        ]

        cwd = compat.filename_str(cwd) if isinstance(cwd, py.path.local) else cwd

        env = self._make_env(self.spawn_debuggee.env, codecov=False)
        env["PTVSD_ADAPTER_ENDPOINTS"] = self.adapter_endpoints = (
            self.tmpdir / "adapter_endpoints"
        )
        if debug_me is not None:
            env["PTVSD_TEST_DEBUG_ME"] = debug_me

        log.info(
            "Spawning {0}:\n\n"
            "Current directory: {1!j}\n\n"
            "Command line: {2!j}\n\n"
github spack / spack / lib / spack / external / _pytest / python.py View on Github external
def filter_traceback(entry):
    """Return True if a TracebackEntry instance should be removed from tracebacks:
    * dynamically generated code (no code to show up for it);
    * internal traceback from pytest or its internal libraries, py and pluggy.
    """
    # entry.path might sometimes return a str object when the entry
    # points to dynamically generated code
    # see https://bitbucket.org/pytest-dev/py/issues/71
    raw_filename = entry.frame.code.raw.co_filename
    is_generated = '<' in raw_filename and '>' in raw_filename
    if is_generated:
        return False
    # entry.path might point to an inexisting file, in which case it will
    # alsso return a str object. see #1133
    p = py.path.local(entry.path)
    return p != cutdir1 and not p.relto(cutdir2) and not p.relto(cutdir3)
github Robpol86 / appveyor-artifacts / tests / test_artifacts_urls.py View on Github external
actual = artifacts_urls(config, jobs_artifacts)
    expected = dict()
    messages = [r.message for r in caplog.records]

    # Test-specific API URL.
    url = API_PREFIX + '/buildjobs/%s/artifacts/%s'

    if not no_job_dirs:
        assert 'Multiple job IDs with file conflicts, automatically setting job_dirs = True' in messages
        expected[py.path.local('v5wnn9k8auqcqovw/luajit.exe')] = (url % ('v5wnn9k8auqcqovw', 'luajit.exe'), 675840)
        expected[py.path.local('v5wnn9k8auqcqovw/luv.dll')] = (url % ('v5wnn9k8auqcqovw', 'luv.dll'), 891392)
        expected[py.path.local('v5wnn9k8auqcqovw/.coverage')] = (url % ('v5wnn9k8auqcqovw', '.coverage'), 123)
        expected[py.path.local('v5wnn9k8auqcqovw/no_ext')] = (url % ('v5wnn9k8auqcqovw', 'no_ext'), 456)
        expected[py.path.local('bpgcbvqmawv1jw06/luajit.exe')] = (url % ('bpgcbvqmawv1jw06', 'luajit.exe'), 539136)
        expected[py.path.local('bpgcbvqmawv1jw06/luv.dll')] = (url % ('bpgcbvqmawv1jw06', 'luv.dll'), 718336)
        expected[py.path.local('bpgcbvqmawv1jw06/.coverage')] = (url % ('bpgcbvqmawv1jw06', '.coverage'), 789)
        expected[py.path.local('bpgcbvqmawv1jw06/no_ext')] = (url % ('bpgcbvqmawv1jw06', 'no_ext'), 101)
    else:
        assert 'Multiple job IDs with file conflicts, automatically setting job_dirs = True' not in messages

    if no_job_dirs == 'skip':
        assert any(re.match(r'Skipping.*luajit\.exe.*bpgcbvqmawv1jw06', m) for m in messages)
        assert any(re.match(r'Skipping.*luv\.dll.*bpgcbvqmawv1jw06', m) for m in messages)
        assert any(re.match(r'Skipping.*\.coverage.*bpgcbvqmawv1jw06', m) for m in messages)
        assert any(re.match(r'Skipping.*no_ext.*bpgcbvqmawv1jw06', m) for m in messages)
        expected[py.path.local('luajit.exe')] = (url % ('v5wnn9k8auqcqovw', 'luajit.exe'), 675840)
        expected[py.path.local('luv.dll')] = (url % ('v5wnn9k8auqcqovw', 'luv.dll'), 891392)
        expected[py.path.local('.coverage')] = (url % ('v5wnn9k8auqcqovw', '.coverage'), 123)
        expected[py.path.local('no_ext')] = (url % ('v5wnn9k8auqcqovw', 'no_ext'), 456)
    else:
        assert not any(re.match(r'Skipping.*luajit\.exe.*bpgcbvqmawv1jw06', m) for m in messages)
github ikalnytskyi / holocron / tests / processors / test_commit.py View on Github external
    (b"\xf1", py.path.local.read_binary),
])
def test_item_content_types(testapp, monkeypatch, tmpdir, data, loader):
    """Commit processor has to properly write items" content."""

    monkeypatch.chdir(tmpdir)

    stream = commit.process(
        testapp,
        [
            core.Item(
                {
                    "content": data,
                    "destination": "1.dat",
                }),
        ])
github pytest-dev / pytest-xdist / src / xdist / plugin.py View on Github external
parser.addini(
        "rsyncdirs",
        "list of (relative) paths to be rsynced for remote distributed testing.",
        type="pathlist",
    )
    parser.addini(
        "rsyncignore",
        "list of (relative) glob-style paths to be ignored for rsyncing.",
        type="pathlist",
    )
    parser.addini(
        "looponfailroots",
        type="pathlist",
        help="directories to check for changes",
        default=[py.path.local()],
    )
github web-platform-tests / wpt / tools / third_party / pytest / src / _pytest / helpconfig.py View on Github external
def pytest_cmdline_main(config):
    if config.option.version:
        p = py.path.local(pytest.__file__)
        sys.stderr.write(
            "This is pytest version %s, imported from %s\n" % (pytest.__version__, p)
        )
        plugininfo = getpluginversioninfo(config)
        if plugininfo:
            for line in plugininfo:
                sys.stderr.write(line + "\n")
        return 0
    elif config.option.help:
        config._do_configure()
        showhelp(config)
        config._ensure_unconfigure()
        return 0
github servo / mozjs / mozjs / third_party / python / py / py / _code / source.py View on Github external
def compile(self, filename=None, mode='exec',
                flag=generators.compiler_flag,
                dont_inherit=0, _genframe=None):
        """ return compiled code object. if filename is None
            invent an artificial filename which displays
            the source/line position of the caller frame.
        """
        if not filename or py.path.local(filename).check(file=0):
            if _genframe is None:
                _genframe = sys._getframe(1) # the caller
            fn,lineno = _genframe.f_code.co_filename, _genframe.f_lineno
            base = "<%d-codegen " % self._compilecounter
            self.__class__._compilecounter += 1
            if not filename:
                filename = base + '%s:%d>' % (fn, lineno)
            else:
                filename = base + '%r %s:%d>' % (filename, fn, lineno)
        source = "\n".join(self.lines) + '\n'
        try:
            co = cpy_compile(source, filename, mode, flag)
        except SyntaxError:
            ex = sys.exc_info()[1]
            # re-represent syntax errors from parsing python strings
            msglines = self.lines[:ex.lineno]