◐ Shell
clean mode source ↗

bpo-20104: Change the file_actions parameter of os.posix_spawn(). by serhiy-storchaka · Pull Request #6725 · python/cpython

Expand Up @@ -1499,8 +1499,7 @@ def test_returns_pid(self): pidfile.write(str(os.getpid())) """ args = self.python_args('-c', script) pid = posix.posix_spawn(args[0], args, os.environ) pid = posix.posix_spawn(args[0], args, os.environ) self.assertEqual(os.waitpid(pid, 0), (pid, 0)) with open(pidfile) as f: self.assertEqual(f.read(), str(pid)) Expand Down Expand Up @@ -1538,7 +1537,7 @@ def test_empty_file_actions(self): self.NOOP_PROGRAM[0], self.NOOP_PROGRAM, os.environ, [] file_actions=[] ) self.assertEqual(os.waitpid(pid, 0), (pid, 0))
Expand Down Expand Up @@ -1691,37 +1690,38 @@ def test_multiple_file_actions(self): ] pid = posix.posix_spawn(self.NOOP_PROGRAM[0], self.NOOP_PROGRAM, os.environ, file_actions) os.environ, file_actions=file_actions) self.assertEqual(os.waitpid(pid, 0), (pid, 0))
def test_bad_file_actions(self): args = self.NOOP_PROGRAM with self.assertRaises(TypeError): posix.posix_spawn(args[0], args, os.environ, [None]) posix.posix_spawn(args[0], args, os.environ, file_actions=[None]) with self.assertRaises(TypeError): posix.posix_spawn(args[0], args, os.environ, [()]) posix.posix_spawn(args[0], args, os.environ, file_actions=[()]) with self.assertRaises(TypeError): posix.posix_spawn(args[0], args, os.environ, [(None,)]) posix.posix_spawn(args[0], args, os.environ, file_actions=[(None,)]) with self.assertRaises(TypeError): posix.posix_spawn(args[0], args, os.environ, [(12345,)]) posix.posix_spawn(args[0], args, os.environ, file_actions=[(12345,)]) with self.assertRaises(TypeError): posix.posix_spawn(args[0], args, os.environ, [(os.POSIX_SPAWN_CLOSE,)]) posix.posix_spawn(args[0], args, os.environ, file_actions=[(os.POSIX_SPAWN_CLOSE,)]) with self.assertRaises(TypeError): posix.posix_spawn(args[0], args, os.environ, [(os.POSIX_SPAWN_CLOSE, 1, 2)]) posix.posix_spawn(args[0], args, os.environ, file_actions=[(os.POSIX_SPAWN_CLOSE, 1, 2)]) with self.assertRaises(TypeError): posix.posix_spawn(args[0], args, os.environ, [(os.POSIX_SPAWN_CLOSE, None)]) posix.posix_spawn(args[0], args, os.environ, file_actions=[(os.POSIX_SPAWN_CLOSE, None)]) with self.assertRaises(ValueError): posix.posix_spawn(args[0], args, os.environ, [(os.POSIX_SPAWN_OPEN, 3, __file__ + '\0', os.O_RDONLY, 0)]) posix.posix_spawn(args[0], args, os.environ, file_actions=[(os.POSIX_SPAWN_OPEN, 3, __file__ + '\0', os.O_RDONLY, 0)])
def test_open_file(self): outfile = support.TESTFN Expand All @@ -1736,8 +1736,8 @@ def test_open_file(self): stat.S_IRUSR | stat.S_IWUSR), ] args = self.python_args('-c', script) pid = posix.posix_spawn(args[0], args, os.environ, file_actions) pid = posix.posix_spawn(args[0], args, os.environ, file_actions=file_actions) self.assertEqual(os.waitpid(pid, 0), (pid, 0)) with open(outfile) as f: self.assertEqual(f.read(), 'hello') Expand All @@ -1754,9 +1754,8 @@ def test_close_file(self): closefile.write('is closed %d' % e.errno) """ args = self.python_args('-c', script) pid = posix.posix_spawn(args[0], args, os.environ, [(os.POSIX_SPAWN_CLOSE, 0),]) pid = posix.posix_spawn(args[0], args, os.environ, file_actions=[(os.POSIX_SPAWN_CLOSE, 0),]) self.assertEqual(os.waitpid(pid, 0), (pid, 0)) with open(closefile) as f: self.assertEqual(f.read(), 'is closed %d' % errno.EBADF) Expand All @@ -1773,8 +1772,8 @@ def test_dup2(self): (os.POSIX_SPAWN_DUP2, childfile.fileno(), 1), ] args = self.python_args('-c', script) pid = posix.posix_spawn(args[0], args, os.environ, file_actions) pid = posix.posix_spawn(args[0], args, os.environ, file_actions=file_actions) self.assertEqual(os.waitpid(pid, 0), (pid, 0)) with open(dupfile) as f: self.assertEqual(f.read(), 'hello') Expand Down