From ee81ff2c31dadd032fb61e5b2ce69249367615a9 Mon Sep 17 00:00:00 2001 From: AkshayRKapur0205 <98418846+AkshayRKapur0205@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:42:57 -0700 Subject: [PATCH] Add pathlib-compatible Path.is_mount Refs #214 -- is_mount subtask only. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- newsfragments/214.feature.1.rst | 1 + path/__init__.py | 2 ++ tests/test_path.py | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 newsfragments/214.feature.1.rst diff --git a/newsfragments/214.feature.1.rst b/newsfragments/214.feature.1.rst new file mode 100644 index 0000000..bffda8c --- /dev/null +++ b/newsfragments/214.feature.1.rst @@ -0,0 +1 @@ +Added ``Path.is_mount()`` as an alias for ``Path.ismount()`` for pathlib compatibility. diff --git a/path/__init__.py b/path/__init__.py index 33dd979..2979a2f 100644 --- a/path/__init__.py +++ b/path/__init__.py @@ -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) diff --git a/tests/test_path.py b/tests/test_path.py index b424bb6..6f7c3d4 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -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.