Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-130614: pathlib ABCs: revise test suite for Posix path joining #131017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 6 Lib/test/test_pathlib/support/lexical_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os.path
import pathlib.types
import posixpath


class LexicalPath(pathlib.types._JoinablePath):
Expand Down Expand Up @@ -31,3 +32,8 @@ def __repr__(self):

def with_segments(self, *pathsegments):
return type(self)(*pathsegments)


class LexicalPosixPath(LexicalPath):
__slots__ = ()
parser = posixpath
49 changes: 49 additions & 0 deletions 49 Lib/test/test_pathlib/test_join_posix.py
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 0 additions & 23 deletions 23 Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ def test_str_subclass_windows(self):
self._check_str_subclass('\\\\some\\share\\a')
self._check_str_subclass('\\\\some\\share\\a\\b.txt')

@needs_posix
def test_join_posix(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'))

@needs_windows
def test_join_windows(self):
P = self.cls
Expand Down Expand Up @@ -157,18 +146,6 @@ def test_join_windows(self):
pp = P('//./BootPartition').joinpath('Windows')
self.assertEqual(pp, P('//./BootPartition/Windows'))

@needs_posix
def test_div_posix(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'))

@needs_windows
def test_div_windows(self):
# Basically the same as joinpath().
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.