diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2017-05-05 21:27:12 (GMT) |
---|---|---|
committer | Brett Cannon <brettcannon@users.noreply.github.com> | 2017-05-05 21:27:12 (GMT) |
commit | a12df7b7d40dbf47825917c8fa03d2c09b5a382c (patch) | |
tree | ad818268e3f1adb56743292245eac64c8ce9be20 /Lib/test/test_shutil.py | |
parent | a1054c3b0037d4c2a5492e79fc193f36245366c7 (diff) | |
download | cpython-a12df7b7d40dbf47825917c8fa03d2c09b5a382c.zip cpython-a12df7b7d40dbf47825917c8fa03d2c09b5a382c.tar.gz cpython-a12df7b7d40dbf47825917c8fa03d2c09b5a382c.tar.bz2 |
bpo-30218: support path-like objects in shutil.unpack_archive() (GH-1367)
Thanks to Jelle Zijlstra for the patch.
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r-- | Lib/test/test_shutil.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index c7f7d1d..f21e6ad 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -10,6 +10,7 @@ import os import os.path import errno import functools +import pathlib import subprocess from shutil import (make_archive, register_archive_format, unregister_archive_format, @@ -1223,6 +1224,18 @@ class TestShutil(unittest.TestCase): self.assertNotIn('xxx', formats) def check_unpack_archive(self, format): + self.check_unpack_archive_with_converter(format, lambda path: path) + self.check_unpack_archive_with_converter(format, pathlib.Path) + + class MyPath: + def __init__(self, path): + self.path = path + def __fspath__(self): + return self.path + + self.check_unpack_archive_with_converter(format, MyPath) + + def check_unpack_archive_with_converter(self, format, converter): root_dir, base_dir = self._create_files() expected = rlistdir(root_dir) expected.remove('outer') @@ -1232,16 +1245,16 @@ class TestShutil(unittest.TestCase): # let's try to unpack it now tmpdir2 = self.mkdtemp() - unpack_archive(filename, tmpdir2) + unpack_archive(converter(filename), converter(tmpdir2)) self.assertEqual(rlistdir(tmpdir2), expected) # and again, this time with the format specified tmpdir3 = self.mkdtemp() - unpack_archive(filename, tmpdir3, format=format) + unpack_archive(converter(filename), converter(tmpdir3), format=format) self.assertEqual(rlistdir(tmpdir3), expected) - self.assertRaises(shutil.ReadError, unpack_archive, TESTFN) - self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx') + self.assertRaises(shutil.ReadError, unpack_archive, converter(TESTFN)) + self.assertRaises(ValueError, unpack_archive, converter(TESTFN), format='xxx') def test_unpack_archive_tar(self): self.check_unpack_archive('tar') |