@@ -1376,6 +1376,107 @@ def test_owner_and_group_windows(self):
13761376 with self .assertRaises (NotImplementedError ):
13771377 self .path (path ).group ()
13781378
1379+ @unittest .skipIf (sys .version_info < (3 , 14 ), "copy() is new in Python 3.14" )
1380+ def test_copy_new_file (self ):
1381+ source_path = self .path (self .make_path ("some_file" ))
1382+ target_path = self .make_path ("some_other_file" )
1383+ self .create_file (source_path , contents = "test" )
1384+ target = source_path .copy (target_path )
1385+ self .assertEqual (target_path , str (target ))
1386+ self .assertTrue (target .exists ())
1387+ self .assertEqual ("test" , target .read_text ())
1388+
1389+ @unittest .skipIf (sys .version_info < (3 , 14 ), "copy() is new in Python 3.14" )
1390+ def test_copy_to_existing_file (self ):
1391+ source_path = self .path (self .make_path ("some_file" ))
1392+ target_path = self .make_path ("some_other_file" )
1393+ self .create_file (source_path , contents = "foo" )
1394+ self .create_file (target_path , contents = "bar" )
1395+ target = source_path .copy (target_path )
1396+ self .assertEqual (target_path , str (target ))
1397+ self .assertTrue (source_path .exists ())
1398+ self .assertTrue (target .exists ())
1399+ self .assertEqual ("foo" , target .read_text ())
1400+
1401+ @unittest .skipIf (sys .version_info < (3 , 14 ), "copy() is new in Python 3.14" )
1402+ def test_copy_directory (self ):
1403+ source_path = self .path (self .make_path ("some_dir" ))
1404+ self .create_file (source_path / "foo" , contents = "foo" )
1405+ self .create_file (source_path / "bar" , contents = "bar" )
1406+ self .create_dir (source_path / "dir" )
1407+ target_path = self .make_path ("new_dir" )
1408+ target = source_path .copy (target_path )
1409+ self .assertEqual (target_path , str (target ))
1410+ self .assertTrue (source_path .exists ())
1411+ self .assertTrue (target .exists ())
1412+ self .assertTrue ((target / "foo" ).exists ())
1413+ self .assertEqual ("foo" , (target / "foo" ).read_text ())
1414+ self .assertEqual ("bar" , (target / "bar" ).read_text ())
1415+
1416+ @unittest .skipIf (sys .version_info < (3 , 14 ), "copy_into() is new in Python 3.14" )
1417+ def test_copy_into (self ):
1418+ source_dir = self .path (self .make_path ("some_dir" ))
1419+ source_path = source_dir / "foo"
1420+ self .create_file (source_path , contents = "foo" )
1421+ target_path = self .path (self .make_path ("new_dir" ))
1422+ self .create_dir (target_path )
1423+ target = source_path .copy_into (target_path )
1424+ self .assertTrue (source_path .exists ())
1425+ self .assertTrue (target .exists ())
1426+ self .assertEqual (str (target_path / "foo" ), str (target ))
1427+ self .assertEqual ("foo" , target .read_text ())
1428+
1429+ @unittest .skipIf (sys .version_info < (3 , 14 ), "move() is new in Python 3.14" )
1430+ def test_move_file (self ):
1431+ source_path = self .path (self .make_path ("some_file" ))
1432+ target_path = self .make_path ("some_other_file" )
1433+ self .create_file (source_path , contents = "test" )
1434+ target = source_path .move (target_path )
1435+ self .assertEqual (target_path , str (target ))
1436+ self .assertFalse (source_path .exists ())
1437+ self .assertTrue (target .exists ())
1438+ self .assertEqual ("test" , target .read_text ())
1439+
1440+ @unittest .skipIf (sys .version_info < (3 , 14 ), "move() is new in Python 3.14" )
1441+ def test_move_to_existing_file (self ):
1442+ source_path = self .path (self .make_path ("some_file" ))
1443+ target_path = self .make_path ("some_other_file" )
1444+ self .create_file (source_path , contents = "foo" )
1445+ self .create_file (target_path , contents = "bar" )
1446+ target = source_path .move (target_path )
1447+ self .assertEqual (target_path , str (target ))
1448+ self .assertFalse (source_path .exists ())
1449+ self .assertTrue (target .exists ())
1450+ self .assertEqual ("foo" , target .read_text ())
1451+
1452+ @unittest .skipIf (sys .version_info < (3 , 14 ), "move() is new in Python 3.14" )
1453+ def test_move_directory (self ):
1454+ source_path = self .path (self .make_path ("some_dir" ))
1455+ self .create_file (source_path / "foo" , contents = "foo" )
1456+ self .create_file (source_path / "bar" , contents = "bar" )
1457+ self .create_dir (source_path / "dir" )
1458+ target_path = self .make_path ("new_dir" )
1459+ target = source_path .move (target_path )
1460+ self .assertEqual (target_path , str (target ))
1461+ self .assertFalse (source_path .exists ())
1462+ self .assertTrue (target .exists ())
1463+ self .assertTrue ((target / "foo" ).exists ())
1464+ self .assertEqual ("foo" , (target / "foo" ).read_text ())
1465+ self .assertEqual ("bar" , (target / "bar" ).read_text ())
1466+
1467+ @unittest .skipIf (sys .version_info < (3 , 14 ), "move_into() is new in Python 3.14" )
1468+ def test_move_into (self ):
1469+ source_dir = self .path (self .make_path ("some_dir" ))
1470+ source_path = source_dir / "foo"
1471+ self .create_file (source_path , contents = "foo" )
1472+ target_path = self .path (self .make_path ("new_dir" ))
1473+ self .create_dir (target_path )
1474+ target = source_path .move_into (target_path )
1475+ self .assertFalse (source_path .exists ())
1476+ self .assertTrue (target .exists ())
1477+ self .assertEqual (str (target_path / "foo" ), str (target ))
1478+ self .assertEqual ("foo" , target .read_text ())
1479+
13791480 def test_walk (self ):
13801481 """Regression test for #915 - walk results shall be strings."""
13811482 base_dir = self .make_path ("foo" )
0 commit comments