summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_shutil.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-109590: Update shutil.which on Windows to prefer a PATHEXT extension on ↵Charles Machalow2023-10-021-10/+72
| | | | | executable files (GH-109995) The default arguments for shutil.which() request an executable file, but extensionless files are not executable on Windows and should be ignored.
* gh-99203: shutil.make_archive(): restore select CPython <= 3.10.5 behavior ↵6t8k2023-08-161-0/+43
| | | | | | | | | | | | (GH-99802) Restore following CPython <= 3.10.5 behavior of shutil.make_archive() that went away as part of gh-93160: Do not create an empty archive if root_dir is not a directory, and, in that case, raise FileNotFoundError or NotADirectoryError regardless of format choice. Beyond the brought-back behavior, the function may now also raise these exceptions in dry_run mode.
* gh-106300: Improve `assertRaises(Exception)` usages in tests (GH-106302)Nikita Sobolev2023-07-071-1/+1
|
* gh-105407: Remove unused imports in tests (#105408)Victor Stinner2023-06-061-1/+0
|
* gh-102950: Implement PEP 706 – Filter for tarfile.extractall (#102953)Petr Viktorin2023-04-241-13/+28
|
* GH-75586: Make shutil.which() on Windows more consistent with the OS (GH-103179)Charles Machalow2023-04-041-5/+81
|
* gh-102828: emit deprecation warning for onerror arg to shutil.rmtree (#102850)Irit Katriel2023-03-211-5/+11
|
* gh-102828: fix test failure (add missing skip instructions) (#102835)Irit Katriel2023-03-201-0/+4
|
* gh-102828: add onexc arg to shutil.rmtree. Deprecate onerror. (#102829)Irit Katriel2023-03-191-3/+167
|
* bpo-38523: ignore_dangling_symlinks does not apply recursively (GH-22937)Zackery Spytz2022-11-071-6/+13
|
* gh-74696: Pass root_dir to custom archivers which support it (GH-94251)Serhiy Storchaka2022-10-051-6/+43
| | | | Co-authored-by: Éric <merwok@netwok.org>
* gh-94315: Check for DAC override capability (GH-94316)Christian Heimes2022-06-271-9/+6
| | | | | ``os.geteuid() == 0`` is not a reliable check whether the current user has the capability to bypass permission checks. Tests now probe for DAC override.
* gh-74696: Do not change the current working directory in ↵Serhiy Storchaka2022-06-221-17/+32
| | | | | | | | | | | shutil.make_archive() if possible (GH-93160) It is no longer changed when create a zip or tar archive. It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None. Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* gh-90473: Make chmod a dummy on WASI, skip chmod tests (GH-93534)Christian Heimes2022-06-061-0/+1
| | | WASI does not have the ``chmod(2)`` syscall yet.
* gh-90473: Skip and document more failing tests on WASI (GH-93436)Christian Heimes2022-06-021-0/+1
| | | | | | | - Mark more ``umask()`` cases - ``dup()`` is not supported - ``/dev/null`` is not available - document missing features - mark more modules as not available
* gh-92670: Skip test_shutil.TestCopy.test_copyfile_nonexistent_dir on AIX ↵Ayappan Perumal2022-05-191-0/+4
| | | | (#92718)
* bpo-46245: Add optional parameter dir_fd in shutil.rmtree() (GH-30365)Serhiy Storchaka2022-03-091-0/+21
|
* bpo-45234: Fix FileNotFound exception raised instead of IsADirectoryError in ↵andrei kulakov2021-09-211-0/+40
| | | | | shutil.copyfile() (GH-28421) This was a regression from fixing BPO-43219.
* bpo-43219: skip Solaris in the test as well (GH-27257)Jakub Kulík2021-07-201-1/+2
|
* bpo-43219: shutil.copyfile, raise a less confusing exception instead of ↵andrei kulakov2021-07-101-0/+9
| | | | | | IsADirectoryError (GH-27049) Fixes the misleading IsADirectoryError to be FileNotFoundError.
* bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25181)Inada Naoki2021-04-051-9/+13
| | | | | | * Fix test_shutil * Fix test_imp * Fix test_import * Fix test_importlib
* bpo-42782: Fail fast for permission errors in shutil.move() (GH-24001)Winson Luk2021-03-021-0/+37
| | | | | * Fail fast in shutil.move() to avoid creating destination directories on failure. Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* [WIP/RFC] bpo-15872: tests: remove oddity from test_rmtree_errors (GH-22967)Daniel Hahler2020-12-211-6/+3
| | | | | | | | | This was added for (some) Windows buildbots back in 2012, and should either not be necessary anymore, or it should probably get investigated why "\*.*" gets added to filenames in the first place. Ref: Automerge-Triggered-By: GH:hynek
* bpo-31904: skip some tests related to fifo on VxWorks (GH-23473)pxinwr2020-11-281-0/+4
| | | On VxWork RTOS, FIFO must be created under directory "/fifos/". Some test cases related to fifo is invalid on VxWorks. So skip them.
* bpo-40592: shutil.which will not return None anymore if ; is the last char ↵Christopher Marchfelder2020-10-231-0/+17
| | | | | | in PATHEXT (GH-20088) shutil.which will not return None anymore for empty str in PATHEXT Empty PATHEXT will now be defaulted to _WIN_DEFAULT_PATHEXT
* bpo-40275: Use new test.support helper submodules in tests (GH-21169)Hai Shi2020-06-301-73/+74
|
* bpo-40275: More lazy imports in test.support (GH-20131)Hai Shi2020-05-181-12/+12
| | | | | | | | | | | | | | | | | | | Make the the following imports lazy in test.support: * bz2 * gzip * lzma * resource * zlib The following test.support decorators now need to be called with parenthesis: * @support.requires_bz2 * @support.requires_gzip * @support.requires_lzma * @support.requires_zlib For example, "@requires_zlib" becomes "@requires_zlib()".
* bpo-26067: Do not fail test_shutil / chown when gid/uid cannot be resolved ↵Matthias Braun2020-03-171-6/+11
| | | | | | | | | | | | | | | | | | | (#19032) * bpo-26067: Do not fail test_shutil.chown when gid/uid cannot be resolved There is no guarantee that the users primary uid or gid can be resolved in the unix group/account databases. Skip the last part of the chown test if we cannot resolve the gid or uid to a name. * 📜🤖 Added by blurb_it. * Address review feedback * address review feedback correctly * fix typo Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* bpo-39390 shutil: fix argument types for ignore callback (GH-18122)mbarkhau2020-01-241-0/+42
|
* bpo-38688, shutil.copytree: consume iterator and create list of entries to ↵Bruno P. Kinoshita2019-11-271-0/+11
| | | | prevent infinite recursion (GH-17098)
* bpo-38453: Ensure ntpath.realpath correctly resolves relative paths (GH-16967)Steve Dower2019-11-151-25/+24
| | | | | Ensure isabs() is always True for \\?\ prefixed paths Avoid unnecessary usage of readlink() to avoid resolving broken links incorrectly Ensure shutil tests run in test directory
* bpo-32689: Updates shutil.move to allow for Path objects to be used as ↵Maxwell A McKinnon2019-10-011-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | source arg (GH-15326) Important work originally done by @emilyemorehouse two years ago and nearly ready to go in. This bug has affected many people and in some cases has been a dealbreaker to the adoption of the otherwise wonderful pathlib and PEP519. https://stackoverflow.com/questions/33625931/copy-file-with-pathlib-in-python. This adds the outstanding test request from that PR @vstinner (https://github.com/python/cpython/pull/5393). Test fails without the change, passes with it, along with every other test in test_shutil. Some variants were experimented with to make the one line change and the most performant one was picked. # Added Test for PathLike directory destination, the current fail case ``` Lib/test/test_shutil.py::TestMove::test_move_file_pathlike FAILED [100%] ============================================================== FAILURES =============================================================== __________________________________________________ TestMove.test_move_file_pathlike ___________________________________________________ self = <test.test_shutil.TestMove testMethod=test_move_file_pathlike> def test_move_file_pathlike(self): # Move a file to another location on the same filesystem. src = pathlib.Path(self.src_file) > self._check_move_file(src, self.dst_dir, self.dst_file) Lib/test/test_shutil.py:1563: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Lib/test/test_shutil.py:1545: in _check_move_file shutil.move(src, dst) /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shutil.py:562: in move real_dst = os.path.join(dst, _basename(src)) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ path = PosixPath('/var/folders/r2/psq74t5x3nbfzlph8bh2pvdw0000gn/T/tmp9ie0wh9_/foo') def _basename(path): # A basename() variant which first strips the trailing slash, if present. # Thus we always get the last component of the path, even for directories. sep = os.path.sep + (os.path.altsep or '') > return os.path.basename(path.rstrip(sep)) E AttributeError: 'PosixPath' object has no attribute 'rstrip' /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shutil.py:526: AttributeError ============================================== 1 failed, 102 deselected in 0.30 seconds =============================================== ``` After change: ``` ========================================================= test session starts ========================================================= platform darwin -- Python 3.7.4, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- /Users/maxwellmckinnon/.venvs/TA3.7/bin/python3.7 cachedir: .pytest_cache rootdir: /Users/maxwellmckinnon/dev/cpython plugins: cov-2.7.1, mock-1.10.4 collected 103 items / 102 deselected / 1 selected Lib/test/test_shutil.py::TestMove::test_move_file_pathlike PASSED [100%] ============================================== 1 passed, 102 deselected in 0.06 seconds =============================================== ``` Running all the tests in test_shutil.py ``` ╰─ pytest Lib/test/test_shutil.py -v ========================================================= test session starts ========================================================= platform darwin -- Python 3.7.4, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- /Users/maxwellmckinnon/.venvs/TA3.7/bin/python3.7 cachedir: .pytest_cache rootdir: /Users/maxwellmckinnon/dev/cpython plugins: cov-2.7.1, mock-1.10.4 collected 103 items Lib/test/test_shutil.py::TestShutil::test_chown PASSED [ 0%] Lib/test/test_shutil.py::TestShutil::test_copy PASSED [ 1%] ... Lib/test/test_shutil.py::TermsizeTests::test_stty_match SKIPPED [ 99%] Lib/test/test_shutil.py::PublicAPITests::test_module_all_attribute PASSED [100%] ================================================ 96 passed, 7 skipped in 1.25 seconds ================================================= ``` # Performance Considerations Is it considered poor form to get rid of _basename altogether and make use of pathlib in the move function? I'm not sure if the idea is for all these modules to strictly avoid circular dependencies. They are already using os.path which is just as much a citizen in 3.8 as pathlib right? e.g. `real_dst = os.path.join(dst, _basename(src))` becomes `real_dst = Path(dst) / Path(src).name` I've looked around and familiarized myself, and I now think importing pathlib here is fine. My only remaining concern is that of performance. Here's the performance difference for this step. ``` In [46]: %timeit real_dst = os.path.join("a/b/c", _basename('b/')) 2.71 µs ± 62.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) In [47]: %timeit real_dst = Path("a/b/c") / Path('b/').name 12.4 µs ± 65.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) ``` Is 10us significant or insignificant compared to the least expensive operation this function will do? I don't know. Let's find out. ``` In [55]: %timeit os.rename('/tmp/a/a.txt', '/tmp/a/b.txt'); os.rename('/tmp/a/b.txt', '/tmp/a/a.txt') 124 µs ± 2.18 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) ``` 62us to rename. 10us seems significant enough that we wouldn't want to favor the Path sugar suggestion. 16% speed decrease from adding the 10us. What do people think? I was hoping to get to use pathlib.Path here, but I suspect for this low level move, it should be as fast as possible, and 16% is not worth one line of sugary code to me. https://bugs.python.org/issue32689 Automerge-Triggered-By: @gvanrossum
* bpo-38223: Reorganize test_shutil. (GH-16281)Serhiy Storchaka2019-09-261-487/+478
| | | | | | * Group tests for specific functions and groups of related functions into separate classes. * Clean up creating and cleaning up temporary directories. * Simplify and make more robust monkey patching of shutil.open.
* bpo-37834: Normalise handling of reparse points on Windows (GH-15231)Steve Dower2019-08-211-3/+66
| | | | | | | | | | bpo-37834: Normalise handling of reparse points on Windows * ntpath.realpath() and nt.stat() will traverse all supported reparse points (previously was mixed) * nt.lstat() will let the OS traverse reparse points that are not name surrogates (previously would not traverse any reparse point) * nt.[l]stat() will only set S_IFLNK for symlinks (previous behaviour) * nt.readlink() will read destinations for symlinks and junction points only bpo-1311: os.path.exists('nul') now returns True on Windows * nt.stat('nul').st_mode is now S_IFCHR (previously was an error)
* bpo-9949: Enable symlink traversal for ntpath.realpath (GH-15287)Steve Dower2019-08-211-5/+1
|
* bpo-37421: Fix test_shutil: don't leak temporary files (GH-14416)Victor Stinner2019-06-261-2/+3
| | | | | | | * Fix typo in supports_file2file_sendfile(); ensure that dst is removed * Fix test_copytree_custom_copy_function(): remove dst tree. Use support.rmtree() rather than shutil.rmtree() to remove temporary directories: support tries harder.
* bpo-36610: shutil.copyfile(): use sendfile() on Linux only (GH-13675)Giampaolo Rodola2019-05-301-3/+3
| | | | ...and avoid using it on Solaris as it can raise EINVAL if offset is equal or bigger than the size of the file
* bpo-24538: Fix bug in shutil involving the copying of xattrs to read-only ↵Olexa Bilaniuk2019-05-101-0/+8
| | | | | | | | files. (PR-13212) Extended attributes can only be set on user-writeable files, but shutil previously first chmod()ed the destination file to the source's permissions and then tried to copy xattrs. This will cause failures if attempting to copy read-only files with xattrs, as occurs with Git clones on Lustre FS.
* bpo-35755: shutil.which() uses os.confstr("CS_PATH") (GH-12858)Victor Stinner2019-04-171-0/+68
| | | | | | | | | | | | | | | | shutil.which() and distutils.spawn.find_executable() now use os.confstr("CS_PATH") if available instead of os.defpath, if the PATH environment variable is not set. Don't use os.confstr("CS_PATH") nor os.defpath if the PATH environment variable is set to an empty string to mimick Unix 'which' command behavior. Changes: * find_executable() now starts by checking for the executable in the current working directly case. Add an explicit "if not path: return None". * Add tests for PATH='' (empty string), PATH=':' and for PATHEXT.
* bpo-35652: shutil.copytree(copy_function=...) erroneously pass DirEntry ↵Giampaolo Rodola2019-02-261-0/+18
| | | | instead of path str (GH-11997)
* Clean up code which checked presence of os.{stat,lstat,chmod} (#11643)Anthony Sottile2019-02-251-4/+0
|
* bpo-35704: Prevent test_shutil fail result when AIX is 32-bit and MAXDATA < ↵Michael Felt2019-02-181-0/+13
| | | | | 0x20000000 (GH-11500) https://bugs.python.org/issue35704
* bpo-18283: Add support for bytes to shutil.which (GH-11818)Cheryl Sabella2019-02-131-4/+17
|
* bpo-20849: add dirs_exist_ok arg to shutil.copytree (patch by Josh Bronson)jab2018-12-281-0/+25
|
* bpo-35458: Fix test_shutil.test_disk_usage() (GH-11111)Victor Stinner2018-12-111-1/+5
| | | | | | | | | | The following test fails if a different process creates or removes a file on the same disk partition between the two lines: usage = shutil.disk_usage(os.path.dirname(__file__)) self.assertEqual(usage, shutil.disk_usage(__file__)) Only test that disk_usage() succeed on a filename, but don't check the result. Add also tests on the fields type (must be int).
* bpo-32557: allow shutil.disk_usage to take a file path on Windows also (GH-9372)Joe Pamer2018-09-251-0/+1
| | | https://bugs.python.org/issue32557
* bpo-34661: Fix test skipping call. (GH-9266)Benjamin Peterson2018-09-131-1/+1
|
* closes bpo-34661: Fix test_shutil if unzip doesn't support -t. (GH-9262)Benjamin Peterson2018-09-131-0/+2
|
* Revert "bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)" (GH-7919)Victor Stinner2018-06-261-4/+5
| | | This reverts commit 8fbbdf0c3107c3052659e166f73990b466eacbb0.
* bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)Victor Stinner2018-06-221-5/+4
| | | | | | | | * Add support.MS_WINDOWS: True if Python is running on Microsoft Windows. * Add support.MACOS: True if Python is running on Apple macOS. * Replace support.is_android with support.ANDROID * Replace support.is_jython with support.JYTHON * Cleanup code to initialize unix_shell