diff --git a/audeer/core/io.py b/audeer/core/io.py index b41f009..aee2e7f 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -866,9 +866,9 @@ def move( and different from ``src_path`` and ``src_path`` is also a folder (raised only under Windows) - IsADirectoryError: if ``src_path`` is a file + OSError: if ``src_path`` is a file and ``dst_path`` is an existing folder - NotADirectoryError: if ``src_path`` is a folder + OSError: if ``src_path`` is a folder and ``dst_path`` is an existing file Examples: diff --git a/tests/test_io.py b/tests/test_io.py index b3a916e..19f696b 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -1151,7 +1151,7 @@ def test_mkdir(tmpdir): def test_move(tmpdir, src_path, dst_path): system = platform.system() - tmp_dir = audeer.mkdir(tmpdir, 'files') + tmp_dir = audeer.mkdir(tmpdir, 'folder') # src: file # dst: new file @@ -1314,7 +1314,11 @@ def test_move(tmpdir, src_path, dst_path): audeer.touch(tmp_dir, src_path) audeer.mkdir(tmp_dir, dst_path) audeer.touch(tmp_dir, dst_path, 'file.txt') - with pytest.raises(IsADirectoryError, match='Is a directory'): + if system == 'Windows': + error_msg = 'Access denied' + else: + error_msg = 'Is a directory' + with pytest.raises(OSError, match=error_msg): audeer.move_file( os.path.join(tmp_dir, src_path), os.path.join(tmp_dir, dst_path), @@ -1322,7 +1326,7 @@ def test_move(tmpdir, src_path, dst_path): # src: file # dst: empty folder os.remove(os.path.join(tmp_dir, dst_path, 'file.txt')) - with pytest.raises(IsADirectoryError, match='Is a directory'): + with pytest.raises(OSError, match=error_msg): audeer.move_file( os.path.join(tmp_dir, src_path), os.path.join(tmp_dir, dst_path), @@ -1334,7 +1338,11 @@ def test_move(tmpdir, src_path, dst_path): audeer.mkdir(tmp_dir, src_path) audeer.touch(tmp_dir, src_path, 'file.txt') audeer.touch(tmp_dir, dst_path) - with pytest.raises(NotADirectoryError, match='Not a directory'): + if system == 'Windows': + error_msg = 'Access denied' + else: + error_msg = 'Not a directory' + with pytest.raises(OSError, match=error_msg): audeer.move_file( os.path.join(tmp_dir, src_path), os.path.join(tmp_dir, dst_path), @@ -1342,7 +1350,7 @@ def test_move(tmpdir, src_path, dst_path): # src: empty folder # dst: file os.remove(os.path.join(tmp_dir, src_path, 'file.txt')) - with pytest.raises(NotADirectoryError, match='Not a directory'): + with pytest.raises(OSError, match=error_msg): audeer.move_file( os.path.join(tmp_dir, src_path), os.path.join(tmp_dir, dst_path),