From 8ae5284b5042b1bdbdf1ceeefb7892555ec22d20 Mon Sep 17 00:00:00 2001 From: Chris Griffith Date: Thu, 13 Feb 2014 23:43:54 -0500 Subject: [PATCH] Changed name of find_all_files_iter to a generator --- reuse/reuse.py | 5 +++-- test/test_reuse.py | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/reuse/reuse.py b/reuse/reuse.py index 7e9c08c..69c94fa 100644 --- a/reuse/reuse.py +++ b/reuse/reuse.py @@ -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)): @@ -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=""): diff --git a/test/test_reuse.py b/test/test_reuse.py index 25333f6..35f4e06 100644 --- a/test/test_reuse.py +++ b/test/test_reuse.py @@ -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"))