summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_glob.py
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2005-01-08 13:13:19 (GMT)
committerJohannes Gijsbers <jlg@dds.nl>2005-01-08 13:13:19 (GMT)
commit836f5433f7ee79f208186ca0d10594b22cf7e05b (patch)
treed5909575b732a17a75dc5e0e76180d61a5d037c6 /Lib/test/test_glob.py
parente4172eadf3fb9c1de591305ad4ca4ce3e252abd3 (diff)
downloadcpython-836f5433f7ee79f208186ca0d10594b22cf7e05b.zip
cpython-836f5433f7ee79f208186ca0d10594b22cf7e05b.tar.gz
cpython-836f5433f7ee79f208186ca0d10594b22cf7e05b.tar.bz2
Patch #943206:
`glob.glob()` currently calls itself recursively to build a list of matches of the dirname part of the pattern and then filters by the basename part. This is effectively BFS. ``glob.glob('*/*/*/*/*/foo')`` will build a huge list of all directories 5 levels deep even if only a handful of them contain a ``foo`` entry. A generator-based recusion would never have to store these list at once by implementing DFS. This patch converts the `glob` function to an `iglob` recursive generator . `glob()` now just returns ``list(iglob(pattern))``. I also cleaned up the code a bit (reduced duplicate `has_magic()` checks and created a second `glob0` helper func so that the main loop need not be duplicated). Thanks to Cherniavsky Beni for the patch!
Diffstat (limited to 'Lib/test/test_glob.py')
-rw-r--r--Lib/test/test_glob.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py
index af81dab..f23dcf1 100644
--- a/Lib/test/test_glob.py
+++ b/Lib/test/test_glob.py
@@ -61,7 +61,9 @@ class GlobTests(unittest.TestCase):
else:
pattern = os.path.join(*parts)
p = os.path.join(self.tempdir, pattern)
- return glob.glob(p)
+ res = glob.glob(p)
+ self.assertEqual(list(glob.iglob(p)), res)
+ return res
def assertSequencesEqual_noorder(self, l1, l2):
self.assertEqual(set(l1), set(l2))