(self)
| 1335 | self.assertEqual(stdout, '[{}]'.format(expected)) |
| 1336 | |
| 1337 | def test_no_leaking(self): |
| 1338 | # Make sure we leak no resources |
| 1339 | if not mswindows: |
| 1340 | max_handles = 1026 # too much for most UNIX systems |
| 1341 | else: |
| 1342 | max_handles = 2050 # too much for (at least some) Windows setups |
| 1343 | if resource: |
| 1344 | # And if it is not too much, try to make it too much. |
| 1345 | try: |
| 1346 | soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) |
| 1347 | if soft > 1024: |
| 1348 | resource.setrlimit(resource.RLIMIT_NOFILE, (1024, hard)) |
| 1349 | self.addCleanup(resource.setrlimit, resource.RLIMIT_NOFILE, |
| 1350 | (soft, hard)) |
| 1351 | except (OSError, ValueError): |
| 1352 | pass |
| 1353 | handles = [] |
| 1354 | tmpdir = tempfile.mkdtemp() |
| 1355 | try: |
| 1356 | for i in range(max_handles): |
| 1357 | try: |
| 1358 | tmpfile = os.path.join(tmpdir, os_helper.TESTFN) |
| 1359 | handles.append(os.open(tmpfile, os.O_WRONLY|os.O_CREAT)) |
| 1360 | except OSError as e: |
| 1361 | if e.errno != errno.EMFILE: |
| 1362 | raise |
| 1363 | break |
| 1364 | else: |
| 1365 | self.skipTest("failed to reach the file descriptor limit " |
| 1366 | "(tried %d)" % max_handles) |
| 1367 | # Close a couple of them (should be enough for a subprocess). |
| 1368 | # Close lower file descriptors, so select() will work. |
| 1369 | handles.reverse() |
| 1370 | for i in range(10): |
| 1371 | os.close(handles.pop()) |
| 1372 | # Loop creating some subprocesses. If one of them leaks some fds, |
| 1373 | # the next loop iteration will fail by reaching the max fd limit. |
| 1374 | for i in range(15): |
| 1375 | p = subprocess.Popen([sys.executable, "-c", |
| 1376 | "import sys;" |
| 1377 | "sys.stdout.write(sys.stdin.read())"], |
| 1378 | stdin=subprocess.PIPE, |
| 1379 | stdout=subprocess.PIPE, |
| 1380 | stderr=subprocess.PIPE) |
| 1381 | data = p.communicate(b"lime")[0] |
| 1382 | self.assertEqual(data, b"lime") |
| 1383 | finally: |
| 1384 | for h in handles: |
| 1385 | os.close(h) |
| 1386 | shutil.rmtree(tmpdir) |
| 1387 | |
| 1388 | def test_list2cmdline(self): |
| 1389 | self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']), |
nothing calls this directly
no test coverage detected