Merge pull request #192 from PabloKohan/Fix133
Fix findfiles not to fail on missing/invalid dir
This commit is contained in:
@@ -262,7 +262,10 @@ def get_preferred_uti_extension(uti):
|
|||||||
|
|
||||||
def findfiles(pattern, path_):
|
def findfiles(pattern, path_):
|
||||||
"""Returns list of filenames from path_ matched by pattern
|
"""Returns list of filenames from path_ matched by pattern
|
||||||
shell pattern. Matching is case-insensitive."""
|
shell pattern. Matching is case-insensitive.
|
||||||
|
If 'path_' is invalid/doesn't exist, returns []."""
|
||||||
|
if not os.path.isdir(path_):
|
||||||
|
return []
|
||||||
# See: https://gist.github.com/techtonik/5694830
|
# See: https://gist.github.com/techtonik/5694830
|
||||||
|
|
||||||
rule = re.compile(fnmatch.translate(pattern), re.IGNORECASE)
|
rule = re.compile(fnmatch.translate(pattern), re.IGNORECASE)
|
||||||
|
|||||||
@@ -76,3 +76,13 @@ def test_findfiles():
|
|||||||
assert len(files) == 2
|
assert len(files) == 2
|
||||||
assert "file1.jpg" in files
|
assert "file1.jpg" in files
|
||||||
assert "file2.JPG" in files
|
assert "file2.JPG" in files
|
||||||
|
|
||||||
|
|
||||||
|
def test_findfiles_invalid_dir():
|
||||||
|
import tempfile
|
||||||
|
import os.path
|
||||||
|
from osxphotos.utils import findfiles
|
||||||
|
|
||||||
|
temp_dir = tempfile.TemporaryDirectory(prefix="osxphotos_")
|
||||||
|
files = findfiles("*.jpg", f"{temp_dir.name}/no_such_dir" )
|
||||||
|
assert len(files) == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user