diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-11 11:33:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-11 11:33:02 (GMT) |
commit | a1b16bab2fc389813d042fe1d0c3d4d38d1bbb9b (patch) | |
tree | ffcfd3ecb274228ac0d997d9b6b48f05edf1bb98 /Lib/test/test_glob.py | |
parent | 2c16df269af5986e2eb79bda36dc8f0f34324a7e (diff) | |
download | cpython-a1b16bab2fc389813d042fe1d0c3d4d38d1bbb9b.zip cpython-a1b16bab2fc389813d042fe1d0c3d4d38d1bbb9b.tar.gz cpython-a1b16bab2fc389813d042fe1d0c3d4d38d1bbb9b.tar.bz2 |
Issue #13968: Fixed newly added recursive glob test.
It was failed when run with non-empty current directory.
Diffstat (limited to 'Lib/test/test_glob.py')
-rw-r--r-- | Lib/test/test_glob.py | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index 72789d0..21b0153 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -5,7 +5,7 @@ import sys import unittest from test.support import (TESTFN, skip_unless_symlink, - can_symlink, create_empty_file) + can_symlink, create_empty_file, change_cwd) class GlobTests(unittest.TestCase): @@ -266,44 +266,46 @@ class SymlinkLoopGlobTests(unittest.TestCase): def test_selflink(self): tempdir = TESTFN + "_dir" 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) - - results = glob.glob('**', recursive=True) - self.assertEqual(len(results), len(set(results))) - results = set(results) - depth = 0 - while results: - path = os.path.join(*([tempdir] + ['link'] * depth)) - self.assertIn(path, results) - results.remove(path) - if not results: - break - path = os.path.join(path, 'file') - self.assertIn(path, results) - results.remove(path) - depth += 1 - - results = glob.glob(os.path.join('**', 'file'), recursive=True) - self.assertEqual(len(results), len(set(results))) - results = set(results) - depth = 0 - while results: - path = os.path.join(*([tempdir] + ['link'] * depth + ['file'])) - self.assertIn(path, results) - results.remove(path) - depth += 1 - - results = glob.glob(os.path.join('**', ''), recursive=True) - self.assertEqual(len(results), len(set(results))) - results = set(results) - depth = 0 - while results: - path = os.path.join(*([tempdir] + ['link'] * depth + [''])) - self.assertIn(path, results) - results.remove(path) - depth += 1 + with change_cwd(tempdir): + os.makedirs('dir') + create_empty_file(os.path.join('dir', 'file')) + os.symlink(os.curdir, os.path.join('dir', 'link')) + + results = glob.glob('**', recursive=True) + self.assertEqual(len(results), len(set(results))) + results = set(results) + depth = 0 + while results: + path = os.path.join(*(['dir'] + ['link'] * depth)) + self.assertIn(path, results) + results.remove(path) + if not results: + break + path = os.path.join(path, 'file') + self.assertIn(path, results) + results.remove(path) + depth += 1 + + results = glob.glob(os.path.join('**', 'file'), recursive=True) + self.assertEqual(len(results), len(set(results))) + results = set(results) + depth = 0 + while results: + path = os.path.join(*(['dir'] + ['link'] * depth + ['file'])) + self.assertIn(path, results) + results.remove(path) + depth += 1 + + results = glob.glob(os.path.join('**', ''), recursive=True) + self.assertEqual(len(results), len(set(results))) + results = set(results) + depth = 0 + while results: + path = os.path.join(*(['dir'] + ['link'] * depth + [''])) + self.assertIn(path, results) + results.remove(path) + depth += 1 if __name__ == "__main__": |