bpo-35967 resolve platform.processor late (GH-12239)

* Replace flag-flip indirection with direct inspection

* Use any for simpler code

* Avoid flag flip and set results directly.

* Resolve processor in a single function.

* Extract processor handling into a namespace (class)

* Remove _syscmd_uname, unused

* Restore platform.processor behavior to match prior expectation (reliant on uname -p in a subprocess).

* Extract '_unknown_as_blank' function.

* Override uname_result to resolve the processor late.

* Add a test intended to capture the expected values from 'uname -p'

* Instead of trying to keep track of all of the possible outputs on different systems (probably a fool's errand), simply assert that except for the known platform variance, uname().processor matches the output of 'uname -p'

* Use a skipIf directive

* Use contextlib.suppress to suppress the error. Inline strip call.

* 📜🤖 Added by blurb_it.

* Remove use of contextlib.suppress (it would fail with NameError if it had any effect). Rely on _unknown_as_blank to replace unknown with blank.

Co-authored-by: blurb-it[bot] <blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
Jason R. Coombs 2020-04-16 08:28:09 -04:00 committed by GitHub
parent 6a5bf15c71
commit 518835f335
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 86 deletions

View file

@ -4,7 +4,6 @@ import subprocess
import sys
import unittest
import collections
import contextlib
from unittest import mock
from test import support
@ -168,12 +167,8 @@ class PlatformTest(unittest.TestCase):
On some systems, the processor must match the output
of 'uname -p'. See Issue 35967 for rationale.
"""
with contextlib.suppress(subprocess.CalledProcessError):
expect = subprocess.check_output(['uname', '-p'], text=True).strip()
if expect == 'unknown':
expect = ''
proc_res = subprocess.check_output(['uname', '-p'], text=True).strip()
expect = platform._unknown_as_blank(proc_res)
self.assertEqual(platform.uname().processor, expect)
@unittest.skipUnless(sys.platform.startswith('win'), "windows only test")