bpo-40570: Improve compatibility of uname_result with late-bound .platform (#20015)

* bpo-40570: Improve compatibility of uname_result with late-bound .platform.

* Add test capturing ability to cast uname to a tuple.
This commit is contained in:
Jason R. Coombs 2020-05-09 10:12:41 -04:00 committed by GitHub
parent 77c614624b
commit 2c3d508c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -798,9 +798,10 @@ class uname_result(
)
def __getitem__(self, key):
if key == 5:
return self.processor
return super().__getitem__(key)
return tuple(iter(self))[key]
def __len__(self):
return len(tuple(iter(self)))
_uname_cache = None

View File

@ -154,11 +154,26 @@ class PlatformTest(unittest.TestCase):
res = platform.uname()
self.assertTrue(any(res))
self.assertEqual(res[0], res.system)
self.assertEqual(res[-6], res.system)
self.assertEqual(res[1], res.node)
self.assertEqual(res[-5], res.node)
self.assertEqual(res[2], res.release)
self.assertEqual(res[-4], res.release)
self.assertEqual(res[3], res.version)
self.assertEqual(res[-3], res.version)
self.assertEqual(res[4], res.machine)
self.assertEqual(res[-2], res.machine)
self.assertEqual(res[5], res.processor)
self.assertEqual(res[-1], res.processor)
self.assertEqual(len(res), 6)
def test_uname_cast_to_tuple(self):
res = platform.uname()
expected = (
res.system, res.node, res.release, res.version, res.machine,
res.processor,
)
self.assertEqual(tuple(res), expected)
@unittest.skipIf(sys.platform in ['win32', 'OpenVMS'], "uname -p not used")
def test_uname_processor(self):