Skip to content

Commit

Permalink
Changed name of find_all_files_iter to a generator
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgriffith committed Feb 14, 2014
1 parent d090ec9 commit 8ae5284
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions reuse/reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,12 @@ def file_hash(path, hash_type="md5", blocksize=65536):
return hashit.hexdigest()


def find_all_files_iter(directory=".", ext=None, name=None):
def find_all_files_generator(directory=".", ext=None, name=None):
"""
Walk through a file directory and return an iterator of files
that match requirements.
"""
print(ext)
if ext and isinstance(ext, str):
ext = [ext]
elif ext and not isinstance(ext, (list, tuple)):
Expand All @@ -306,7 +307,7 @@ def find_all_files(directory=".", ext=None, name=None):
Returns a list of all files in a sub directory that match an extension
and or part of a filename.
"""
return list(find_all_files_iter(directory, ext=ext, name=name))
return list(find_all_files_generator(directory, ext=ext, name=name))


def main(command_line_options=""):
Expand Down
8 changes: 4 additions & 4 deletions test/test_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def test_find_files_name(self):
assert resp[0].endswith(os.path.join(test_root, "test_config.cfg"))

def test_find_files_bad_ext(self):
self.assertRaises(TypeError,
reuse.find_all_files_iter(test_root,
ext=dict(ext='.txt')))
resp = iter(reuse.find_all_files_generator(test_root,
ext={'test': '.txt'}))
self.assertRaises(TypeError, next, resp)

def test_find_files_iterator(self):
resp = reuse.find_all_files_iter(test_root, ext=".cfg")
resp = reuse.find_all_files_generator(test_root, ext=".cfg")
assert not isinstance(resp, list)
resp = [x for x in resp]
assert resp[0].endswith(os.path.join(test_root, "test_config.cfg"))
Expand Down

0 comments on commit 8ae5284

Please sign in to comment.