Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/214.feature.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``Path.is_mount()`` as an alias for ``Path.ismount()`` for pathlib compatibility.
2 changes: 2 additions & 0 deletions path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,8 @@ def ismount(self) -> bool:
"""
return self.module.ismount(self)

is_mount = ismount

def samefile(self, other: str) -> bool:
""".. seealso:: :func:`os.path.samefile`"""
return self.module.samefile(self, other)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ def test_home(self):
assert isinstance(home, Path)
assert home == os.path.expanduser('~')

@pytest.mark.parametrize('method', ['ismount', 'is_mount'])
@pytest.mark.parametrize('kind', ['directory', 'file', 'missing', 'root'])
def test_is_mount(self, tmp_path, method, kind):
(tmp_path / 'directory').mkdir()
(tmp_path / 'file').touch()
target = Path(tmp_path.anchor) if kind == 'root' else Path(tmp_path / kind)
assert getattr(target, method)() is (kind == 'root')

@pytest.mark.parametrize('method', ['ismount', 'is_mount'])
@pytest.mark.parametrize('expected', [False, True])
def test_is_mount_module(self, monkeypatch, method, expected):
module = types.ModuleType('mount_module')
target = Path.using_module(module)('some-path')

def ismount(value):
assert value is target
return expected

monkeypatch.setattr(module, 'ismount', ismount, raising=False)
assert getattr(target, method)() is expected

def test_explicit_module(self):
"""
The user may specify an explicit path module to use.
Expand Down