mirror of
https://github.com/python/cpython.git
synced 2025-08-15 22:30:42 +00:00
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.
This commit is contained in:
parent
93fc3d34f9
commit
5a484714c3
3 changed files with 55 additions and 23 deletions
49
Lib/test/test_pathlib/test_join_posix.py
Normal file
49
Lib/test/test_pathlib/test_join_posix.py
Normal file
|
@ -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()
|
Loading…
Add table
Add a link
Reference in a new issue