-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added file existence check and option for force redownload to CorpusD…
…ownloader - GH #125
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
|
||
from audiomate.corpus.io import base | ||
|
||
import pytest | ||
|
||
|
||
def create_mock_corpus_downloader(): | ||
|
||
class MockCorpusDownloader(base.CorpusDownloader): | ||
|
||
@classmethod | ||
def type(cls): | ||
return 'mock' | ||
|
||
def _download(self, target_path): | ||
os.makedirs(os.path.join(target_path, 'subfolder', 'a.txt')) | ||
|
||
return MockCorpusDownloader() | ||
|
||
|
||
class TestCorpusDownloader: | ||
|
||
def test_force_redownload_overwrites_existing_directory(self, tmpdir): | ||
target_folder = tmpdir.strpath | ||
corpus_dl = create_mock_corpus_downloader() | ||
|
||
tmpdir.mkdir('subfolder').join('b.txt') | ||
corpus_dl.download(target_folder, force_redownload=True) | ||
|
||
assert len(os.listdir(tmpdir)) == 1 | ||
assert os.path.exists(os.path.join(target_folder, 'subfolder', 'a.txt')) | ||
assert not os.path.exists(os.path.join(target_folder, 'subfolder', 'b.txt')) | ||
|
||
def test_existing_directory_forces_io_error(self, tmpdir): | ||
target_folder = tmpdir.strpath | ||
corpus_dl = create_mock_corpus_downloader() | ||
|
||
tmpdir.mkdir('subfolder').join('a.txt') | ||
|
||
with pytest.raises(IOError): | ||
corpus_dl.download(target_folder, force_redownload=False) |