From 9aacda974a322d76de9139f86eced861fca7bde0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 13 Apr 2019 21:14:53 -0400 Subject: [PATCH 1/4] Add a test intended to capture the expected values from 'uname -p' --- Lib/test/test_platform.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 9cf17726d92e0dc..7e9acad2df5ce45 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -5,6 +5,7 @@ import sysconfig import tempfile import unittest +import collections from unittest import mock from test import support @@ -189,6 +190,13 @@ def test_uname(self): self.assertEqual(res[4], res.machine) self.assertEqual(res[5], res.processor) + def test_uname_processor(self): + expected = collections.defaultdict( + set, + Darwin={'i386'}, + )[platform.system()] + self.assertIn(platform.uname().processor, expected) + @unittest.skipUnless(sys.platform.startswith('win'), "windows only test") def test_uname_win32_ARCHITEW6432(self): # Issue 7860: make sure we get architecture from the correct variable From aa297014e2e88d0c1296ebc10d2209b9ae6ca2b3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 14 Apr 2019 09:42:18 -0400 Subject: [PATCH 2/4] 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' --- Lib/test/test_platform.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 7e9acad2df5ce45..feec75bd86fb95e 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -191,11 +191,20 @@ def test_uname(self): self.assertEqual(res[5], res.processor) def test_uname_processor(self): - expected = collections.defaultdict( - set, - Darwin={'i386'}, - )[platform.system()] - self.assertIn(platform.uname().processor, expected) + """ + On some systems, the processor must match the output + of 'uname -p'. + """ + if sys.platform in ['win32', 'OpenVMS']: + return + + try: + output = subprocess.check_output(['uname', '-p'], text=True) + except subprocess.CalledProcessError: + return + + expected = output.strip() + self.assertEqual(platform.uname().processor, expected) @unittest.skipUnless(sys.platform.startswith('win'), "windows only test") def test_uname_win32_ARCHITEW6432(self): From 01ac684f72eb409337ef838489f75dd08990aef0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 14 Apr 2019 09:48:51 -0400 Subject: [PATCH 3/4] Use a skipIf directive --- Lib/test/test_platform.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index feec75bd86fb95e..7e480aa09d74184 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -190,14 +190,12 @@ def test_uname(self): self.assertEqual(res[4], res.machine) self.assertEqual(res[5], res.processor) + @unittest.skipIf(sys.platform in ['win32', 'OpenVMS'], "uname -p not used") def test_uname_processor(self): """ On some systems, the processor must match the output - of 'uname -p'. + of 'uname -p'. See Issue 35967 for rationale. """ - if sys.platform in ['win32', 'OpenVMS']: - return - try: output = subprocess.check_output(['uname', '-p'], text=True) except subprocess.CalledProcessError: From 9df8602a562a2a30510d6451ff469635b350167d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 14 Apr 2019 09:52:39 -0400 Subject: [PATCH 4/4] Use contextlib.suppress to suppress the error. Inline strip call. --- Lib/test/test_platform.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 7e480aa09d74184..8541655e2d0bd02 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -6,6 +6,7 @@ import tempfile import unittest import collections +import contextlib from unittest import mock from test import support @@ -196,13 +197,11 @@ def test_uname_processor(self): On some systems, the processor must match the output of 'uname -p'. See Issue 35967 for rationale. """ - try: - output = subprocess.check_output(['uname', '-p'], text=True) - except subprocess.CalledProcessError: - return - - expected = output.strip() - self.assertEqual(platform.uname().processor, expected) + with contextlib.suppress(subprocess.CalledProcessError): + self.assertEqual( + platform.uname().processor, + subprocess.check_output(['uname', '-p'], text=True).strip(), + ) @unittest.skipUnless(sys.platform.startswith('win'), "windows only test") def test_uname_win32_ARCHITEW6432(self):