From 592ac488d730a668419b72d779a81d6ad00e5b4d Mon Sep 17 00:00:00 2001 From: Fred Date: Tue, 28 Apr 2020 09:55:15 +0200 Subject: [PATCH] is_matching() should work when match is None --- Makefile | 2 +- peakina/io/fetcher.py | 6 ++++-- setup.cfg | 7 +++++-- tests/io/local/test_file_fetcher.py | 14 ++++++++++++++ tests/test_cache.py | 4 ++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 010a05d3..36280ba1 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ lint: .PHONY: mypy mypy: - mypy peakina + mypy . .PHONY: test test: diff --git a/peakina/io/fetcher.py b/peakina/io/fetcher.py index 35ae4641..ddcb63d4 100644 --- a/peakina/io/fetcher.py +++ b/peakina/io/fetcher.py @@ -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)) diff --git a/setup.cfg b/setup.cfg index de577a9d..ff94f012 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ long-description-content-type = text/markdown; charset=UTF-8 author = Toucan Toco author_email = dev@toucantoco.com url = https://github.com/ToucanToco/peakina -version = 0.5.1 +version = 0.5.2 license = BSD classifiers= Intended Audience :: Developers @@ -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 diff --git a/tests/io/local/test_file_fetcher.py b/tests/io/local/test_file_fetcher.py index ed2874b2..0eb59cd4 100644 --- a/tests/io/local/test_file_fetcher.py +++ b/tests/io/local/test_file_fetcher.py @@ -1,3 +1,6 @@ +import re + +from peakina.io.fetcher import MatchEnum from peakina.io.local.file_fetcher import FileFetcher @@ -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') + ) diff --git a/tests/test_cache.py b/tests/test_cache.py index fc8503f8..59e56ee8 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -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)