diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-06-06 15:57:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-06 15:57:20 (GMT) |
commit | 016aff77cbf5f63ed051a98ac628522a1cfd40a4 (patch) | |
tree | 8ec40c311c2816008dd2255e08fa66f84b8c5c61 /Lib/test/test_support.py | |
parent | 5c022f13ab6db8929e092ad035b3dc61701e3198 (diff) | |
download | cpython-016aff77cbf5f63ed051a98ac628522a1cfd40a4.zip cpython-016aff77cbf5f63ed051a98ac628522a1cfd40a4.tar.gz cpython-016aff77cbf5f63ed051a98ac628522a1cfd40a4.tar.bz2 |
bpo-33773: Fix test.support.fd_count() on Linux/FreBSD (GH-7421)
Substract one because listdir() opens internally a file
descriptor to list the content of the /proc/self/fd/ directory.
Add test_support.test_fd_count().
Move also MAXFD code before msvcrt.CrtSetReportMode(), to make sure
that the report mode is always restored on failure.
(cherry picked from commit 492d6424a7ca907c8ec1df21e51062e8f3d88e32)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r-- | Lib/test/test_support.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 36d5f84..89f1fbf 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -569,6 +569,17 @@ class TestSupport(unittest.TestCase): self.assertTrue(support.match_test(test_access)) self.assertFalse(support.match_test(test_chdir)) + def test_fd_count(self): + # We cannot test the absolute value of fd_count(): on old Linux + # kernel or glibc versions, os.urandom() keeps a FD open on + # /dev/urandom device and Python has 4 FD opens instead of 3. + start = support.fd_count() + fd = os.open(__file__, os.O_RDONLY) + try: + more = support.fd_count() + finally: + os.close(fd) + self.assertEqual(more - start, 1) # XXX -follows a list of untested API # make_legacy_pyc |