summaryrefslogtreecommitdiff
path: root/Lib/test/test_platform.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-12-05 22:41:52 +0100
committerGitHub <noreply@github.com>2018-12-05 22:41:52 +0100
commitea0ca218b0c28b2af2b1f6a5d3383569de7fc2c1 (patch)
treea24104d328f8f9288fe7bef507eff49cb25a80e1 /Lib/test/test_platform.py
parent40a61da40d252626f8b9ff524d76c1f0ccb3a4f7 (diff)
downloadcpython-git-ea0ca218b0c28b2af2b1f6a5d3383569de7fc2c1.tar.gz
bpo-35344: platform.platform() uses mac_ver() on macOS (GH-10780)
On macOS, platform.platform() now uses mac_ver(), if it returns a non-empty release string, to get the macOS version rather than darwin version.
Diffstat (limited to 'Lib/test/test_platform.py')
-rw-r--r--Lib/test/test_platform.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index 978d2f76ab..c1a7e34079 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -10,6 +10,11 @@ from unittest import mock
from test import support
class PlatformTest(unittest.TestCase):
+ def clear_caches(self):
+ platform._platform_cache.clear()
+ platform._sys_version_cache.clear()
+ platform._uname_cache = None
+
def test_architecture(self):
res = platform.architecture()
@@ -344,5 +349,33 @@ class PlatformTest(unittest.TestCase):
self.assertLess(V('0.960923'), V('2.2beta29'))
+ def test_macos(self):
+ self.addCleanup(self.clear_caches)
+
+ uname = ('Darwin', 'hostname', '17.7.0',
+ ('Darwin Kernel Version 17.7.0: '
+ 'Thu Jun 21 22:53:14 PDT 2018; '
+ 'root:xnu-4570.71.2~1/RELEASE_X86_64'),
+ 'x86_64', 'i386')
+ arch = ('64bit', '')
+ with mock.patch.object(platform, 'uname', return_value=uname), \
+ mock.patch.object(platform, 'architecture', return_value=arch):
+ for mac_ver, expected_terse, expected in [
+ # darwin: mac_ver() returns empty strings
+ (('', '', ''),
+ 'Darwin-17.7.0',
+ 'Darwin-17.7.0-x86_64-i386-64bit'),
+ # macOS: mac_ver() returns macOS version
+ (('10.13.6', ('', '', ''), 'x86_64'),
+ 'macOS-10.13.6',
+ 'macOS-10.13.6-x86_64-i386-64bit'),
+ ]:
+ with mock.patch.object(platform, 'mac_ver',
+ return_value=mac_ver):
+ self.clear_caches()
+ self.assertEqual(platform.platform(terse=1), expected_terse)
+ self.assertEqual(platform.platform(), expected)
+
+
if __name__ == '__main__':
unittest.main()