def test_moveto(self): # move file p_file = Path(__file__).change(new_basename="file_to_move.txt") p_file_new = p_file.moveto(new_ext=".rst") # change extension assert p_file.exists() is False assert p_file_new.exists() is True p_file = p_file_new.moveto(new_ext=".txt") # move back # move file into not existing folder with pytest.raises(EnvironmentError): p_file.moveto(new_dirname="NOT-EXIST-FOLDER-MOVETO") # move file into not existsing folder, and create the folder p_file_new = p_file.moveto( new_abspath=Path(__file__).parent.append_parts( "NOT-EXIST-FOLDER-MOVETO", "file_to_move.txt"), makedirs=True, ) p_file = p_file_new.moveto(new_abspath=p_file.abspath) # move directory p_dir = Path(__file__).change(new_basename="wow") n_files = p_dir.n_file n_dir = p_dir.n_dir p_dir_new = p_dir.moveto(new_basename="wow1") assert n_files == p_dir_new.n_file assert n_dir == p_dir_new.n_dir p_dir = p_dir_new.moveto(new_basename="wow")
def test_copyto(self): # copy file p_file = Path(__file__).change(new_basename="file_to_copy.txt") p_file_new = p_file.change(new_ext=".rst") assert p_file_new.exists() is False p_file_new = p_file.copyto(new_ext=".rst") assert p_file.exists() is True assert p_file_new.exists() is True # copy file into not existing folder with pytest.raises(Exception): p_file.copyto(new_dirname="NOT-EXIST-FOLDER-COPYTO") # copy file into not existing folder, and create the folder p_file_new = p_file.change( new_abspath=Path(__file__).parent.append_parts( "NOT-EXIST-FOLDER-COPYTO", "file_to_copy.txt"), ) assert p_file_new.exists() is False assert p_file_new.parent.exists() is False p_file_new = p_file.copyto( new_abspath=Path(__file__).parent.append_parts( "NOT-EXIST-FOLDER-COPYTO", "file_to_copy.txt"), makedirs=True, ) assert p_file_new.exists() is True # copy directory p_dir = Path(__file__).change(new_basename="wow") n_files = p_dir.n_file p_dir_new = p_dir.moveto(new_basename="wow1") assert n_files == p_dir_new.n_file