diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-16 15:03:42 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-16 15:03:42 (GMT) |
commit | 33138df36abda2d4f1e92537d375f04942d9ab19 (patch) | |
tree | a1ec57e56af687b56e401197699f9afe3ddb021d /Lib/test/test_glob.py | |
parent | 3c331bb729b78419da455b9f8be81b566cb7a489 (diff) | |
parent | 5461558d1ab5809c44d02f5e8669aca64ec07404 (diff) | |
download | cpython-33138df36abda2d4f1e92537d375f04942d9ab19.zip cpython-33138df36abda2d4f1e92537d375f04942d9ab19.tar.gz cpython-33138df36abda2d4f1e92537d375f04942d9ab19.tar.bz2 |
Issue #16696: fix comparison between bytes and string. Also, improve glob tests.
Diffstat (limited to 'Lib/test/test_glob.py')
-rw-r--r-- | Lib/test/test_glob.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index 8972b8f..e6538f7 100644 --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -97,12 +97,35 @@ class GlobTests(unittest.TestCase): os.path.join('aab', 'F')])) def test_glob_directory_with_trailing_slash(self): - # We are verifying that when there is wildcard pattern which - # ends with os.sep doesn't blow up. - res = glob.glob(self.tempdir + '*' + os.sep) - self.assertEqual(len(res), 1) + # Patterns ending with a slash shouldn't match non-dirs + res = glob.glob(os.path.join(self.tempdir, 'Z*Z') + os.sep) + self.assertEqual(res, []) + res = glob.glob(os.path.join(self.tempdir, 'ZZZ') + os.sep) + self.assertEqual(res, []) + # When there is wildcard pattern which ends with os.sep, glob() + # doesn't blow up. + res = glob.glob(os.path.join(self.tempdir, 'aa*') + os.sep) + self.assertEqual(len(res), 2) # either of these results are reasonable - self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep]) + self.assertIn(set(res), [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) + + def test_glob_bytes_directory_with_trailing_slash(self): + # Same as test_glob_directory_with_trailing_slash, but with a + # bytes argument. + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'Z*Z') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'ZZZ') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'aa*') + os.sep)) + self.assertEqual(len(res), 2) + # either of these results are reasonable + self.assertIn({os.fsdecode(x) for x in res}, [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) @skip_unless_symlink def test_glob_broken_symlinks(self): |