def test_generator(self): """ Test with no parameters. """ # find all paths paths = [] for path in find_paths(BASEPATH): paths.append(path) self.assertEqual(22, len(paths)) self.assertTrue(os.path.join(BASEPATH, 'dir1') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir2') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir3') in paths) self.assertTrue(os.path.join(BASEPATH, '.dir4') in paths) self.assertTrue(os.path.join(BASEPATH, 'file1.txt') in paths) self.assertTrue(os.path.join(BASEPATH, 'file2.dat') in paths) self.assertTrue(os.path.join(BASEPATH, 'file3.txt') in paths) self.assertTrue(os.path.join(BASEPATH, 'python_logo.gif') in paths) self.assertTrue(os.path.join(BASEPATH, 'python_logo.png') in paths) self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.gif') in paths) self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.jpg') in paths) self.assertTrue(os.path.join(BASEPATH, 'python_logo_gs.png') in paths) self.assertTrue(os.path.join(BASEPATH, 'transparent_gs.png') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir1', 'subdirectory', 'sub.txt') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file4.txt') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir1', 'file5.log') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file6.log') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir2', 'file7.html') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir3', 'file8') in paths) self.assertTrue(os.path.join(BASEPATH, 'dir3', '.file9') in paths)
def build_finder(path, filter): '''Construct a path finder for the specified `path` and with the specified `filter`. Hidden directories are ignored by default.''' if os.path.isfile(path): return (path,) return find_paths(path, filter=filter, ignore=FnmatchFilter('*/.*'))