Add a std::filesystem::path <-> os.PathLike caster. (#2730)

This commit is contained in:
Antony Lee
2021-07-02 16:00:50 +02:00
committed by GitHub
parent f067deb563
commit 5bcaaa0423
5 changed files with 149 additions and 0 deletions

View File

@@ -162,6 +162,25 @@ def test_exp_optional():
assert holder.member_initialized()
@pytest.mark.skipif(not hasattr(m, "has_filesystem"), reason="no <filesystem>")
def test_fs_path():
from pathlib import Path
class PseudoStrPath:
def __fspath__(self):
return "foo/bar"
class PseudoBytesPath:
def __fspath__(self):
return b"foo/bar"
assert m.parent_path(Path("foo/bar")) == Path("foo")
assert m.parent_path("foo/bar") == Path("foo")
assert m.parent_path(b"foo/bar") == Path("foo")
assert m.parent_path(PseudoStrPath()) == Path("foo")
assert m.parent_path(PseudoBytesPath()) == Path("foo")
@pytest.mark.skipif(not hasattr(m, "load_variant"), reason="no <variant>")
def test_variant(doc):
assert m.load_variant(1) == "int"