bpo-30218: support path-like objects in shutil.unpack_archive() (GH-1… · python/cpython@a12df7b (original) (raw)
`@@ -10,6 +10,7 @@
`
10
10
`import os.path
`
11
11
`import errno
`
12
12
`import functools
`
``
13
`+
import pathlib
`
13
14
`import subprocess
`
14
15
`from shutil import (make_archive,
`
15
16
`register_archive_format, unregister_archive_format,
`
`@@ -1223,6 +1224,18 @@ def test_register_archive_format(self):
`
1223
1224
`self.assertNotIn('xxx', formats)
`
1224
1225
``
1225
1226
`def check_unpack_archive(self, format):
`
``
1227
`+
self.check_unpack_archive_with_converter(format, lambda path: path)
`
``
1228
`+
self.check_unpack_archive_with_converter(format, pathlib.Path)
`
``
1229
+
``
1230
`+
class MyPath:
`
``
1231
`+
def init(self, path):
`
``
1232
`+
self.path = path
`
``
1233
`+
def fspath(self):
`
``
1234
`+
return self.path
`
``
1235
+
``
1236
`+
self.check_unpack_archive_with_converter(format, MyPath)
`
``
1237
+
``
1238
`+
def check_unpack_archive_with_converter(self, format, converter):
`
1226
1239
`root_dir, base_dir = self._create_files()
`
1227
1240
`expected = rlistdir(root_dir)
`
1228
1241
`expected.remove('outer')
`
`@@ -1232,16 +1245,16 @@ def check_unpack_archive(self, format):
`
1232
1245
``
1233
1246
`# let's try to unpack it now
`
1234
1247
`tmpdir2 = self.mkdtemp()
`
1235
``
`-
unpack_archive(filename, tmpdir2)
`
``
1248
`+
unpack_archive(converter(filename), converter(tmpdir2))
`
1236
1249
`self.assertEqual(rlistdir(tmpdir2), expected)
`
1237
1250
``
1238
1251
`# and again, this time with the format specified
`
1239
1252
`tmpdir3 = self.mkdtemp()
`
1240
``
`-
unpack_archive(filename, tmpdir3, format=format)
`
``
1253
`+
unpack_archive(converter(filename), converter(tmpdir3), format=format)
`
1241
1254
`self.assertEqual(rlistdir(tmpdir3), expected)
`
1242
1255
``
1243
``
`-
self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
`
1244
``
`-
self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')
`
``
1256
`+
self.assertRaises(shutil.ReadError, unpack_archive, converter(TESTFN))
`
``
1257
`+
self.assertRaises(ValueError, unpack_archive, converter(TESTFN), format='xxx')
`
1245
1258
``
1246
1259
`def test_unpack_archive_tar(self):
`
1247
1260
`self.check_unpack_archive('tar')
`