Skip to content

Commit

Permalink
pythonGH-112855: Slightly improve tests for pathlib.PurePath pickli…
Browse files Browse the repository at this point in the history
…ng (python#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.
  • Loading branch information
barneygale authored Dec 22, 2023
1 parent 4a3d241 commit ff5e131
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
18 changes: 10 additions & 8 deletions Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def test_div_nested(self):

def test_pickling_common(self):
P = self.cls
p = P('/a/b')
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
dumped = pickle.dumps(p, proto)
pp = pickle.loads(dumped)
self.assertIs(pp.__class__, p.__class__)
self.assertEqual(pp, p)
self.assertEqual(hash(pp), hash(p))
self.assertEqual(str(pp), str(p))
for pathstr in ('a', 'a/', 'a/b', 'a/b/c', '/', '/a/b', '/a/b/c', 'a/b/c/'):
with self.subTest(pathstr=pathstr):
p = P(pathstr)
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
dumped = pickle.dumps(p, proto)
pp = pickle.loads(dumped)
self.assertIs(pp.__class__, p.__class__)
self.assertEqual(pp, p)
self.assertEqual(hash(pp), hash(p))
self.assertEqual(str(pp), str(p))

def test_repr_common(self):
for pathstr in ('a', 'a/b', 'a/b/c', '/', '/a/b', '/a/b/c'):
Expand Down
8 changes: 0 additions & 8 deletions Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import errno
import pathlib
import pickle
import posixpath
import stat
import unittest
Expand Down Expand Up @@ -1644,13 +1643,6 @@ def test_is_char_device_false(self):
self.assertIs((P / 'fileA\udfff').is_char_device(), False)
self.assertIs((P / 'fileA\x00').is_char_device(), False)

def test_pickling_common(self):
p = self.cls(self.base, 'fileA')
for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
dumped = pickle.dumps(p, proto)
pp = pickle.loads(dumped)
self.assertEqual(pp.stat(), p.stat())

def test_parts_interning(self):
P = self.cls
p = P('/usr/bin/foo')
Expand Down

0 comments on commit ff5e131

Please sign in to comment.