Skip to content

Commit

Permalink
Try to fix Windows test
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Dec 5, 2023
1 parent 9285547 commit a5c76c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions audeer/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ def move(
and ``dst_path`` is an existing folder
OSError: if ``src_path`` is a folder
and ``dst_path`` is an existing file
(not raised under Windows)
OSError: if ``dst_path`` is a non-empty folder,
different from ``src_path``,
and ``src_path`` is also a folder
Expand Down
36 changes: 31 additions & 5 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ def test_move(tmpdir, src_path, dst_path):
os.path.join(tmp_dir, src_path),
os.path.join(tmp_dir, dst_path),
)

# src: non-empty folder
# dst: existing empty folder
os.remove(os.path.join(tmp_dir, dst_path, 'file.txt'))
Expand Down Expand Up @@ -1266,6 +1267,7 @@ def test_move(tmpdir, src_path, dst_path):
os.path.join(tmp_dir, src_path),
os.path.join(tmp_dir, dst_path),
)

# src: empty folder
# dst: existing empty folder
os.remove(os.path.join(tmp_dir, dst_path, 'file.txt'))
Expand Down Expand Up @@ -1307,6 +1309,7 @@ def test_move(tmpdir, src_path, dst_path):
assert os.path.isdir(os.path.join(tmp_dir, dst_path))

if src_path != dst_path:

# src: file
# dst: non-empty folder
audeer.rmdir(tmp_dir)
Expand All @@ -1323,6 +1326,7 @@ def test_move(tmpdir, src_path, dst_path):
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'))
Expand All @@ -1331,30 +1335,52 @@ def test_move(tmpdir, src_path, dst_path):
os.path.join(tmp_dir, src_path),
os.path.join(tmp_dir, dst_path),
)

# src: non-empty folder
# dst: file
audeer.rmdir(tmp_dir)
audeer.mkdir(tmp_dir)
audeer.mkdir(tmp_dir, src_path)
audeer.touch(tmp_dir, src_path, 'file.txt')
audeer.touch(tmp_dir, dst_path)
if system == 'Windows':
error_msg = 'Access is denied'
else:
if system != 'Windows':
error_msg = 'Not a directory'
with pytest.raises(OSError, match=error_msg):
with pytest.raises(OSError, match=error_msg):
audeer.move_file(
os.path.join(tmp_dir, src_path),
os.path.join(tmp_dir, dst_path),
)
else:
audeer.move_file(
os.path.join(tmp_dir, src_path),
os.path.join(tmp_dir, dst_path),
)
assert not os.path.exists(os.path.join(tmp_dir, src_path))
assert os.path.exists(os.path.join(tmp_dir, dst_path))
assert os.path.exists(os.path.join(tmp_dir, dst_path, 'file.txt'))
assert os.path.isdir(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(OSError, match=error_msg):
if system != 'Windows':
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),
)
else:
audeer.move_file(
os.path.join(tmp_dir, src_path),
os.path.join(tmp_dir, dst_path),
)
assert not os.path.exists(os.path.join(tmp_dir, src_path))
assert os.path.exists(os.path.join(tmp_dir, dst_path))
assert not os.path.exists(
os.path.join(tmp_dir, dst_path, 'file.txt')
)
assert os.path.isdir(os.path.join(tmp_dir, dst_path))


@pytest.mark.parametrize(
Expand Down

0 comments on commit a5c76c0

Please sign in to comment.