Skip to content

Commit ff5e131

Browse files
authored
GH-112855: Slightly improve tests for pathlib.PurePath pickling (#113243)
Add a few more simple test cases, like non-anchored paths. Remove misplaced and indirect test that pickling doesn't change the `stat()` value.
1 parent 4a3d241 commit ff5e131

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ def test_div_nested(self):
6060

6161
def test_pickling_common(self):
6262
P = self.cls
63-
p = P('/a/b')
64-
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
65-
dumped = pickle.dumps(p, proto)
66-
pp = pickle.loads(dumped)
67-
self.assertIs(pp.__class__, p.__class__)
68-
self.assertEqual(pp, p)
69-
self.assertEqual(hash(pp), hash(p))
70-
self.assertEqual(str(pp), str(p))
63+
for pathstr in ('a', 'a/', 'a/b', 'a/b/c', '/', '/a/b', '/a/b/c', 'a/b/c/'):
64+
with self.subTest(pathstr=pathstr):
65+
p = P(pathstr)
66+
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
67+
dumped = pickle.dumps(p, proto)
68+
pp = pickle.loads(dumped)
69+
self.assertIs(pp.__class__, p.__class__)
70+
self.assertEqual(pp, p)
71+
self.assertEqual(hash(pp), hash(p))
72+
self.assertEqual(str(pp), str(p))
7173

7274
def test_repr_common(self):
7375
for pathstr in ('a', 'a/b', 'a/b/c', '/', '/a/b', '/a/b/c'):

Lib/test/test_pathlib/test_pathlib_abc.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import errno
55
import pathlib
6-
import pickle
76
import posixpath
87
import stat
98
import unittest
@@ -1644,13 +1643,6 @@ def test_is_char_device_false(self):
16441643
self.assertIs((P / 'fileA\udfff').is_char_device(), False)
16451644
self.assertIs((P / 'fileA\x00').is_char_device(), False)
16461645

1647-
def test_pickling_common(self):
1648-
p = self.cls(self.base, 'fileA')
1649-
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
1650-
dumped = pickle.dumps(p, proto)
1651-
pp = pickle.loads(dumped)
1652-
self.assertEqual(pp.stat(), p.stat())
1653-
16541646
def test_parts_interning(self):
16551647
P = self.cls
16561648
p = P('/usr/bin/foo')

0 commit comments

Comments
 (0)