Skip to content

Commit 7509ea1

Browse files
committed
Correct platform tests for tvOS/watchOS/visionOS.
1 parent 1fcfbe3 commit 7509ea1

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎Lib/platform.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def ios_ver(system="", release="", model="", is_simulator=False):
532532
If values can't be determined, they are set to values provided as
533533
parameters.
534534
"""
535-
if sys.platform == "ios":
535+
if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
536536
import _ios_support
537537
result = _ios_support.get_platform_ios()
538538
if result is not None:
@@ -1026,7 +1026,7 @@ def uname():
10261026
release = android_ver().release
10271027

10281028
# Normalize responses on Apple mobile platforms
1029-
if sys.platform in {'ios', 'tvos', 'visionos', 'watchos'}:
1029+
if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
10301030
system, release, _, _ = ios_ver()
10311031

10321032
vals = system, node, release, version, machine
@@ -1315,7 +1315,7 @@ def platform(aliased=False, terse=False):
13151315

13161316
if system == 'Darwin':
13171317
# macOS and iOS both report as a "Darwin" kernel
1318-
if sys.platform in {'ios', 'tvos', 'visionos', 'watchos'}:
1318+
if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
13191319
system, release, _, _ = ios_ver()
13201320
else:
13211321
macos_release = mac_ver()[0]

‎Lib/test/test_platform.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ def test_uname(self):
299299
# All other platforms - sys.platform is the lower case
300300
# form of system (e.g., visionOS->visionos)
301301
self.assertEqual(res.system.lower(), sys.platform)
302-
# Use the platform-specific version method
303-
platform_ver = getattr(platform, f"{sys.platform}_ver")
304-
self.assertEqual(res.release, platform_ver().release)
302+
self.assertEqual(res.release, platform.ios_ver().release)
305303
else:
306304
self.assertEqual(res.system, "")
307305
self.assertEqual(res.release, "")
@@ -493,8 +491,8 @@ def test_mac_ver_with_fork(self):
493491
def test_ios_ver(self):
494492
result = platform.ios_ver()
495493

496-
# ios_ver is only fully available on iOS where ctypes is available.
497-
if sys.platform == "ios" and _ctypes:
494+
# ios_ver is only fully available on Apple mobile platorms where ctypes is available.
495+
if sys.platform in {"ios", "tvos", "visionos", "watchos"} and _ctypes:
498496
system, release, model, is_simulator = result
499497
# Result is a namedtuple
500498
self.assertEqual(result.system, system)
@@ -506,7 +504,10 @@ def test_ios_ver(self):
506504
# ios_ver(), so we check that the values are broadly what we expect.
507505

508506
# System is either iOS or iPadOS, depending on the test device
509-
self.assertIn(system, {"iOS", "iPadOS"})
507+
if sys.platform == "ios":
508+
self.assertIn(system, {"iOS", "iPadOS"})
509+
else:
510+
self.assertEqual(system.lower(), sys.platform)
510511

511512
# Release is a numeric version specifier with at least 2 parts
512513
parts = release.split(".")
@@ -516,11 +517,17 @@ def test_ios_ver(self):
516517
# If this is a simulator, we get a high level device descriptor
517518
# with no identifying model number. If this is a physical device,
518519
# we get a model descriptor like "iPhone13,1"
520+
devices = {
521+
"ios": {"iPhone", "iPad"},
522+
"tvos": {"Apple TV"},
523+
"visionos": {"Apple Vision Pro"},
524+
"watchos": {"Apple Watch"},
525+
}[sys.platform]
519526
if is_simulator:
520-
self.assertIn(model, {"iPhone", "iPad"})
527+
self.assertIn(model, devices)
521528
else:
522529
self.assertTrue(
523-
(model.startswith("iPhone") or model.startswith("iPad"))
530+
any(model.startswith(d) for d in devices)
524531
and "," in model
525532
)
526533

0 commit comments

Comments
 (0)