summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib/test_join_posix.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2025-03-10 17:59:10 (GMT)
committerGitHub <noreply@github.com>2025-03-10 17:59:10 (GMT)
commit5a484714c3497dd5c67a1469c0cc246bf1452892 (patch)
tree3b515770a5f1d9c32fabcd246cc98993c46d6130 /Lib/test/test_pathlib/test_join_posix.py
parent93fc3d34f9285d337c1e19e84764b02629eaab68 (diff)
downloadcpython-5a484714c3497dd5c67a1469c0cc246bf1452892.zip
cpython-5a484714c3497dd5c67a1469c0cc246bf1452892.tar.gz
cpython-5a484714c3497dd5c67a1469c0cc246bf1452892.tar.bz2
GH-130614: pathlib ABCs: revise test suite for Posix path joining (#131017)
Test Posix-flavoured `pathlib.types._JoinablePath` in a dedicated test module. These tests cover `LexicalPosixPath`, `PurePosixPath` and `PosixPath`, where `LexicalPosixPath` is a simple implementation of `_JoinablePath` for use in tests.
Diffstat (limited to 'Lib/test/test_pathlib/test_join_posix.py')
-rw-r--r--Lib/test/test_pathlib/test_join_posix.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib/test_join_posix.py b/Lib/test/test_pathlib/test_join_posix.py
new file mode 100644
index 0000000..7f657c2
--- /dev/null
+++ b/Lib/test/test_pathlib/test_join_posix.py
@@ -0,0 +1,49 @@
+"""
+Tests for Posix-flavoured pathlib.types._JoinablePath
+"""
+
+import os
+import unittest
+
+from pathlib import PurePosixPath, PosixPath
+from test.test_pathlib.support.lexical_path import LexicalPosixPath
+
+
+class JoinTestBase:
+ def test_join(self):
+ P = self.cls
+ p = P('//a')
+ pp = p.joinpath('b')
+ self.assertEqual(pp, P('//a/b'))
+ pp = P('/a').joinpath('//c')
+ self.assertEqual(pp, P('//c'))
+ pp = P('//a').joinpath('/c')
+ self.assertEqual(pp, P('/c'))
+
+ def test_div(self):
+ # Basically the same as joinpath().
+ P = self.cls
+ p = P('//a')
+ pp = p / 'b'
+ self.assertEqual(pp, P('//a/b'))
+ pp = P('/a') / '//c'
+ self.assertEqual(pp, P('//c'))
+ pp = P('//a') / '/c'
+ self.assertEqual(pp, P('/c'))
+
+
+class LexicalPosixPathJoinTest(JoinTestBase, unittest.TestCase):
+ cls = LexicalPosixPath
+
+
+class PurePosixPathJoinTest(JoinTestBase, unittest.TestCase):
+ cls = PurePosixPath
+
+
+if os.name != 'nt':
+ class PosixPathJoinTest(JoinTestBase, unittest.TestCase):
+ cls = PosixPath
+
+
+if __name__ == "__main__":
+ unittest.main()