Skip to content

Commit

Permalink
is_matching() should work when match is None
Browse files Browse the repository at this point in the history
  • Loading branch information
fspot committed Apr 28, 2020
1 parent 51a4c3d commit 592ac48
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lint:

.PHONY: mypy
mypy:
mypy peakina
mypy .

.PHONY: test
test:
Expand Down
6 changes: 4 additions & 2 deletions peakina/io/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def mtime(self, filepath: str) -> Optional[int]:
"""Get last modification time of a file"""

@staticmethod
def is_matching(filename: str, match: MatchEnum, pattern: Pattern) -> bool:
if match is MatchEnum.GLOB:
def is_matching(filename: str, match: Optional[MatchEnum], pattern: Pattern) -> bool:
if match is None:
return filename == pattern.pattern
elif match is MatchEnum.GLOB:
return bool(fnmatch.fnmatch(filename, pattern.pattern))
else:
return bool(pattern.match(filename))
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ long-description-content-type = text/markdown; charset=UTF-8
author = Toucan Toco
author_email = [email protected]
url = https://github.com/ToucanToco/peakina
version = 0.5.1
version = 0.5.2
license = BSD
classifiers=
Intended Audience :: Developers
Expand Down Expand Up @@ -68,8 +68,11 @@ force_grid_wrap=0
combine_as_imports=True

[mypy]
ignore_missing_imports = True
plugins = pydantic.mypy
follow_imports = silent
ignore_missing_imports = True
allow_redefinition = True
#check_untyped_defs = True

[tool:pytest]
testpaths = tests
Expand Down
14 changes: 14 additions & 0 deletions tests/io/local/test_file_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import re

from peakina.io.fetcher import MatchEnum
from peakina.io.local.file_fetcher import FileFetcher


Expand All @@ -18,3 +21,14 @@ def test_file_fetcher_mtime_oserror(mocker):
fetcher = FileFetcher()
mocker.patch.object(fetcher, 'mtime').side_effect = OSError('oops')
assert fetcher.get_str_mtime('whatever') is None


def test_file_fetcher_match(path):
fetcher = FileFetcher()
filename = '2020 Report (6).xlsx'
assert fetcher.is_matching(filename, match=None, pattern=re.compile(filename))
assert fetcher.is_matching(filename, match=MatchEnum.GLOB, pattern=re.compile(filename))
assert not fetcher.is_matching(filename, match=MatchEnum.REGEX, pattern=re.compile(filename))
assert fetcher.is_matching(
filename, match=MatchEnum.REGEX, pattern=re.compile(r'2020 Report \(6\).xlsx')
)
4 changes: 2 additions & 2 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def test_hdf_cache(mocker, tmp_path, df_test):


def case_inmemory(tmp_path=None) -> CaseData:
return (CacheEnum.MEMORY,)
return (CacheEnum.MEMORY,) # type: ignore


def case_hdf(tmp_path) -> CaseData:
return (CacheEnum.HDF, tmp_path)
return (CacheEnum.HDF, tmp_path) # type: ignore


@cases_data(module=THIS_MODULE)
Expand Down

0 comments on commit 592ac48

Please sign in to comment.