Skip to content

Commit

Permalink
Merge pull request #199 from jokva/add-tag-not-found
Browse files Browse the repository at this point in the history
Add TagNotFoundError for tag misses in Bazefetcher
  • Loading branch information
jokva authored Mar 17, 2020
2 parents b3b63cd + 4f7cd04 commit 076f050
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion camille/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""


from .bazefetcher import Bazefetcher
from .bazefetcher import Bazefetcher, TagNotFoundError
from .windiris import windiris


Expand Down
4 changes: 3 additions & 1 deletion camille/source/bazefetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from collections import abc
from math import ceil

class TagNotFoundError(ValueError):
pass

date_pattern = r'[0-9]{4}-[0-9]{2}-[0-9]{2}'
time_pattern = r'[0-9]{2}\.[0-9]{2}\.[0-9]{2}\+[0-9]{2}\.[0-9]{2}'
Expand Down Expand Up @@ -55,7 +57,7 @@ def _get_files(src_dirs, tag, fn_regex, date_pred):
tag_roots = list(filter(isdir, (join(dr, tag) for dr in src_dirs)))

if not tag_roots:
raise ValueError('Tag {} not found in {}'.format(tag, src_dirs))
raise TagNotFoundError('Tag {} not found in {}'.format(tag, src_dirs))

files = [join(r, fn) for r in tag_roots for fn in os.listdir(r)
if fn_regex.match(fn) and date_pred(fn)]
Expand Down
4 changes: 2 additions & 2 deletions tests/source/test_bazefetcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from camille.source import Bazefetcher
from camille.source import Bazefetcher, TagNotFoundError
from camille.source.bazefetcher import _get_files_between_start_and_end
from datetime import datetime, timedelta
from math import pi
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_no_directories():
in str(excinfo.value))

def test_non_existing_tag():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(TagNotFoundError) as excinfo:
baze('non-existing-tag', t1_1, t1_1_1)
assert 'Tag non-existing-tag not found' in str(excinfo.value)

Expand Down

0 comments on commit 076f050

Please sign in to comment.