Skip to content

Commit

Permalink
Add .home classmethod.
Browse files Browse the repository at this point in the history
Ref #214
  • Loading branch information
jaraco committed Jul 27, 2024
1 parent 28f8f74 commit 66992c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions newsfragments/214.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add .home classmethod.
4 changes: 4 additions & 0 deletions path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def getcwd(cls):
)
return cls.cwd()

@classmethod
def home(cls) -> Path:
return cls(os.path.expanduser('~'))

#
# --- Operations on Path strings.

Expand Down
5 changes: 5 additions & 0 deletions test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def test_cwd(self):
assert isinstance(cwd, Path)
assert cwd == os.getcwd()

def test_home(self):
home = Path.home()
assert isinstance(home, Path)
assert home == os.path.expanduser('~')

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

0 comments on commit 66992c3

Please sign in to comment.