diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pathlib.py | 7 | ||||
-rw-r--r-- | Lib/test/test_pathlib.py | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 6244932..dd2ccba 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -1008,6 +1008,13 @@ class Path(PurePath): """ return cls(os.getcwd()) + @classmethod + def home(cls): + """Return a new path pointing to the user's home directory (as + returned by os.path.expanduser('~')). + """ + return cls(cls()._flavour.gethomedir(None)) + def samefile(self, other_path): """Return whether `other_file` is the same or not as this file. (as returned by os.path.samefile(file, other_file)). diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 2e97a5e..f4ee519 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1261,6 +1261,17 @@ class _BasePathTest(object): p = self.cls.cwd() self._test_cwd(p) + def _test_home(self, p): + q = self.cls(os.path.expanduser('~')) + self.assertEqual(p, q) + self.assertEqual(str(p), str(q)) + self.assertIs(type(p), type(q)) + self.assertTrue(p.is_absolute()) + + def test_home(self): + p = self.cls.home() + self._test_home(p) + def test_samefile(self): fileA_path = os.path.join(BASE, 'fileA') fileB_path = os.path.join(BASE, 'dirB', 'fileB') |