Skip to content

Commit

Permalink
Added file existence check to CorpusReader ABC - Fixes #89
Browse files Browse the repository at this point in the history
  • Loading branch information
cdkini authored and ynop committed Jul 13, 2020
1 parent 143c21d commit 5da5e70
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions audiomate/corpus/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ def load(self, path):
Corpus: The loaded corpus
Raises:
IOError: When the provided path does not exist.
IOError: When the data set is invalid, for example because required files (annotations, …) are missing.
"""
if not os.path.exists(path):
raise IOError('Invalid path provided: {} not found'.format(path))

# Check for missing files
missing_files = self._check_for_missing_files(path)

Expand Down
28 changes: 28 additions & 0 deletions tests/corpus/io/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,31 @@ def test_existing_directory_forces_io_error(self, tmpdir):

with pytest.raises(IOError):
corpus_dl.download(target_folder, force_redownload=False)


def create_mock_corpus_reader():

class MockCorpusReader(base.CorpusReader):

@classmethod
def type(cls):
return 'mock'

def _load(self, path):
return

def _check_for_missing_files(self, path):
return []

return MockCorpusReader()


class TestCorpusReader:

def test_invalid_path_forces_io_error(self, tmpdir):
target_folder = tmpdir.strpath
corpus_reader = create_mock_corpus_reader()

with pytest.raises(IOError):
path = os.path.join(target_folder, 'tmp')
corpus_reader.load(path)

0 comments on commit 5da5e70

Please sign in to comment.