|
10 | 10 | from test import support |
11 | 11 |
|
12 | 12 | class PlatformTest(unittest.TestCase): |
| 13 | + def clear_caches(self): |
| 14 | + platform._platform_cache.clear() |
| 15 | + platform._sys_version_cache.clear() |
| 16 | + platform._uname_cache = None |
| 17 | + |
13 | 18 | def test_architecture(self): |
14 | 19 | res = platform.architecture() |
15 | 20 |
|
@@ -344,5 +349,33 @@ def test__comparable_version(self): |
344 | 349 | self.assertLess(V('0.960923'), V('2.2beta29')) |
345 | 350 |
|
346 | 351 |
|
| 352 | + def test_macos(self): |
| 353 | + self.addCleanup(self.clear_caches) |
| 354 | + |
| 355 | + uname = ('Darwin', 'hostname', '17.7.0', |
| 356 | + ('Darwin Kernel Version 17.7.0: ' |
| 357 | + 'Thu Jun 21 22:53:14 PDT 2018; ' |
| 358 | + 'root:xnu-4570.71.2~1/RELEASE_X86_64'), |
| 359 | + 'x86_64', 'i386') |
| 360 | + arch = ('64bit', '') |
| 361 | + with mock.patch.object(platform, 'uname', return_value=uname), \ |
| 362 | + mock.patch.object(platform, 'architecture', return_value=arch): |
| 363 | + for mac_ver, expected_terse, expected in [ |
| 364 | + # darwin: mac_ver() returns empty strings |
| 365 | + (('', '', ''), |
| 366 | + 'Darwin-17.7.0', |
| 367 | + 'Darwin-17.7.0-x86_64-i386-64bit'), |
| 368 | + # macOS: mac_ver() returns macOS version |
| 369 | + (('10.13.6', ('', '', ''), 'x86_64'), |
| 370 | + 'macOS-10.13.6', |
| 371 | + 'macOS-10.13.6-x86_64-i386-64bit'), |
| 372 | + ]: |
| 373 | + with mock.patch.object(platform, 'mac_ver', |
| 374 | + return_value=mac_ver): |
| 375 | + self.clear_caches() |
| 376 | + self.assertEqual(platform.platform(terse=1), expected_terse) |
| 377 | + self.assertEqual(platform.platform(), expected) |
| 378 | + |
| 379 | + |
347 | 380 | if __name__ == '__main__': |
348 | 381 | unittest.main() |
0 commit comments