diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -4,12 +4,14 @@ import sys import unittest -from test.support import (run_unittest, TESTFN, skip_unless_symlink, +from test.support import (TESTFN, skip_unless_symlink, can_symlink, create_empty_file) class GlobTests(unittest.TestCase): + sep = os.sep + def norm(self, *parts): return os.path.normpath(os.path.join(self.tempdir, *parts)) @@ -117,24 +119,24 @@ # either of these results is reasonable self.assertIn(set(res), [ {self.norm('aaa'), self.norm('aab')}, - {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + {self.norm('aaa') + self.sep, self.norm('aab') + self.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(self.norm('Z*Z') + os.sep)) + res = glob.glob(os.fsencode(self.norm('Z*Z') + self.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(self.norm('ZZZ') + os.sep)) + res = glob.glob(os.fsencode(self.norm('ZZZ') + self.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(self.norm('aa*') + os.sep)) + res = glob.glob(os.fsencode(self.norm('aa*') + self.sep)) self.assertEqual(len(res), 2) # either of these results is reasonable self.assertIn(set(res), [ {os.fsencode(self.norm('aaa')), os.fsencode(self.norm('aab'))}, - {os.fsencode(self.norm('aaa') + os.sep), - os.fsencode(self.norm('aab') + os.sep)}, + {os.fsencode(self.norm('aaa') + self.sep), + os.fsencode(self.norm('aab') + self.sep)}, ]) @skip_unless_symlink @@ -144,7 +146,7 @@ eq(self.glob('sym3', '*'), [self.norm('sym3', 'EF'), self.norm('sym3', 'efg')]) self.assertIn(self.glob('sym3' + os.sep), - [[self.norm('sym3')], [self.norm('sym3') + os.sep]]) + [[self.norm('sym3')], [self.norm('sym3') + self.sep]]) eq(self.glob('*', '*F'), [self.norm('aaa', 'zzzF'), self.norm('aab', 'F'), self.norm('sym3', 'EF')]) @@ -170,9 +172,31 @@ eq(glob.glob(b'\\\\*\\*\\'), []) -def test_main(): - run_unittest(GlobTests) +class GlobBytesTests(GlobTests): + + sep = bytes(os.sep, 'ASCII') + + def norm(self, *parts): + return bytes(os.path.normpath(os.path.join( + self.tempdir, *parts)), 'ASCII') + + def glob(self, *parts): + if len(parts) == 1: + pattern = parts[0] + else: + pattern = os.path.join(*parts) + p = bytes(os.path.join(self.tempdir, pattern), 'ASCII') + res = glob.glob(p) + self.assertEqual(list(glob.iglob(p)), res) + return res + + def test_glob_directory_with_trailing_slash(self): + # This test doesn't use self.glob/norm, override for bytes. + res = glob.glob(bytes(self.tempdir + '*' + os.sep, 'ASCII')) + self.assertEqual(len(res), 1) + self.assertIn(res[0], [bytes(self.tempdir, 'ASCII'), + bytes(self.tempdir + os.sep, 'ASCII')]) if __name__ == "__main__": - test_main() + unittest.main()