summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-09-12 12:54:48 (GMT)
committerGregory P. Smith <greg@krypto.org>2019-09-12 12:54:48 (GMT)
commitf9dc2ad89032201427ed5f08061c703794627ad9 (patch)
tree76f92a623714e6cb88f7dae8e4a175d2a4e00c02 /Lib/test/test_os.py
parent5a4f82f457049b5b07b6fba4ca42bc1ecf597976 (diff)
downloadcpython-f9dc2ad89032201427ed5f08061c703794627ad9.zip
cpython-f9dc2ad89032201427ed5f08061c703794627ad9.tar.gz
cpython-f9dc2ad89032201427ed5f08061c703794627ad9.tar.bz2
bpo-37935: Added tests for os.walk(), glob.iglob() and Path.glob() (GH-15956)
Test that they do not keep too many file descriptors open for the host OS in a reasonable test scenario. See [bpo-37935](https://bugs.python.org/issue37935).
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 8ff0296..4a076e3 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1178,6 +1178,27 @@ class WalkTests(unittest.TestCase):
finally:
os.rename(path1new, path1)
+ def test_walk_many_open_files(self):
+ depth = 30
+ base = os.path.join(support.TESTFN, 'deep')
+ p = os.path.join(base, *(['d']*depth))
+ os.makedirs(p)
+
+ iters = [self.walk(base, topdown=False) for j in range(100)]
+ for i in range(depth + 1):
+ expected = (p, ['d'] if i else [], [])
+ for it in iters:
+ self.assertEqual(next(it), expected)
+ p = os.path.dirname(p)
+
+ iters = [self.walk(base, topdown=True) for j in range(100)]
+ p = base
+ for i in range(depth + 1):
+ expected = (p, ['d'] if i < depth else [], [])
+ for it in iters:
+ self.assertEqual(next(it), expected)
+ p = os.path.join(p, 'd')
+
@unittest.skipUnless(hasattr(os, 'fwalk'), "Test needs os.fwalk()")
class FwalkTests(WalkTests):
@@ -1247,6 +1268,10 @@ class FwalkTests(WalkTests):
self.addCleanup(os.close, newfd)
self.assertEqual(newfd, minfd)
+ # fwalk() keeps file descriptors open
+ test_walk_many_open_files = None
+
+
class BytesWalkTests(WalkTests):
"""Tests for os.walk() with bytes."""
def walk(self, top, **kwargs):