Skip to content

Commit ec3cc2c

Browse files
committed
Let Click handle nonexistent files (issue #318)
1 parent aa813d1 commit ec3cc2c

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

annif/corpus/document.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ def opener(path):
6464
return gzip.open(path, mode='rt')
6565
else:
6666
opener = open
67-
try:
68-
with opener(self.path) as tsvfile:
69-
for line in tsvfile:
70-
yield from self._parse_tsv_line(line)
71-
except FileNotFoundError as err:
72-
raise AnnifException(str(err))
67+
with opener(self.path) as tsvfile:
68+
for line in tsvfile:
69+
yield from self._parse_tsv_line(line)
7370

7471
def _parse_tsv_line(self, line):
7572
if '\t' in line:

tests/test_corpus.py

-8
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,6 @@ def test_docfile_plain(tmpdir):
220220
assert len(list(docs.documents)) == 3
221221

222222

223-
def test_docfile_nonexistent(tmpdir):
224-
docfile = tmpdir.join('documents_nonexistent.tsv')
225-
with pytest.raises(AnnifException) as err:
226-
docs = annif.corpus.DocumentFile(str(docfile))
227-
list(docs.documents)
228-
assert "No such file or directory: '{}'".format(docfile) in str(err.value)
229-
230-
231223
def test_docfile_plain_invalid_lines(tmpdir, caplog):
232224
logger = annif.logger
233225
logger.propagate = True

0 commit comments

Comments
 (0)