|
4 | 4 | import pathlib
|
5 | 5 | import unittest
|
6 | 6 | import string
|
7 |
| -import functools |
| 7 | +import pickle |
| 8 | +import itertools |
| 9 | + |
| 10 | +from ._test_params import parameterize, Invoked |
| 11 | +from ._functools import compose |
| 12 | + |
8 | 13 |
|
9 | 14 | from test.support.os_helper import temp_dir
|
10 | 15 |
|
@@ -76,31 +81,19 @@ def build_alpharep_fixture():
|
76 | 81 | return zf
|
77 | 82 |
|
78 | 83 |
|
79 |
| -def pass_alpharep(meth): |
80 |
| - """ |
81 |
| - Given a method, wrap it in a for loop that invokes method |
82 |
| - with each subtest. |
83 |
| - """ |
84 |
| - |
85 |
| - @functools.wraps(meth) |
86 |
| - def wrapper(self): |
87 |
| - for alpharep in self.zipfile_alpharep(): |
88 |
| - meth(self, alpharep=alpharep) |
| 84 | +alpharep_generators = [ |
| 85 | + Invoked.wrap(build_alpharep_fixture), |
| 86 | + Invoked.wrap(compose(add_dirs, build_alpharep_fixture)), |
| 87 | +] |
89 | 88 |
|
90 |
| - return wrapper |
| 89 | +pass_alpharep = parameterize(['alpharep'], alpharep_generators) |
91 | 90 |
|
92 | 91 |
|
93 | 92 | class TestPath(unittest.TestCase):
|
94 | 93 | def setUp(self):
|
95 | 94 | self.fixtures = contextlib.ExitStack()
|
96 | 95 | self.addCleanup(self.fixtures.close)
|
97 | 96 |
|
98 |
| - def zipfile_alpharep(self): |
99 |
| - with self.subTest(): |
100 |
| - yield build_alpharep_fixture() |
101 |
| - with self.subTest(): |
102 |
| - yield add_dirs(build_alpharep_fixture()) |
103 |
| - |
104 | 97 | def zipfile_ondisk(self, alpharep):
|
105 | 98 | tmpdir = pathlib.Path(self.fixtures.enter_context(temp_dir()))
|
106 | 99 | buffer = alpharep.fp
|
@@ -418,6 +411,21 @@ def test_root_unnamed(self, alpharep):
|
418 | 411 | @pass_alpharep
|
419 | 412 | def test_inheritance(self, alpharep):
|
420 | 413 | cls = type('PathChild', (zipfile.Path,), {})
|
421 |
| - for alpharep in self.zipfile_alpharep(): |
422 |
| - file = cls(alpharep).joinpath('some dir').parent |
423 |
| - assert isinstance(file, cls) |
| 414 | + file = cls(alpharep).joinpath('some dir').parent |
| 415 | + assert isinstance(file, cls) |
| 416 | + |
| 417 | + @parameterize( |
| 418 | + ['alpharep', 'path_type', 'subpath'], |
| 419 | + itertools.product( |
| 420 | + alpharep_generators, |
| 421 | + [str, pathlib.Path], |
| 422 | + ['', 'b/'], |
| 423 | + ), |
| 424 | + ) |
| 425 | + def test_pickle(self, alpharep, path_type, subpath): |
| 426 | + zipfile_ondisk = path_type(self.zipfile_ondisk(alpharep)) |
| 427 | + |
| 428 | + saved_1 = pickle.dumps(zipfile.Path(zipfile_ondisk, at=subpath)) |
| 429 | + restored_1 = pickle.loads(saved_1) |
| 430 | + first, *rest = restored_1.iterdir() |
| 431 | + assert first.read_text().startswith('content of ') |
0 commit comments