diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-08-25 15:51:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-25 15:51:51 (GMT) |
commit | 625d0705b9ab348f85853ed73b796763b70154a5 (patch) | |
tree | 40e40aa79d09b2ad39ed7cb4b5efb34ed20e20b5 /Lib/test/test_pathlib/test_pathlib.py | |
parent | aa905925e1a0120e59e4ffe0874fbd098bf47e63 (diff) | |
download | cpython-625d0705b9ab348f85853ed73b796763b70154a5.zip cpython-625d0705b9ab348f85853ed73b796763b70154a5.tar.gz cpython-625d0705b9ab348f85853ed73b796763b70154a5.tar.bz2 |
GH-73991: Add `pathlib.Path.move()` (#122073)
Add a `Path.move()` method that moves a file or directory tree, and returns a new `Path` instance pointing to the target.
This method is similar to `shutil.move()`, except that it doesn't accept a *copy_function* argument, and it doesn't check whether the destination is an existing directory.
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib.py')
-rw-r--r-- | Lib/test/test_pathlib/test_pathlib.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index ad1720c..4d38246 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -45,6 +45,19 @@ delete_use_fd_functions = ( {os.open, os.stat, os.unlink, os.rmdir} <= os.supports_dir_fd and os.listdir in os.supports_fd and os.stat in os.supports_follow_symlinks) +def patch_replace(old_test): + def new_replace(self, target): + raise OSError(errno.EXDEV, "Cross-device link", self, target) + + def new_test(self): + old_replace = self.cls.replace + self.cls.replace = new_replace + try: + old_test(self) + finally: + self.cls.replace = old_replace + return new_test + # # Tests for the pure classes. # @@ -799,6 +812,55 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest): target_file = target.joinpath('dirD', 'fileD') self.assertEqual(os.getxattr(target_file, b'user.foo'), b'42') + @patch_replace + def test_move_file_other_fs(self): + self.test_move_file() + + @patch_replace + def test_move_file_to_file_other_fs(self): + self.test_move_file_to_file() + + @patch_replace + def test_move_file_to_dir_other_fs(self): + self.test_move_file_to_dir() + + @patch_replace + def test_move_dir_other_fs(self): + self.test_move_dir() + + @patch_replace + def test_move_dir_to_dir_other_fs(self): + self.test_move_dir_to_dir() + + @patch_replace + def test_move_dir_into_itself_other_fs(self): + self.test_move_dir_into_itself() + + @patch_replace + @needs_symlinks + def test_move_file_symlink_other_fs(self): + self.test_move_file_symlink() + + @patch_replace + @needs_symlinks + def test_move_file_symlink_to_itself_other_fs(self): + self.test_move_file_symlink_to_itself() + + @patch_replace + @needs_symlinks + def test_move_dir_symlink_other_fs(self): + self.test_move_dir_symlink() + + @patch_replace + @needs_symlinks + def test_move_dir_symlink_to_itself_other_fs(self): + self.test_move_dir_symlink_to_itself() + + @patch_replace + @needs_symlinks + def test_move_dangling_symlink_other_fs(self): + self.test_move_dangling_symlink() + def test_resolve_nonexist_relative_issue38671(self): p = self.cls('non', 'exist') |