mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #11377: Deprecate platform.popen() and reimplement it with os.popen().
This commit is contained in:
parent
7b3b20ad29
commit
1dfd380306
4 changed files with 26 additions and 82 deletions
|
@ -243,6 +243,25 @@ class PlatformTest(unittest.TestCase):
|
|||
):
|
||||
self.assertEqual(platform._parse_release_file(input), output)
|
||||
|
||||
def test_popen(self):
|
||||
command = "'{}' -c 'print(\"Hello\")'".format(sys.executable)
|
||||
with platform.popen(command) as stdout:
|
||||
hello = stdout.read().strip()
|
||||
stdout.close()
|
||||
self.assertEqual(hello, "Hello")
|
||||
|
||||
command = "'{}' -c 'import sys; data=sys.stdin.read(); exit(len(data))'".format(sys.executable)
|
||||
data = 'plop'
|
||||
with platform.popen(command, 'w') as stdin:
|
||||
stdout = stdin.write(data)
|
||||
ret = stdin.close()
|
||||
self.assertIsNotNone(ret)
|
||||
if os.name == 'nt':
|
||||
returncode = ret
|
||||
else:
|
||||
returncode = ret >> 8
|
||||
self.assertEqual(returncode, len(data))
|
||||
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue