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


Python py.path方法代码示例

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


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

示例1: make_repo_auth

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def make_repo_auth(repo, userdata):
    """ write config to repo

        user information in userdata is used for auth
        userdata has user names as keys, and a tuple (password, readwrite) as
        values, where 'readwrite' is either 'r' or 'rw'
    """
    confdir = py.path.local(repo).join('conf')
    confdir.join('svnserve.conf').write('''\
[general]
anon-access = none
password-db = passwd
authz-db = authz
realm = TestRepo
''')
    authzdata = '[/]\n'
    passwddata = '[users]\n'
    for user in userdata:
        authzdata += '%s = %s\n' % (user, userdata[user][1])
        passwddata += '%s = %s\n' % (user, userdata[user][0])
    confdir.join('authz').write(authzdata)
    confdir.join('passwd').write(passwddata) 
开发者ID:pytest-dev,项目名称:py,代码行数:24,代码来源:test_svnauth.py

示例2: __init__

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def __init__(self, request):
        if not svnbin:
            py.test.skip("svn binary required")
        if not request.config.option.runslowtests:
            py.test.skip('use --runslowtests to run these tests')

        tmpdir = request.getfuncargvalue("tmpdir")
        repodir = tmpdir.join("repo")
        py.process.cmdexec('svnadmin create %s' % repodir)
        if sys.platform == 'win32':
            repodir = '/' + str(repodir).replace('\\', '/')
        self.repo = py.path.svnurl("file://%s" % repodir)
        if sys.platform == 'win32':
            # remove trailing slash...
            repodir = repodir[1:]
        self.repopath = py.path.local(repodir)
        self.temppath = tmpdir.mkdir("temppath")
        self.auth = SvnAuth('johnny', 'foo', cache_auth=False,
                                    interactive=False)
        make_repo_auth(self.repopath, {'johnny': ('foo', 'rw')})
        self.port, self.pid = serve_bg(self.repopath.dirpath())
        # XXX caching is too global
        py.path.svnurl._lsnorevcache._dict.clear()
        request.addfinalizer(lambda: py.process.kill(self.pid)) 
开发者ID:pytest-dev,项目名称:py,代码行数:26,代码来源:test_svnauth.py

示例3: test_update

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_update(self, setup):
        wc1 = py.path.svnwc(setup.temppath.ensure('wc1', dir=True),
                            auth=setup.auth)
        wc2 = py.path.svnwc(setup.temppath.ensure('wc2', dir=True),
                            auth=setup.auth)
        wc1.checkout(
            'svn://localhost:%s/%s' % (setup.port, setup.repopath.basename))
        wc2.checkout(
            'svn://localhost:%s/%s' % (setup.port, setup.repopath.basename))
        wc1.ensure('foo', dir=True)
        wc1.commit('added foo dir')
        wc2.update()
        assert wc2.join('foo').check()

        auth = SvnAuth('unknown', 'unknown', interactive=False)
        wc2.auth = auth
        py.test.raises(Exception, 'wc2.update()') 
开发者ID:pytest-dev,项目名称:py,代码行数:19,代码来源:test_svnauth.py

示例4: test_lock_unlock_status

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_lock_unlock_status(self, setup):
        port = setup.port
        wc = py.path.svnwc(setup.temppath, auth=setup.auth)
        wc.checkout(
            'svn://localhost:%s/%s' % (port, setup.repopath.basename,))
        wc.ensure('foo', file=True)
        wc.commit('added foo file')
        foo = wc.join('foo')
        foo.lock()
        status = foo.status()
        assert status.locked
        foo.unlock()
        status = foo.status()
        assert not status.locked

        auth = SvnAuth('unknown', 'unknown', interactive=False)
        foo.auth = auth
        py.test.raises(Exception, 'foo.lock()')
        py.test.raises(Exception, 'foo.unlock()') 
开发者ID:pytest-dev,项目名称:py,代码行数:21,代码来源:test_svnauth.py

示例5: test_diff

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_diff(self, setup):
        port = setup.port
        wc = py.path.svnwc(setup.temppath, auth=setup.auth)
        wc.checkout(
            'svn://localhost:%s/%s' % (port, setup.repopath.basename,))
        wc.ensure('foo', file=True)
        wc.commit('added foo file')
        wc.update()
        rev = int(wc.status().rev)
        foo = wc.join('foo')
        foo.write('bar')
        diff = foo.diff()
        assert '\n+bar\n' in diff
        foo.commit('added some content')
        diff = foo.diff()
        assert not diff
        diff = foo.diff(rev=rev)
        assert '\n+bar\n' in diff

        auth = SvnAuth('unknown', 'unknown', interactive=False)
        foo.auth = auth
        py.test.raises(Exception, 'foo.diff(rev=rev)') 
开发者ID:pytest-dev,项目名称:py,代码行数:24,代码来源:test_svnauth.py

示例6: test_copy

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_copy(self, setup):
        port = setup.port
        u = py.path.svnurl(
            'svn://localhost:%s/%s' % (port, setup.repopath.basename),
            auth=setup.auth)
        foo = u.mkdir('foo')
        assert foo.check()
        bar = u.join('bar')
        foo.copy(bar)
        assert bar.check()
        assert bar.auth is setup.auth

        auth = SvnAuth('foo', 'bar', interactive=False)
        u = py.path.svnurl(
            'svn://localhost:%s/%s' % (port, setup.repopath.basename),
            auth=auth)
        foo = u.join('foo')
        bar = u.join('bar')
        py.test.raises(Exception, 'foo.copy(bar)') 
开发者ID:pytest-dev,项目名称:py,代码行数:21,代码来源:test_svnauth.py

示例7: test_eq_with_none_and_custom_fspath

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_eq_with_none_and_custom_fspath(self, monkeypatch, path1):
        import os
        import shutil
        import tempfile

        d = tempfile.mkdtemp()
        monkeypatch.chdir(d)
        shutil.rmtree(d)

        monkeypatch.delitem(sys.modules, 'pathlib', raising=False)
        monkeypatch.setattr(sys, 'path', [''] + sys.path)

        with pytest.raises(FileNotFoundError):
            import pathlib  # noqa: F401

        assert path1 != None  # noqa: E711 
开发者ID:pytest-dev,项目名称:py,代码行数:18,代码来源:test_local.py

示例8: test_setmtime

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_setmtime(self):
        import tempfile
        import time
        try:
            fd, name = tempfile.mkstemp()
            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:
            os.remove(name) 
开发者ID:pytest-dev,项目名称:py,代码行数:21,代码来源:test_local.py

示例9: test_make_repo

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_make_repo(path1, tmpdir):
    repo = tmpdir.join("repo")
    py.process.cmdexec('svnadmin create %s' % repo)
    if sys.platform == 'win32':
        repo = '/' + str(repo).replace('\\', '/')
    repo = py.path.svnurl("file://%s" % repo)
    wc = py.path.svnwc(tmpdir.join("wc"))
    wc.checkout(repo)
    assert wc.rev == 0
    assert len(wc.listdir()) == 0
    p = wc.join("a_file")
    p.write("test file")
    p.add()
    rev = wc.commit("some test")
    assert p.info().rev == 1
    assert rev == 1
    rev = wc.commit()
    assert rev is None 
开发者ID:pytest-dev,项目名称:py,代码行数:20,代码来源:test_svnwc.py

示例10: test_exists_svn_root

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_exists_svn_root(self, path1):
        assert path1.check()

    #def test_not_exists_rev(self, path1):
    #    url = path1.__class__(path1url, rev=500)
    #    assert url.check(exists=0)

    #def test_nonexisting_listdir_rev(self, path1):
    #    url = path1.__class__(path1url, rev=500)
    #    raises(py.error.ENOENT, url.listdir)

    #def test_newrev(self, path1):
    #    url = path1.new(rev=None)
    #    assert url.rev == None
    #    assert url.strpath == path1.strpath
    #    url = path1.new(rev=10)
    #    assert url.rev == 10

    #def test_info_rev(self, path1):
    #    url = path1.__class__(path1url, rev=1155)
    #    url = url.join("samplefile")
    #    res = url.info()
    #    assert res.size > len("samplefile") and res.created_rev == 1155

    # the following tests are easier if we have a path class 
开发者ID:pytest-dev,项目名称:py,代码行数:27,代码来源:test_svnwc.py

示例11: test_broken_py_path_local_join_workaround_on_Windows

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_broken_py_path_local_join_workaround_on_Windows(self, tmpdir, initproj, monkeypatch):
        # construct an absolute folder path for our src_root folder without the
        # Windows drive indicator
        src_root = tmpdir.join("spam")
        src_root = _path_parts(src_root)
        src_root[0] = ""
        src_root = "/".join(src_root)

        # make sure tmpdir drive is the current one so the constructed src_root
        # folder path gets interpreted correctly on Windows
        monkeypatch.chdir(tmpdir)

        # will throw an assertion error if the bug is not worked around
        initproj("spam-666", src_root=src_root)

        init_file = tmpdir.join("spam", "spam", "__init__.py")
        expected = b'""" module spam """' + linesep_bytes() + b"__version__ = '666'"
        assert init_file.read_binary() == expected 
开发者ID:tox-dev,项目名称:tox,代码行数:20,代码来源:test_pytest_plugins.py

示例12: getsource

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def getsource(self, astcache=None):
        """ return failing source code. """
        # we use the passed in astcache to not reparse asttrees
        # within exception info printing
        from _pytest._code.source import getstatementrange_ast

        source = self.frame.code.fullsource
        if source is None:
            return None
        key = astnode = None
        if astcache is not None:
            key = self.frame.code.path
            if key is not None:
                astnode = astcache.get(key, None)
        start = self.getfirstlinesource()
        try:
            astnode, _, end = getstatementrange_ast(
                self.lineno, source, astnode=astnode
            )
        except SyntaxError:
            end = self.lineno + 1
        else:
            if key is not None:
                astcache[key] = astnode
        return source[start:end] 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:27,代码来源:code.py

示例13: filter_traceback

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
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 a non-existing file, in which case it will
    # also return a str object. see #1133
    p = py.path.local(entry.path)
    return (
        not p.relto(_PLUGGY_DIR) and not p.relto(_PYTEST_DIR) and not p.relto(_PY_DIR)
    ) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:20,代码来源:code.py

示例14: cut

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def cut(self, path=None, lineno=None, firstlineno=None, excludepath=None):
        """ return a Traceback instance wrapping part of this Traceback

            by provding any combination of path, lineno and firstlineno, the
            first frame to start the to-be-returned traceback is determined

            this allows cutting the first part of a Traceback instance e.g.
            for formatting reasons (removing some uninteresting bits that deal
            with handling of the exception/traceback)
        """
        for x in self:
            code = x.frame.code
            codepath = code.path
            if (
                (path is None or codepath == path)
                and (
                    excludepath is None
                    or not hasattr(codepath, "relto")
                    or not codepath.relto(excludepath)
                )
                and (lineno is None or x.lineno == lineno)
                and (firstlineno is None or x.frame.code.firstlineno == firstlineno)
            ):
                return Traceback(x._rawentry, self._excinfo)
        return self 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:27,代码来源:code.py

示例15: test_reencode_glyphs

# 需要导入模块: import py [as 别名]
# 或者: from py import path [as 别名]
def test_reencode_glyphs(tmpdir):
    data_dir = py.path.local(DATA)

    designspace_path = data_dir / "TestReencode.designspace"
    designspace_path.copy(tmpdir)

    ufo_path = data_dir / "TestReencode-Regular.ufo"
    ufo_path.copy(tmpdir.ensure_dir("TestReencode-Regular.ufo"))

    instance_dir = tmpdir.ensure_dir("instance_ufo")
    ufo_path.copy(instance_dir.ensure_dir("TestReencode-Regular.ufo"))
    ufo_path.copy(instance_dir.ensure_dir("TestReencodeUI-Regular.ufo"))

    ufos = apply_instance_data(str(tmpdir / "TestReencode.designspace"))

    assert len(ufos) == 2
    assert ufos[0]["A"].unicode == 0x0041
    assert ufos[0]["A.alt"].unicode is None
    assert ufos[0]["C"].unicode == 0x0043
    # Reencode Glyphs: A.alt=0041, C=
    assert ufos[1]["A"].unicode is None
    assert ufos[1]["A.alt"].unicode == 0x0041
    assert ufos[1]["C"].unicode is None 
开发者ID:googlefonts,项目名称:glyphsLib,代码行数:25,代码来源:instances_test.py


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