From cca33e8207c244ceb6d7c68edf57587810bb1d81 Mon Sep 17 00:00:00 2001 From: barneygale Date: Mon, 18 Dec 2023 05:35:16 +0000 Subject: [PATCH 1/2] GH-112855: Slightly improve tests for `pathlib.PurePath` pickling 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 | 18 ++++++++++-------- Lib/test/test_pathlib/test_pathlib_abc.py | 7 ------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 00cfdd37e568a6..844ebdcd71890c 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -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_fspath_common(self): P = self.cls diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py index a272973d9c1d61..296c3765b00316 100644 --- a/Lib/test/test_pathlib/test_pathlib_abc.py +++ b/Lib/test/test_pathlib/test_pathlib_abc.py @@ -1655,13 +1655,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') From 5f7fe636ddee3731f228de22a60e1cbb091cbd83 Mon Sep 17 00:00:00 2001 From: barneygale Date: Fri, 22 Dec 2023 17:10:06 +0000 Subject: [PATCH 2/2] Delete unused import --- Lib/test/test_pathlib/test_pathlib_abc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py index 296c3765b00316..fe2340ff7ebcf7 100644 --- a/Lib/test/test_pathlib/test_pathlib_abc.py +++ b/Lib/test/test_pathlib/test_pathlib_abc.py @@ -3,7 +3,6 @@ import os import errno import pathlib -import pickle import posixpath import stat import unittest