]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-112855: Slightly improve tests for `pathlib.PurePath` pickling (#113243)
authorBarney Gale <barney.gale@gmail.com>
Fri, 22 Dec 2023 17:49:09 +0000 (17:49 +0000)
committerGitHub <noreply@github.com>
Fri, 22 Dec 2023 17:49:09 +0000 (17:49 +0000)
Add a few more simple test cases, like non-anchored paths. Remove misplaced
and indirect test that pickling doesn't change the `stat()` value.

Lib/test/test_pathlib/test_pathlib.py
Lib/test/test_pathlib/test_pathlib_abc.py

index d55ccd9e255fcc1e3b9cb7d7da10a5ba4be47d96..a448f6a1adefce1bc27e16963a922c9b19a1ca8c 100644 (file)
@@ -60,14 +60,16 @@ class PurePathTest(test_pathlib_abc.DummyPurePathTest):
 
     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'):
index 6748def91a1e6e8abec0b6c54163877c1a74d244..42575a5e640d65e568069c579ca3aff61bc868db 100644 (file)
@@ -3,7 +3,6 @@ import io
 import os
 import errno
 import pathlib
-import pickle
 import posixpath
 import stat
 import unittest
@@ -1644,13 +1643,6 @@ class DummyPathTest(DummyPurePathTest):
         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')