mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-35346, platform: replace os.popen() with subprocess (GH-10786)
Replace os.popen() with subprocess.check_output() in the platform module: * platform.uname() (its _syscmd_ver() helper function) now redirects stderr to DEVNULL. * Remove platform.DEV_NULL. * _syscmd_uname() and _syscmd_file() no longer catch AttributeError. The "except AttributeError:" was only needed in Python 2, when os.popen() was not always available. In Python 3, subprocess.check_output() is always available.
This commit is contained in:
parent
9ebe8794f0
commit
3a521f0b61
3 changed files with 30 additions and 48 deletions
|
@ -222,16 +222,16 @@ class PlatformTest(unittest.TestCase):
|
|||
res = platform.mac_ver()
|
||||
|
||||
if platform.uname().system == 'Darwin':
|
||||
# We're on a MacOSX system, check that
|
||||
# the right version information is returned
|
||||
fd = os.popen('sw_vers', 'r')
|
||||
real_ver = None
|
||||
for ln in fd:
|
||||
if ln.startswith('ProductVersion:'):
|
||||
real_ver = ln.strip().split()[-1]
|
||||
# We are on a macOS system, check that the right version
|
||||
# information is returned
|
||||
output = subprocess.check_output(['sw_vers'], text=True)
|
||||
for line in output.splitlines():
|
||||
if line.startswith('ProductVersion:'):
|
||||
real_ver = line.strip().split()[-1]
|
||||
break
|
||||
fd.close()
|
||||
self.assertFalse(real_ver is None)
|
||||
else:
|
||||
self.fail(f"failed to parse sw_vers output: {output!r}")
|
||||
|
||||
result_list = res[0].split('.')
|
||||
expect_list = real_ver.split('.')
|
||||
len_diff = len(result_list) - len(expect_list)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue