summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-05-13 08:50:15 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-05-13 08:50:15 (GMT)
commit43e3d9409de92808b2ef5974b6a9f13eda57033f (patch)
tree1f8d1a1d379fdd3a0c76b5eae57a215df59e2854 /Lib/test/test_pathlib.py
parent38acd4c028f72a80079c27d68c8da2efd059a38d (diff)
downloadcpython-43e3d9409de92808b2ef5974b6a9f13eda57033f.zip
cpython-43e3d9409de92808b2ef5974b6a9f13eda57033f.tar.gz
cpython-43e3d9409de92808b2ef5974b6a9f13eda57033f.tar.bz2
Issue #19775: Add a samefile() method to pathlib Path objects.
Initial patch by Vajrasky Kok.
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rw-r--r--Lib/test/test_pathlib.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 6378d8c..fd9cf23 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1251,6 +1251,26 @@ class _BasePathTest(object):
p = self.cls.cwd()
self._test_cwd(p)
+ def test_samefile(self):
+ fileA_path = os.path.join(BASE, 'fileA')
+ fileB_path = os.path.join(BASE, 'dirB', 'fileB')
+ p = self.cls(fileA_path)
+ pp = self.cls(fileA_path)
+ q = self.cls(fileB_path)
+ self.assertTrue(p.samefile(fileA_path))
+ self.assertTrue(p.samefile(pp))
+ self.assertFalse(p.samefile(fileB_path))
+ self.assertFalse(p.samefile(q))
+ # Test the non-existent file case
+ non_existent = os.path.join(BASE, 'foo')
+ r = self.cls(non_existent)
+ self.assertRaises(FileNotFoundError, p.samefile, r)
+ self.assertRaises(FileNotFoundError, p.samefile, non_existent)
+ self.assertRaises(FileNotFoundError, r.samefile, p)
+ self.assertRaises(FileNotFoundError, r.samefile, non_existent)
+ self.assertRaises(FileNotFoundError, r.samefile, r)
+ self.assertRaises(FileNotFoundError, r.samefile, non_existent)
+
def test_empty_path(self):
# The empty path points to '.'
p = self.cls('')