Skip to content

Commit

Permalink
Change to OSError
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Dec 5, 2023
1 parent 4b16b32 commit c05d895
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions audeer/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 13 additions & 5 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1314,15 +1314,19 @@ 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),
)
# 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),
Expand All @@ -1334,15 +1338,19 @@ 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),
)
# 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),
Expand Down

0 comments on commit c05d895

Please sign in to comment.