|
4 | 4 | import shutil |
5 | 5 | import sys |
6 | 6 | import unittest |
7 | | -import unittest.mock |
8 | 7 | import warnings |
9 | 8 |
|
10 | 9 | from test import support |
|
13 | 12 | can_symlink, create_empty_file, change_cwd) |
14 | 13 |
|
15 | 14 |
|
16 | | -_supports_dir_fd = {os.open, os.stat} <= os.supports_dir_fd and os.scandir in os.supports_fd |
17 | | - |
18 | | - |
19 | 15 | class GlobTests(unittest.TestCase): |
20 | 16 | dir_fd = None |
21 | 17 |
|
@@ -53,7 +49,7 @@ def setUp(self): |
53 | 49 | def open_dirfd(self): |
54 | 50 | if self.dir_fd is not None: |
55 | 51 | os.close(self.dir_fd) |
56 | | - if _supports_dir_fd: |
| 52 | + if {os.open, os.stat} <= os.supports_dir_fd and os.scandir in os.supports_fd: |
57 | 53 | self.dir_fd = os.open(self.tempdir, os.O_RDONLY | os.O_DIRECTORY) |
58 | 54 | else: |
59 | 55 | self.dir_fd = None |
@@ -409,24 +405,6 @@ def test_glob_above_recursion_limit(self): |
409 | 405 | with infinite_recursion(depth - 5): |
410 | 406 | glob.glob(pattern, recursive=True) |
411 | 407 |
|
412 | | - @unittest.skipUnless(_supports_dir_fd, "Needs support for iglob(dir_fd=...)") |
413 | | - def test_iglob_iter_close(self): |
414 | | - base = os.path.join(self.tempdir, 'deep') |
415 | | - p = os.path.join(base, *(['d'] * 10)) |
416 | | - os.makedirs(p) |
417 | | - with ( |
418 | | - unittest.mock.patch("glob._StringGlobber.open", wraps=os.open) as os_open, |
419 | | - unittest.mock.patch("glob._StringGlobber.close", wraps=os.close) as os_close |
420 | | - ): |
421 | | - self.assertEqual(os_open.call_count, os_close.call_count) |
422 | | - iter = glob.iglob('**/*/d', dir_fd=self.dir_fd, recursive=True) |
423 | | - self.assertEqual(os_open.call_count, os_close.call_count) |
424 | | - self.assertEqual(next(iter), 'deep/d') |
425 | | - self.assertEqual(next(iter), 'deep/d/d') |
426 | | - self.assertGreater(os_open.call_count, os_close.call_count) |
427 | | - iter.close() |
428 | | - self.assertEqual(os_open.call_count, os_close.call_count) |
429 | | - |
430 | 408 | def test_glob0(self): |
431 | 409 | with self.assertWarns(DeprecationWarning): |
432 | 410 | glob.glob0(self.tempdir, 'a') |
|
0 commit comments