當前位置: 首頁>>代碼示例>>Python>>正文


Python path.open方法代碼示例

本文整理匯總了Python中os.path.open方法的典型用法代碼示例。如果您正苦於以下問題:Python path.open方法的具體用法?Python path.open怎麽用?Python path.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os.path的用法示例。


在下文中一共展示了path.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_package_sync_with_canonical_simple_page

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_package_sync_with_canonical_simple_page(mirror: Mirror) -> None:
    mirror.packages_to_sync = {"Foo": 1}
    package = Package("Foo", 1, mirror)
    await package.sync()

    # Cross-check that simple directory hashing is disabled.
    assert not os.path.exists("web/simple/f/foo/index.html")
    assert (
        open("web/simple/foo/index.html").read()
        == """\
<!DOCTYPE html>
<html>
  <head>
    <title>Links for Foo</title>
  </head>
  <body>
    <h1>Links for Foo</h1>
    {}
  </body>
</html>
<!--SERIAL 654321-->\
""".format(
            EXPECTED_REL_HREFS
        )
    ) 
開發者ID:pypa,項目名稱:bandersnatch,代碼行數:27,代碼來源:test_package.py

示例2: test_package_sync_simple_page_with_files

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_package_sync_simple_page_with_files(mirror: Mirror) -> None:
    mirror.packages_to_sync = {"foo": 1}
    package = Package("foo", 1, mirror)
    await package.sync()
    assert not mirror.errors

    assert (
        open("web/simple/foo/index.html").read()
        == """\
<!DOCTYPE html>
<html>
  <head>
    <title>Links for foo</title>
  </head>
  <body>
    <h1>Links for foo</h1>
    {}
  </body>
</html>
<!--SERIAL 654321-->\
""".format(
            EXPECTED_REL_HREFS
        )
    ) 
開發者ID:pypa,項目名稱:bandersnatch,代碼行數:26,代碼來源:test_package.py

示例3: test_package_sync_does_not_touch_existing_local_file

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_package_sync_does_not_touch_existing_local_file(mirror: Mirror) -> None:
    pkg_file_path_str = "web/packages/any/f/foo/foo.zip"
    pkg_file_path = Path(pkg_file_path_str)
    touch_files((pkg_file_path,))
    with pkg_file_path.open("w") as f:
        f.write("")
    old_stat = pkg_file_path.stat()

    mirror.packages_to_sync = {"foo": 1}
    package = Package("foo", 1, mirror)
    await package.sync()
    assert not mirror.errors

    # Use Pathlib + create a new object to ensure no caching
    # Only compare the relevant stat fields
    assert old_stat.st_mtime == Path(pkg_file_path_str).stat().st_mtime
    assert old_stat.st_ctime == Path(pkg_file_path_str).stat().st_ctime 
開發者ID:pypa,項目名稱:bandersnatch,代碼行數:19,代碼來源:test_package.py

示例4: test_mirror_filter_packages_match

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_mirror_filter_packages_match(tmpdir: Path) -> None:
    """
    Packages that exist in the blacklist should be removed from the list of
    packages to sync.
    """
    test_configuration = """\
[blacklist]
plugins = blacklist_project
packages =
    example1
"""
    Singleton._instances = {}
    with open("test.conf", "w") as testconfig_handle:
        testconfig_handle.write(test_configuration)
    BandersnatchConfig("test.conf")
    for plugin in filter_project_plugins():
        plugin.initialize_plugin()
    m = Mirror(tmpdir, mock.Mock())
    m.packages_to_sync = {"example1": "", "example2": ""}
    m._filter_packages()
    assert "example1" not in m.packages_to_sync.keys() 
開發者ID:pypa,項目名稱:bandersnatch,代碼行數:23,代碼來源:test_mirror.py

示例5: test_mirror_filter_packages_nomatch_package_with_spec

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_mirror_filter_packages_nomatch_package_with_spec(tmpdir: Path) -> None:
    """
    Package lines with a PEP440 spec on them should not be filtered from the
    list of packages.
    """
    test_configuration = """\
[blacklist]
packages =
    example3>2.0.0
"""
    Singleton._instances = {}
    with open("test.conf", "w") as testconfig_handle:
        testconfig_handle.write(test_configuration)
    BandersnatchConfig("test.conf")
    for plugin in filter_project_plugins():
        plugin.initialize_plugin()
    m = Mirror(tmpdir, mock.Mock())
    m.packages_to_sync = {"example1": "", "example3": ""}
    m._filter_packages()
    assert "example3" in m.packages_to_sync.keys() 
開發者ID:pypa,項目名稱:bandersnatch,代碼行數:22,代碼來源:test_mirror.py

示例6: mirror_sync_package_error_early_exit

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def mirror_sync_package_error_early_exit(mirror: Mirror) -> None:
    mirror.master.all_packages = asynctest.CoroutineMock(  # type: ignore
        return_value={"foo": 1}
    )

    with Path("web/simple/index.html").open("wb") as index:
        index.write(b"old index")
    mirror.errors = True
    mirror.stop_on_error = True
    with pytest.raises(SystemExit):
        await mirror.synchronize()

    assert """\
.lock
generation
todo
web{0}packages{0}any{0}f{0}foo{0}foo.zip
web{0}simple{0}foo{0}index.html
web{0}simple{0}index.html""".format(
        sep
    ) == utils.find(
        mirror.homedir, dirs=False
    )
    assert open("web{0}simple{0}index.html".format(sep)).read() == "old index"
    assert open("todo").read() == "1\n" 
開發者ID:pypa,項目名稱:bandersnatch,代碼行數:27,代碼來源:test_mirror.py

示例7: test_find_package_indexes_in_dir_threaded

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_find_package_indexes_in_dir_threaded(mirror: Mirror) -> None:
    directories = (
        "web/simple/peerme",
        "web/simple/click",
        "web/simple/zebra",
        "web/simple/implicit",
        "web/simple/pyaib",
        "web/simple/setuptools",
    )
    with TemporaryDirectory() as td:
        # Create local mirror first so we '_bootstrap'
        mirror_base = Path(td)
        local_mirror = Mirror(mirror_base, mirror.master, stop_on_error=True)
        # Create fake file system objects
        for directory in directories:
            (mirror_base / directory).mkdir(parents=True, exist_ok=True)
        with (mirror_base / "web/simple/index.html").open("w") as index:
            index.write("<html></html>")

        packages = local_mirror.find_package_indexes_in_dir(mirror_base / "web/simple")
        assert "index.html" not in packages  # This should never be in the list
        assert len(packages) == 6  # We expect 6 packages with 6 dirs created
        assert packages[0] == "click"  # Check sorted - click should be first 
開發者ID:pypa,項目名稱:bandersnatch,代碼行數:25,代碼來源:test_mirror.py

示例8: get_requirements

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def get_requirements(self, optional=False):
        if not any(r.is_optional() == optional for r in self.package.all_requires):
            return
        with self.requirements_path.open(encoding='utf-8') as f:
            document = f.read()
        template = Environment().from_string(document)
        document = template.render(
            package=self.package,
            optional=optional,
            format_vcs=self._format_vcs,
        )
        # rm junk
        document = document.replace('    ', '')
        # sort lines
        lines = sorted(line for line in document.split('\n') if line)
        document = '\n'.join(lines) + '\n'
        return document 
開發者ID:orsinium-archive,項目名稱:poetry-setup,代碼行數:19,代碼來源:core.py

示例9: get_setup

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def get_setup(self):
        # render template
        with self.setup_path.open(encoding='utf-8') as f:
            document = f.read()
        template = Environment().from_string(document)
        document = template.render(
            package=self.package,
            format_vcs=self._format_vcs,
        )

        # format by yapf
        style = CreateGoogleStyle()
        document, _changed = FormatCode(document, style_config=style)
        # remove empty strings
        while '\n\n' in document:
            document = document.replace('\n\n', '\n')
        # format by autopep8
        document = fix_code(document)
        return document 
開發者ID:orsinium-archive,項目名稱:poetry-setup,代碼行數:21,代碼來源:core.py

示例10: sync

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def sync(self):
        document = self.get_requirements(optional=False)
        if document:
            path = self.path / self.requirements_name
            with path.open('w', encoding='utf-8') as f:
                f.write(document)

        document = self.get_requirements(optional=True)
        if document:
            path = self.path / self.constraints_name
            with path.open('w', encoding='utf-8') as f:
                f.write(document)

        document = self.get_setup()
        path = self.path / self.setup_name
        with path.open('w', encoding='utf-8') as f:
            f.write(document) 
開發者ID:orsinium-archive,項目名稱:poetry-setup,代碼行數:19,代碼來源:core.py

示例11: test_recarray_fromfile

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_recarray_fromfile(self):
        data_dir = path.join(path.dirname(__file__), 'data')
        filename = path.join(data_dir, 'recarray_from_file.fits')
        fd = open(filename, 'rb')
        fd.seek(2880 * 2)
        r1 = np.rec.fromfile(fd, formats='f8,i4,a5', shape=3, byteorder='big')
        fd.seek(2880 * 2)
        r2 = np.rec.array(fd, formats='f8,i4,a5', shape=3, byteorder='big')
        fd.close()
        assert_equal(r1, r2) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_records.py

示例12: test_tofile_fromfile

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_tofile_fromfile(self):
        with temppath(suffix='.bin') as path:
            path = Path(path)
            np.random.seed(123)
            a = np.random.rand(10).astype('f8,i4,a5')
            a[5] = (0.5,10,'abcde')
            with path.open("wb") as fd:
                a.tofile(fd)
            x = np.core.records.fromfile(path,
                                         formats='f8,i4,a5',
                                         shape=10)
            assert_array_equal(x, a) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_records.py

示例13: sandwich

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def sandwich(resources):
    # Has XMP, docinfo, <?adobe-xap-filters esc="CRLF"?>, shorthand attribute XMP
    return Pdf.open(resources / 'sandwich.pdf') 
開發者ID:pikepdf,項目名稱:pikepdf,代碼行數:5,代碼來源:test_io.py

示例14: test_overwrite_input

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_overwrite_input(resources, outdir):
    copy(resources / 'sandwich.pdf', outdir / 'sandwich.pdf')
    p = Pdf.open(outdir / 'sandwich.pdf')
    with pytest.raises(ValueError, match=r'overwrite input file'):
        p.save(outdir / 'sandwich.pdf') 
開發者ID:pikepdf,項目名稱:pikepdf,代碼行數:7,代碼來源:test_io.py

示例15: test_fail_only_overwrite_input_check

# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import open [as 別名]
def test_fail_only_overwrite_input_check(monkeypatch, resources, outdir):
    copy(resources / 'sandwich.pdf', outdir / 'sandwich.pdf')
    p = Pdf.open(outdir / 'sandwich.pdf')

    def mockraise(*args):
        raise OSError("samefile mocked")

    monkeypatch.setattr(os.path, 'samefile', mockraise)
    with pytest.raises(OSError, match=r'samefile mocked'):
        p.save(outdir / 'wouldwork.pdf') 
開發者ID:pikepdf,項目名稱:pikepdf,代碼行數:12,代碼來源:test_io.py


注:本文中的os.path.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。