Skip to content

Commit

Permalink
Make test suite resilient to the absence of ctypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Mar 28, 2024
1 parent c121d5f commit 1ac4b26
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def _platform(*args):
if cleaned == platform:
break
platform = cleaned
while platform[-1] == '-':
while platform and platform[-1] == '-':
platform = platform[:-1]

return platform
Expand Down
24 changes: 20 additions & 4 deletions Lib/test/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
from test import support
from test.support import os_helper

try:
# Some of the iOS tests need ctypes to operate.
# Confirm that the ctypes module is available
# is available.
import _ctypes
except ImportError:
_ctypes = None

FEDORA_OS_RELEASE = """\
NAME=Fedora
VERSION="32 (Thirty Two)"
Expand Down Expand Up @@ -229,8 +237,15 @@ def test_uname(self):
self.assertEqual(res.system, "Android")
self.assertEqual(res.release, platform.android_ver().release)
elif sys.platform == "ios":
self.assertIn(res.system, {"iOS", "iPadOS"})
self.assertEqual(res.release, platform.ios_ver().release)
# Platform module needs ctypes for full operation. If ctypes
# isn't available, there's no ObjC module, and dummy values are
# returned.
if _ctypes:
self.assertIn(res.system, {"iOS", "iPadOS"})
self.assertEqual(res.release, platform.ios_ver().release)
else:
self.assertEqual(res.system, "")
self.assertEqual(res.release, "")
else:
self.assertEqual(res.system, uname.sysname)
self.assertEqual(res.release, uname.release)
Expand Down Expand Up @@ -428,9 +443,10 @@ def test_mac_ver_with_fork(self):

def test_ios_ver(self):
result = platform.ios_ver()
if sys.platform == "ios":
system, release, model, is_simulator = result

# ios_ver is only fully available on iOS where ctypes is available.
if sys.platform == "ios" and _ctypes:
system, release, model, is_simulator = result
# Result is a namedtuple
self.assertEqual(result.system, system)
self.assertEqual(result.release, release)
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def _obj_ref(self, *args):
# as a proxy for object instance references
return "|".join(str(a) for a in args)

@unittest.skipIf(webbrowser.objc is None, "iOS Webbrowser tests require ctypes")
def setUp(self):
# Intercept the the objc library. Wrap the calls to get the
# references to classes and selectors to return strings, and
Expand Down

0 comments on commit 1ac4b26

Please sign in to comment.