8000 bpo-24132: Add direct subclassing of PurePath/Path in pathlib by kfollstad · Pull Request #26906 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-24132: Add direct subclassing of PurePath/Path in pathlib #26906

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

Closed
wants to merge 7 commits into from
Prev Previous commit
Next Next commit
bpo-24132: Add tests for comparing subclasses of PurePath in pathlib
Add tests mirroring existing comparison tests for PurePosixPath
and PureWindowsPath but extending them to direct subclasses of PurePath.
  • Loading branch information
kfollstad committed Jun 24, 2021
commit 610f41ed81e96b525b6ac230117527255e79b73d
29 changes: 26 additions & 3 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,10 @@ def _get_class_to_generate(self):
is_posix = os.name == 'posix'
return pathlib.PurePosixPath if is_posix else pathlib.PureWindowsPath

def _get_anti_system_flavour_class(self):
is_posix = os.name == 'posix'
return pathlib.PureWindowsPath if is_posix else pathlib.PurePosixPath

def test_instance_class_properties(self):
p = self.cls('placeholder')
correct_cls = self._get_class_to_generate()
Expand Down Expand Up @@ -1369,9 +1373,15 @@ def test_different_flavours_unequal(self):
q = pathlib.PureWindowsPath('a')
self.assertNotEqual(p, q)

def test_different_flavours_unordered(self):
p = pathlib.PurePosixPath('a')
q = pathlib.PureWindowsPath('a')
def test_subclass_different_flavours_unequal(self):
class Derived(pathlib.PurePath):
pass
p = Derived('a')
PureAntiFlavourPath = self._get_anti_system_flavour_class()
q = PureAntiFlavourPath('a')
self.assertNotEqual(p, q)

def _test_different_flavours_unordered(self, p, q):
with self.assertRaises(TypeError):
p < q
with self.assertRaises(TypeError):
Expand All @@ -1381,6 +1391,19 @@ def test_different_flavours_unordered(self):
with self.assertRaises(TypeError):
p >= q

def test_different_flavours_unordered(self):
p = pathlib.PurePosixPath('a')
q = pathlib.PureWindowsPath('a')
self._test_different_flavours_unordered(p, q)

def test_subclass_different_flavours_unordered(self):
class Derived(pathlib.PurePath):
pass
p = Derived('a')
PureAntiFlavourPath = self._get_anti_system_flavour_class()
q = PureAntiFlavourPath('a')
self._test_different_flavours_unordered(p, q)


#
# Tests for the concrete classes.
Expand Down
0