Kaydet (Commit) a1b16bab authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #13968: Fixed newly added recursive glob test.

It was failed when run with non-empty current directory.
üst 2c16df26
...@@ -5,7 +5,7 @@ import sys ...@@ -5,7 +5,7 @@ import sys
import unittest import unittest
from test.support import (TESTFN, skip_unless_symlink, from test.support import (TESTFN, skip_unless_symlink,
can_symlink, create_empty_file) can_symlink, create_empty_file, change_cwd)
class GlobTests(unittest.TestCase): class GlobTests(unittest.TestCase):
...@@ -266,44 +266,46 @@ class SymlinkLoopGlobTests(unittest.TestCase): ...@@ -266,44 +266,46 @@ class SymlinkLoopGlobTests(unittest.TestCase):
def test_selflink(self): def test_selflink(self):
tempdir = TESTFN + "_dir" tempdir = TESTFN + "_dir"
os.makedirs(tempdir) os.makedirs(tempdir)
create_empty_file(os.path.join(tempdir, 'file'))
os.symlink(os.curdir, os.path.join(tempdir, 'link'))
self.addCleanup(shutil.rmtree, tempdir) self.addCleanup(shutil.rmtree, tempdir)
with change_cwd(tempdir):
results = glob.glob('**', recursive=True) os.makedirs('dir')
self.assertEqual(len(results), len(set(results))) create_empty_file(os.path.join('dir', 'file'))
results = set(results) os.symlink(os.curdir, os.path.join('dir', 'link'))
depth = 0
while results: results = glob.glob('**', recursive=True)
path = os.path.join(*([tempdir] + ['link'] * depth)) self.assertEqual(len(results), len(set(results)))
self.assertIn(path, results) results = set(results)
results.remove(path) depth = 0
if not results: while results:
break path = os.path.join(*(['dir'] + ['link'] * depth))
path = os.path.join(path, 'file') self.assertIn(path, results)
self.assertIn(path, results) results.remove(path)
results.remove(path) if not results:
depth += 1 break
path = os.path.join(path, 'file')
results = glob.glob(os.path.join('**', 'file'), recursive=True) self.assertIn(path, results)
self.assertEqual(len(results), len(set(results))) results.remove(path)
results = set(results) depth += 1
depth = 0
while results: results = glob.glob(os.path.join('**', 'file'), recursive=True)
path = os.path.join(*([tempdir] + ['link'] * depth + ['file'])) self.assertEqual(len(results), len(set(results)))
self.assertIn(path, results) results = set(results)
results.remove(path) depth = 0
depth += 1 while results:
path = os.path.join(*(['dir'] + ['link'] * depth + ['file']))
results = glob.glob(os.path.join('**', ''), recursive=True) self.assertIn(path, results)
self.assertEqual(len(results), len(set(results))) results.remove(path)
results = set(results) depth += 1
depth = 0
while results: results = glob.glob(os.path.join('**', ''), recursive=True)
path = os.path.join(*([tempdir] + ['link'] * depth + [''])) self.assertEqual(len(results), len(set(results)))
self.assertIn(path, results) results = set(results)
results.remove(path) depth = 0
depth += 1 while results:
path = os.path.join(*(['dir'] + ['link'] * depth + ['']))
self.assertIn(path, results)
results.remove(path)
depth += 1
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment